Skip to content

Commit 7ced06d

Browse files
committed
Base Geo renderer now allows arbitrary properties to be set, Google Maps impl adds mapTypeId property.
git-svn-id: https://share-extras.googlecode.com/svn/trunk/Site Geotagged Content Dashlet@1338 a3f5c567-fd0f-3a89-9b71-a290c5a5f590
1 parent ca9d9c3 commit 7ced06d

File tree

2 files changed

+174
-78
lines changed

2 files changed

+174
-78
lines changed

config/webscripts/org/sharextras/customization/doclib-geo-view/components/documentlibrary/documentlist.get.html.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
var geoViewRenderer = new Extras.DocumentListGeoViewRenderer("geo")
2828
geoViewRenderer.zoomLevel = ${preferences.zoomLevel!15};
2929
geoViewRenderer.center = "${(preferences.center!'')?js_string}";
30+
geoViewRenderer.mapTypeId = "${(preferences.mapTypeId!'')?js_string}";
3031
scope.registerViewRenderer(geoViewRenderer);
3132
});
3233
//]]></script>

source/web/extras/components/documentlibrary/documentlist-geo.js

Lines changed: 173 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ if (typeof Extras == "undefined" || !Extras)
7777
this.metadataLineViewName = "detailed";
7878
this.thumbnailColumnWidth = 200;
7979
this.rowClassName = "alf-detail";
80+
81+
var me = this;
82+
83+
YAHOO.Bubbling.on("gmapsScriptLoaded", function onGmapsScriptLoaded() {
84+
me.scriptLoaded = true;
85+
if (this.renderedView == true)
86+
{
87+
me.renderView.call(me, me.scope);
88+
}
89+
});
90+
8091
return this;
8192
};
8293

@@ -143,7 +154,7 @@ if (typeof Extras == "undefined" || !Extras)
143154
YAHOO.util.Dom.setStyle(scope.id + this.parentElementIdSuffix, 'display', 'none');
144155
YAHOO.util.Dom.setStyle(this.mapDiv, 'display', 'none');
145156
Dom.removeClass(scope.id + this.parentElementIdSuffix, "documents-geo");
146-
},
157+
}
147158

148159
});
149160

@@ -225,6 +236,12 @@ if (typeof Extras == "undefined" || !Extras)
225236
Dom.addClass(matchedEl, 'alf-hover');
226237
viewRendererInstance.onEventHighlightRow(scope, event, matchedEl);
227238
}, 'div.' + this.rowClassName, this);
239+
240+
// Async load the Google Maps API. Need to do this, as it breaks the YUI Loader otherwise
241+
var script = document.createElement("script");
242+
script.type = "text/javascript";
243+
script.src = window.location.protocol + "//maps.google.com/maps/api/js?sensor=false&callback=Extras.DocumentListGeoViewRenderer.onGMapsScriptLoad";
244+
document.body.appendChild(script);
228245
};
229246

230247
/**
@@ -238,87 +255,92 @@ if (typeof Extras == "undefined" || !Extras)
238255
*/
239256
Extras.DocumentListGeoViewRenderer.prototype.renderView = function DL_GVR_renderView(scope, sRequest, oResponse, oPayload)
240257
{
241-
YAHOO.util.Dom.setStyle(scope.id + this.parentElementIdSuffix, 'display', '');
242-
Dom.addClass(scope.id + this.parentElementIdSuffix, "documents-geo");
243-
244-
var mapId = scope.id + this.parentElementIdSuffix + "-map",
245-
mapDiv = Dom.get(mapId);
246-
247-
var container = Dom.get(scope.id + this.parentElementIdSuffix);
248-
var oRecordSet = scope.widgets.dataTable.getRecordSet();
249-
250-
scope.widgets.dataTable.onDataReturnInitializeTable.call(scope.widgets.dataTable, sRequest, oResponse, oPayload);
251-
252-
if (!this.mapDiv)
253-
{
254-
mapDiv = document.createElement("div");
255-
Dom.setAttribute(mapDiv, "id", mapId);
256-
Dom.addClass(mapDiv, "map");
257-
Dom.setStyle(mapDiv, "height", "" + ((window.innerHeight || document.documentElement.offsetHeight || document.body.offsetHeight) - 310) + "px");
258-
Dom.get(scope.id + this.parentElementIdSuffix).appendChild(mapDiv);
259-
this.mapDiv = mapDiv;
260-
}
261-
else
258+
this.renderedView = true;
259+
this.scope = scope;
260+
if (this.scriptLoaded == true)
262261
{
263-
YAHOO.util.Dom.setStyle(this.mapDiv, 'display', '');
264-
}
265-
266-
if (!this.map)
267-
{
268-
var center = (this.center || "").split(",");
269-
if (center.length == 1)
262+
YAHOO.util.Dom.setStyle(scope.id + this.parentElementIdSuffix, 'display', '');
263+
Dom.addClass(scope.id + this.parentElementIdSuffix, "documents-geo");
264+
265+
var mapId = scope.id + this.parentElementIdSuffix + "-map",
266+
mapDiv = Dom.get(mapId);
267+
268+
var container = Dom.get(scope.id + this.parentElementIdSuffix);
269+
var oRecordSet = scope.widgets.dataTable.getRecordSet();
270+
271+
scope.widgets.dataTable.onDataReturnInitializeTable.call(scope.widgets.dataTable, sRequest, oResponse, oPayload);
272+
273+
if (!this.mapDiv)
274+
{
275+
mapDiv = document.createElement("div");
276+
Dom.setAttribute(mapDiv, "id", mapId);
277+
Dom.addClass(mapDiv, "map");
278+
Dom.setStyle(mapDiv, "height", "" + ((window.innerHeight || document.documentElement.offsetHeight || document.body.offsetHeight) - 310) + "px");
279+
Dom.get(scope.id + this.parentElementIdSuffix).appendChild(mapDiv);
280+
this.mapDiv = mapDiv;
281+
}
282+
else
270283
{
271-
center = [51, 0];
284+
YAHOO.util.Dom.setStyle(this.mapDiv, 'display', '');
272285
}
273286

274-
this._renderMap(scope, mapId, {
275-
center: {
276-
lat: center[0],
277-
lng: center[1]
287+
if (!this.map)
288+
{
289+
var center = (this.center || "").split(",");
290+
if (center.length == 1)
291+
{
292+
center = [51, 0];
278293
}
279-
});
280-
}
281-
282-
this._removeAllMarkers();
283-
284-
var galleryItemTemplate = Dom.get(scope.id + '-geo-item-template'),
285-
galleryItem = null;
286-
287-
var oRecord, record, i, j;
288-
for (i = 0, j = oRecordSet.getLength(); i < j; i++)
289-
{
290-
oRecord = oRecordSet.getRecord(i);
291-
record = oRecord.getData();
292-
293-
// Append a gallery item div
294-
var galleryItemId = this.getRowItemId(oRecord);
295-
galleryItem = galleryItemTemplate.cloneNode(true);
296-
Dom.removeClass(galleryItem, 'hidden');
297-
galleryItem.setAttribute('id', galleryItemId);
298-
container.appendChild(galleryItem);
294+
295+
this._renderMap(scope, mapId, {
296+
center: {
297+
lat: center[0],
298+
lng: center[1]
299+
}
300+
});
301+
}
299302

300-
var galleryItemDetailDiv = this.getRowItemDetailElement(galleryItem);
301-
var galleryItemActionsDiv = this.getRowItemActionsElement(galleryItem);
303+
this._removeAllMarkers();
302304

303-
// Suffix of the content actions div id must match the onEventHighlightRow target id
304-
galleryItemActionsDiv.setAttribute('id', scope.id + '-actions-' + galleryItemId);
305+
var galleryItemTemplate = Dom.get(scope.id + '-geo-item-template'),
306+
galleryItem = null;
307+
308+
var oRecord, record, i, j;
309+
for (i = 0, j = oRecordSet.getLength(); i < j; i++)
310+
{
311+
oRecord = oRecordSet.getRecord(i);
312+
record = oRecord.getData();
313+
314+
// Append a gallery item div
315+
var galleryItemId = this.getRowItemId(oRecord);
316+
galleryItem = galleryItemTemplate.cloneNode(true);
317+
Dom.removeClass(galleryItem, 'hidden');
318+
galleryItem.setAttribute('id', galleryItemId);
319+
container.appendChild(galleryItem);
320+
321+
var galleryItemDetailDiv = this.getRowItemDetailElement(galleryItem);
322+
var galleryItemActionsDiv = this.getRowItemActionsElement(galleryItem);
323+
324+
// Suffix of the content actions div id must match the onEventHighlightRow target id
325+
galleryItemActionsDiv.setAttribute('id', scope.id + '-actions-' + galleryItemId);
305326

306-
// Details div ID
307-
galleryItemDetailDiv.setAttribute('id', scope.id + '-details-' + galleryItemId);
327+
// Details div ID
328+
galleryItemDetailDiv.setAttribute('id', scope.id + '-details-' + galleryItemId);
308329

309-
var properties = record.jsNode.properties;
330+
var properties = record.jsNode.properties;
310331

311-
// create a marker in the given location and add it to the map
312-
if (properties["cm:latitude"] && properties["cm:longitude"])
313-
{
314-
this._addMarker({
315-
lat: properties["cm:latitude"],
316-
lng: properties["cm:longitude"],
317-
title: record.displayName,
318-
galleryItemDetailDivId: scope.id + '-details-' + galleryItemId
319-
});
320-
}
321-
};
332+
// create a marker in the given location and add it to the map
333+
if (properties["cm:latitude"] && properties["cm:longitude"])
334+
{
335+
this._addMarker({
336+
lat: properties["cm:latitude"],
337+
lng: properties["cm:longitude"],
338+
title: record.displayName,
339+
galleryItemDetailDivId: scope.id + '-details-' + galleryItemId
340+
});
341+
}
342+
};
343+
}
322344
};
323345

324346
/**
@@ -332,6 +354,7 @@ if (typeof Extras == "undefined" || !Extras)
332354
*/
333355
Extras.DocumentListGeoViewRenderer.prototype._renderMap = function DL_GVR__renderMap(scope, mapId, pObj)
334356
{
357+
/*
335358
// set up the map
336359
var center = pObj.center,
337360
map = new L.Map(mapId).setView([center.lat, center.lng], this.zoomLevel);
@@ -350,6 +373,26 @@ if (typeof Extras == "undefined" || !Extras)
350373
}, this);
351374
352375
this.map = map;
376+
*/
377+
var me = this,
378+
center = pObj.center;
379+
var myLatlng = new google.maps.LatLng(center.lat, center.lng);
380+
this.map = new google.maps.Map(Dom.get(mapId), {
381+
center: myLatlng,
382+
zoom: this.zoomLevel,
383+
mapTypeId: this.mapTypeId != null ? this.mapTypeId : google.maps.MapTypeId.ROADMAP
384+
});
385+
386+
// Update map settings as user preferences
387+
google.maps.event.addListener(this.map, "zoom_changed", function() {
388+
me._saveMapPreferences.call(me, scope);
389+
});
390+
google.maps.event.addListener(this.map, "dragend", function() {
391+
me._saveMapPreferences.call(me, scope);
392+
});
393+
google.maps.event.addListener(this.map, "maptypeid_changed", function() {
394+
me._saveMapPreferences.call(me, scope);
395+
});
353396
}
354397

355398
/**
@@ -362,12 +405,32 @@ if (typeof Extras == "undefined" || !Extras)
362405
*/
363406
Extras.DocumentListGeoViewRenderer.prototype._addMarker = function DL_GVR__addMarker(mObj)
364407
{
408+
/*
365409
var marker = L.marker([mObj.lat, mObj.lng], {
366410
title: mObj.title
367411
}).addTo(this.map);
368412
marker.bindPopup(Dom.get(mObj.galleryItemDetailDivId), { width: 400, maxWidth: 400 });
369413
Alfresco.logger.debug("Binding popup to item ID " + mObj.galleryItemDetailDivId);
370414
this.markers.push(marker);
415+
*/
416+
var me = this, map = this.map;
417+
var latLng = new google.maps.LatLng(mObj.lat, mObj.lng);
418+
var marker = new google.maps.Marker(
419+
{
420+
position: latLng,
421+
map: map,
422+
title: mObj.title
423+
});
424+
this.markers.push(marker);
425+
426+
var infowindow = new google.maps.InfoWindow({
427+
content: Dom.get(mObj.galleryItemDetailDivId),
428+
size: new google.maps.Size(50,50)
429+
});
430+
google.maps.event.addListener(marker, 'click', function() {
431+
infowindow.open(map, marker);
432+
me.selectedMarker = marker;
433+
});
371434
}
372435

373436
/**
@@ -380,7 +443,8 @@ if (typeof Extras == "undefined" || !Extras)
380443
{
381444
for (var i = 0; i < this.markers.length; i++)
382445
{
383-
this.map.removeLayer(this.markers[i]);
446+
//this.map.removeLayer(this.markers[i]);
447+
this.markers[i].setMap(null);
384448
}
385449
}
386450

@@ -393,33 +457,59 @@ if (typeof Extras == "undefined" || !Extras)
393457
*/
394458
Extras.DocumentListGeoViewRenderer.prototype._saveMapPreferences = function DL_GVR__saveMapPreferences(scope)
395459
{
460+
/*
461+
// save map position and zoom levels
462+
// when zooming leaflet fires both events, which leads to an exception being thrown from the repo
463+
// therefore we must first check that the another event is not 'in progress' before attempting the save
396464
this._savePreferenceValues(scope, {
397465
zoom: this.map.getZoom(),
398466
center: {
399467
lat: this.map.getCenter().lat,
400468
lng: this.map.getCenter().lng
401469
}
402470
});
471+
*/
472+
this._savePreferenceValues(scope, {
473+
zoom: this.map.getZoom(),
474+
center: {
475+
lat: this.map.getCenter().lat(),
476+
lng: this.map.getCenter().lng()
477+
},
478+
mapTypeId: this.map.getMapTypeId()
479+
});
403480
}
404481

405482
/**
406483
* Save preference values
407484
*
408485
* @method _savePreferenceValues
409486
* @param scope {object} The DocumentList object
410-
* @param {object} pObj Setting values. Must define properties `center` and `zoom`.
487+
* @param {object} pObj Setting values. Must define properties `center` and `zoom`, can define others.
411488
* @private
412489
*/
413490
Extras.DocumentListGeoViewRenderer.prototype._savePreferenceValues = function DL_GVR__savePreferenceValues(scope, pObj)
414491
{
415-
// save map position and zoom levels
416-
// when zooming leaflet fires both events, which leads to an exception being thrown from the repo
417-
// therefore we must first check that the another event is not 'in progress' before attempting the save
418492
if (this.savingPrefs == false)
419493
{
420494
this.savingPrefs = true;
495+
var prefValues = {};
496+
for (var k in pObj)
497+
{
498+
if (k == "center")
499+
{
500+
prefValues["center"] = "" + pObj.center.lat + "," + pObj.center.lng;
501+
}
502+
else if (k == "zoom")
503+
{
504+
prefValues["zoomLevel"] = pObj.zoom;
505+
}
506+
else
507+
{
508+
prefValues[k] = pObj[k];
509+
}
510+
}
421511
Alfresco.logger.debug("Set " + PREFERENCES_DOCLIST + " to " + pObj.zoom);
422-
scope.services.preferences.set(PREFERENCES_DOCLIST, { zoomLevel: pObj.zoom, center: pObj.center.lat + "," + pObj.center.lng }, {
512+
scope.services.preferences.set(PREFERENCES_DOCLIST, prefValues, {
423513
successCallback: {
424514
fn: function() {
425515
this.savingPrefs = false;
@@ -435,5 +525,10 @@ if (typeof Extras == "undefined" || !Extras)
435525
});
436526
}
437527
}
528+
529+
Extras.DocumentListGeoViewRenderer.onGMapsScriptLoad = function DL_GVR_onGMapsScriptLoad(e)
530+
{
531+
YAHOO.Bubbling.fire("gmapsScriptLoaded");
532+
}
438533

439534
})();

0 commit comments

Comments
 (0)