diff --git a/code/search.js b/code/search.js index ac6359f1..623d0575 100644 --- a/code/search.js +++ b/code/search.js @@ -137,15 +137,8 @@ window.search.Query.prototype.onResultSelected = function(result, ev) { result.layer = L.layerGroup(); if(result.position) { - var markerTemplate = '@@INCLUDESTRING:images/marker-icon.svg.template@@'; - L.marker(result.position, { - icon: L.divIcon({ - iconSize: new L.Point(25, 41), - iconAnchor: new L.Point(12, 41), - html: markerTemplate.replace(/%COLOR%/g, 'red'), - className: 'leaflet-iitc-search-result-icon', - }), - title: result.title, + createGenericMarker(result.position, 'red', { + title: result.title }).addTo(result.layer); } diff --git a/code/utils_misc.js b/code/utils_misc.js index 81e5e865..f0b5f547 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -440,6 +440,32 @@ window.clampLatLngBounds = function(bounds) { return new L.LatLngBounds ( clampLatLng(bounds.getSouthWest()), clampLatLng(bounds.getNorthEast()) ); } +window.getGenericMarkerSvg = function(color) { + var markerTemplate = '@@INCLUDESTRING:images/marker-icon.svg.template@@'; + + return markerTemplate.replace(/%COLOR%/g, color); +} + +window.getGenericMarkerIcon = function(color,className) { + return L.divIcon({ + iconSize: new L.Point(25, 41), + iconAnchor: new L.Point(12, 41), + html: getGenericMarkerSvg(color), + className: className || 'leaflet-iitc-divicon-generic-marker' + }); +} + +window.createGenericMarker = function(ll,color,options) { + options = options || {}; + + var markerOpt = $.extend({ + icon: getGenericMarkerIcon(color || '#a24ac3') + }, options); + + return L.marker(ll, markerOpt); +} + + // Fix Leaflet: handle touchcancel events in Draggable L.Draggable.prototype._onDownOrig = L.Draggable.prototype._onDown; diff --git a/plugins/distance-to-portal.user.js b/plugins/distance-to-portal.user.js index a32b4274..a0703c8f 100644 --- a/plugins/distance-to-portal.user.js +++ b/plugins/distance-to-portal.user.js @@ -85,19 +85,9 @@ window.plugin.distanceToPortal.setLocation = function() { window.plugin.distanceToPortal.currentLoc = map.getCenter(); } + window.plugin.distanceToPortal.currentLocMarker = createGenericMarker (window.plugin.distanceToPortal.currentLoc,'#444',{draggable:true}); - var markerTemplate = '@@INCLUDESTRING:images/marker-icon.svg.template@@'; - window.plugin.distanceToPortal.currentLocMarker = L.marker(window.plugin.distanceToPortal.currentLoc,{ - icon: L.divIcon({ - iconSize: new L.Point(25, 41), - iconAnchor: new L.Point(12, 41), - html: markerTemplate.replace(/%COLOR%/g, '#444'), - className: 'leaflet-iitc-distance-to-portal-location' - }), - draggable: true, - }); - - window.plugin.distanceToPortal.currentLocMarker.on('dragend', function(e) { + window.plugin.distanceToPortal.currentLocMarker.on('drag', function(e) { window.plugin.distanceToPortal.currentLoc = window.plugin.distanceToPortal.currentLocMarker.getLatLng(); localStorage['plugin-distance-to-portal'] = JSON.stringify({lat:window.plugin.distanceToPortal.currentLoc.lat, lng:window.plugin.distanceToPortal.currentLoc.lng});