Skip to content

Commit 2b49d40

Browse files
committed
Refactor Leaflet-specific Geo renderer code into a separate class
git-svn-id: https://share-extras.googlecode.com/svn/trunk/Site Geotagged Content Dashlet@1347 a3f5c567-fd0f-3a89-9b71-a290c5a5f590
1 parent db8de33 commit 2b49d40

File tree

1 file changed

+57
-41
lines changed

1 file changed

+57
-41
lines changed

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

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -354,26 +354,6 @@ if (typeof Extras == "undefined" || !Extras)
354354
*/
355355
Extras.DocumentListGeoViewRenderer.prototype._renderMap = function DL_GVR__renderMap(scope, mapId, pObj)
356356
{
357-
/*
358-
// set up the map
359-
var center = pObj.center,
360-
map = new L.Map(mapId).setView([center.lat, center.lng], this.zoomLevel);
361-
362-
// create the tile layer with correct attribution
363-
L.tileLayer(this.options.leafletTileUrl, {
364-
attribution: scope.msg("label.copyright.osm")
365-
}).addTo(map);
366-
367-
map.on('zoomend', function(e) {
368-
this._saveMapPreferences.call(this, scope);
369-
}, this);
370-
371-
map.on('moveend', function(e) {
372-
this._saveMapPreferences.call(this, scope);
373-
}, this);
374-
375-
this.map = map;
376-
*/
377357
var me = this,
378358
center = pObj.center;
379359
var myLatlng = new google.maps.LatLng(center.lat, center.lng);
@@ -405,14 +385,6 @@ if (typeof Extras == "undefined" || !Extras)
405385
*/
406386
Extras.DocumentListGeoViewRenderer.prototype._addMarker = function DL_GVR__addMarker(mObj)
407387
{
408-
/*
409-
var marker = L.marker([mObj.lat, mObj.lng], {
410-
title: mObj.title
411-
}).addTo(this.map);
412-
marker.bindPopup(Dom.get(mObj.galleryItemDetailDivId), { width: 400, maxWidth: 400 });
413-
Alfresco.logger.debug("Binding popup to item ID " + mObj.galleryItemDetailDivId);
414-
this.markers.push(marker);
415-
*/
416388
var me = this, map = this.map;
417389
var latLng = new google.maps.LatLng(mObj.lat, mObj.lng);
418390
var marker = new google.maps.Marker(
@@ -443,7 +415,6 @@ if (typeof Extras == "undefined" || !Extras)
443415
{
444416
for (var i = 0; i < this.markers.length; i++)
445417
{
446-
//this.map.removeLayer(this.markers[i]);
447418
this.markers[i].setMap(null);
448419
}
449420
}
@@ -457,18 +428,6 @@ if (typeof Extras == "undefined" || !Extras)
457428
*/
458429
Extras.DocumentListGeoViewRenderer.prototype._saveMapPreferences = function DL_GVR__saveMapPreferences(scope)
459430
{
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
464-
this._savePreferenceValues(scope, {
465-
zoom: this.map.getZoom(),
466-
center: {
467-
lat: this.map.getCenter().lat,
468-
lng: this.map.getCenter().lng
469-
}
470-
});
471-
*/
472431
this._savePreferenceValues(scope, {
473432
zoom: this.map.getZoom(),
474433
center: {
@@ -530,5 +489,62 @@ if (typeof Extras == "undefined" || !Extras)
530489
{
531490
YAHOO.Bubbling.fire("gmapsScriptLoaded");
532491
}
492+
493+
YAHOO.extend(Extras.DocumentListLeafletGeoViewRenderer, Extras.DocumentListGeoViewRenderer,
494+
{
495+
_renderMap: function DL_LGVR__renderMap(scope, mapId, pObj)
496+
{
497+
// set up the map
498+
var center = pObj.center,
499+
map = new L.Map(mapId).setView([center.lat, center.lng], this.zoomLevel);
500+
501+
// create the tile layer with correct attribution
502+
L.tileLayer(this.options.leafletTileUrl, {
503+
attribution: scope.msg("label.copyright.osm")
504+
}).addTo(map);
505+
506+
map.on('zoomend', function(e) {
507+
this._saveMapPreferences.call(this, scope);
508+
}, this);
509+
510+
map.on('moveend', function(e) {
511+
this._saveMapPreferences.call(this, scope);
512+
}, this);
513+
514+
this.map = map;
515+
},
516+
517+
_addMarker: function DL_LGVR__addMarker(mObj)
518+
{
519+
var marker = L.marker([mObj.lat, mObj.lng], {
520+
title: mObj.title
521+
}).addTo(this.map);
522+
marker.bindPopup(Dom.get(mObj.galleryItemDetailDivId), { width: 400, maxWidth: 400 });
523+
Alfresco.logger.debug("Binding popup to item ID " + mObj.galleryItemDetailDivId);
524+
this.markers.push(marker);
525+
},
526+
527+
_removeAllMarkers: function DL_GVR__removeAllMarkers()
528+
{
529+
for (var i = 0; i < this.markers.length; i++)
530+
{
531+
this.map.removeLayer(this.markers[i]);
532+
}
533+
},
534+
535+
_saveMapPreferences = function DL_LGVR__saveMapPreferences(scope)
536+
{
537+
// save map position and zoom levels
538+
// when zooming leaflet fires both events, which leads to an exception being thrown from the repo
539+
// therefore we must first check that the another event is not 'in progress' before attempting the save
540+
this._savePreferenceValues(scope, {
541+
zoom: this.map.getZoom(),
542+
center: {
543+
lat: this.map.getCenter().lat,
544+
lng: this.map.getCenter().lng
545+
}
546+
});
547+
}
548+
});
533549

534550
})();

0 commit comments

Comments
 (0)