diff --git a/dist/javascript/Leaflet.StyleEditor.min.js b/dist/javascript/Leaflet.StyleEditor.min.js index bdf735e..f191f65 100644 --- a/dist/javascript/Leaflet.StyleEditor.min.js +++ b/dist/javascript/Leaflet.StyleEditor.min.js @@ -1 +1 @@ -!function(t,e){"function"==typeof define&&define.amd?define(["leaflet"],t):"object"==typeof exports&&(module.exports=t(require("leaflet"))),void 0!==e&&e.L&&(e.L.StyleEditor=t(L))}(function(t){return{marker:{},forms:{},formElements:{}}},window),L.StyleEditor.Util=L.Class.extend({initialize:function(t){t&&L.setOptions(this,t)},fireChangeEvent:function(t){this.options.styleEditorOptions.map.fireEvent("styleeditor:changed",t)},hideElement:function(t){t&&L.DomUtil.addClass(t,"leaflet-styleeditor-hidden")},rgbToHex:function(t,e){if(t||(t=this.options.styleEditorOptions.defaultColor),0==t.indexOf("#"))return e&&t.replace("#",""),t;var o="";return t=t.substring(4).replace(")","").split(","),o=this._componentToHex(parseInt(t[0],10))+this._componentToHex(parseInt(t[1],10))+this._componentToHex(parseInt(t[2],10)),e?o:"#"+o},getCurrentElement:function(){return this.options.styleEditorOptions.currentElement?this.options.styleEditorOptions.currentElement.target:null},setCurrentElement:function(t){this.options.styleEditorOptions.currentElement.target=t},fillCurrentElement:function(){return this.getCurrentElement().options.fill},getStyle:function(t){var e=this.getCurrentElement().options[t];return e||null},setStyle:function(t,e){var o=this.getCurrentElement();if(o instanceof L.Marker)this.options.styleEditorOptions.markerType.setStyle(t,e);else{var i={};i[t]=e,o.setStyle(i)}this.fireChangeEvent(o)},showElement:function(t){t&&L.DomUtil.removeClass(t,"leaflet-styleeditor-hidden")},_componentToHex:function(t){var e=t.toString(16);return 1===e.length?"0"+e:e}}),L.StyleEditor.formElements.FormElement=L.Class.extend({initialize:function(t){t&&L.setOptions(this,t),this.options.styleOption&&(this.options.title=this.options.styleOption.charAt(0).toUpperCase()+this.options.styleOption.slice(1))},create:function(t){this.options.uiElement=L.DomUtil.create("div","leaflet-styleeditor-uiElement",t);this.createTitle(),this.createContent()},createTitle:function(){L.DomUtil.create("label","leaflet-styleeditor-label",this.options.uiElement).innerHTML=this.options.title+":"},createContent:function(){},show:function(){this.style(),this.showForm()},showForm:function(){this.options.styleEditorOptions.util.showElement(this.options.uiElement)},hide:function(){this.options.styleEditorOptions.util.hideElement(this.options.uiElement)},style:function(){},lostFocus:function(){},setStyle:function(t){var e=this.options.styleEditorOptions.util.getCurrentElement(),o=[e];e instanceof L.LayerGroup&&(o=Object.values(e._layers));for(var i=0;i=30?t[0]>=35?"l":"m":"s"},options:{markers:["circle-stroked","circle","square-stroked","square","triangle-stroked","triangle","star-stroked","star","cross","marker-stroked","marker","religious-jewish","religious-christian","religious-muslim","cemetery","rocket","airport","heliport","rail","rail-metro","rail-light","bus","fuel","parking","parking-garage","airfield","roadblock","ferry","harbor","bicycle","park","park2","museum","lodging","monument","zoo","garden","campsite","theatre","art-gallery","pitch","soccer","america-football","tennis","basketball","baseball","golf","swimming","cricket","skiing","school","college","library","post","fire-station","town-hall","police","prison","embassy","beer","restaurant","cafe","shop","fast-food","bar","bank","grocery","cinema","pharmacy","hospital","danger","industrial","warehouse","commercial","building","place-of-worship","alcohol-shop","logging","oil-well","slaughterhouse","dam","water","wetland","disability","telephone","emergency-telephone","toilets","waste-basket","music","land-use","city","town","village","farm","bakery","dog-park","lighthouse","clothing-store","polling-place","playground","entrance","heart","london-underground","minefield","rail-underground","rail-above","camera","laundry","car","suitcase","hairdresser","chemist","mobilephone","scooter"]}}),L.StyleEditor.marker.GlyphiconMarker=L.StyleEditor.marker.Marker.extend({getMarkerHtml:function(t,e,o){var i=this._getMarkerUrl(t,e);return'
'},createMarkerIcon:function(t){var e=t.iconSize;return new L.divIcon({className:"leaflet-styleeditor-glyphicon-marker-wrapper",html:this.getMarkerHtml(e,t.iconColor,t.icon),icon:t.icon,iconColor:t.iconColor,iconSize:e,iconAnchor:[e[0]/2,e[1]/2],popupAnchor:[0,-e[1]/2]})},setStyle:function(t,e){"icon"!=t&&(t="icon"+t.charAt(0).toUpperCase()+t.slice(1));var o=this.options.iconOptions;o[t]!=e&&(o[t]=e,this.setNewMarker())},createSelectHTML:function(t,e,o){t.innerHTML=this.getMarkerHtml("s",e.iconColor,o)},_size:function(t){return t[0]>=30?t[0]>=35?"l":"m":"s"},_getMarkerUrlForStyle:function(t){return this._getMarkerUrl(t.iconSize,t.iconColor,t.icon)},_getMarkerUrl:function(t,e,o){return"http://api.tiles.mapbox.com/v3/marker/pin-"+(t=this._size(t))+"+"+(e=0==e.indexOf("#")?e.replace("#",""):this.options.styleEditorOptions.util.rgbToHex(e,!0))+".png"},options:{markers:["glyphicon-plus","glyphicon-asterisk","glyphicon-plus","glyphicon-euro","glyphicon-minus","glyphicon-cloud","glyphicon-envelope","glyphicon-pencil","glyphicon-glass","glyphicon-music","glyphicon-search","glyphicon-heart","glyphicon-star","glyphicon-star-empty","glyphicon-user","glyphicon-film","glyphicon-th-large","glyphicon-th","glyphicon-th-list","glyphicon-ok","glyphicon-remove","glyphicon-zoom-in","glyphicon-zoom-out","glyphicon-off","glyphicon-signal","glyphicon-cog","glyphicon-trash","glyphicon-home","glyphicon-file","glyphicon-time","glyphicon-road","glyphicon-download-alt","glyphicon-download","glyphicon-upload","glyphicon-inbox","glyphicon-play-circle","glyphicon-repeat","glyphicon-refresh","glyphicon-list-alt","glyphicon-lock","glyphicon-flag","glyphicon-headphones","glyphicon-volume-off","glyphicon-volume-down","glyphicon-volume-up","glyphicon-qrcode","glyphicon-barcode","glyphicon-tag","glyphicon-tags","glyphicon-book","glyphicon-bookmark","glyphicon-print","glyphicon-camera","glyphicon-font","glyphicon-bold","glyphicon-italic","glyphicon-text-height","glyphicon-text-width","glyphicon-align-left","glyphicon-align-center","glyphicon-align-right","glyphicon-align-justify","glyphicon-list","glyphicon-indent-left","glyphicon-indent-right","glyphicon-facetime-video","glyphicon-picture","glyphicon-map-marker","glyphicon-adjust","glyphicon-tint","glyphicon-edit","glyphicon-share","glyphicon-check","glyphicon-move","glyphicon-chevron-right","glyphicon-plus-sign","glyphicon-minus-sign","glyphicon-remove-sign","glyphicon-ok-sign","glyphicon-question-sign","glyphicon-info-sign","glyphicon-screenshot","glyphicon-remove-circle","glyphicon-ok-circle","glyphicon-ban-circle","glyphicon-arrow-left","glyphicon-arrow-right","glyphicon-arrow-up","glyphicon-arrow-down","glyphicon-share-alt","glyphicon-resize-full","glyphicon-resize-small","glyphicon-exclamation-sign","glyphicon-gift","glyphicon-leaf","glyphicon-fire","glyphicon-eye-open","glyphicon-eye-close","glyphicon-warning-sign","glyphicon-plane","glyphicon-calendar","glyphicon-random","glyphicon-comment","glyphicon-magnet","glyphicon-chevron-up","glyphicon-chevron-down","glyphicon-retweet","glyphicon-shopping-cart","glyphicon-bullhorn","glyphicon-bell","glyphicon-certificate","glyphicon-thumbs-up","glyphicon-thumbs-down","glyphicon-hand-right","glyphicon-hand-left","glyphicon-hand-up","glyphicon-hand-down","glyphicon-circle-arrow-right","glyphicon-circle-arrow-left","glyphicon-circle-arrow-up","glyphicon-circle-arrow-down","glyphicon-globe","glyphicon-wrench","glyphicon-tasks","glyphicon-filter","glyphicon-briefcase","glyphicon-fullscreen","glyphicon-dashboard","glyphicon-paperclip","glyphicon-heart-empty","glyphicon-link","glyphicon-phone","glyphicon-pushpin","glyphicon-usd"]}}),L.StyleForm=L.Class.extend({initialize:function(t){L.setOptions(this,t),this.createMarkerForm(),this.createGeometryForm(),this.addDOMEvents()},addDOMEvents:function(){L.DomEvent.addListener(this.options.styleEditorOptions.map,"click",this.lostFocus,this),L.DomEvent.addListener(this.options.styleEditorDiv,"click",this.lostFocus,this)},clearForm:function(){this.options.styleEditorOptions.markerForm.hide(),this.options.styleEditorOptions.geometryForm.hide()},createMarkerForm:function(){var t=L.DomUtil.create("div","leaflet-styleeditor-interior-marker",this.options.styleEditorInterior);this.options.styleEditorOptions.markerForm.create(t)},createGeometryForm:function(){var t=L.DomUtil.create("div","leaflet-styleeditor-interior-geometry",this.options.styleEditorInterior);this.options.styleEditorOptions.geometryForm.create(t)},showMarkerForm:function(){this.clearForm(),this.options.styleEditorOptions.markerForm.show()},showGeometryForm:function(){this.clearForm(),this.options.styleEditorOptions.geometryForm.show()},fireChangeEvent:function(t){this.options.styleEditorOptions.map.fireEvent("styleeditor:changed",t)},lostFocus:function(t){for(var e=t.target,o=0;o<10&&e;o++){if(e.className&&L.DomUtil.hasClass(e,"leaflet-styleeditor-interior"))return;e=e.parentNode}this.options.styleEditorOptions.markerForm.lostFocus(),this.options.styleEditorOptions.geometryForm.lostFocus()}}),L.Control.StyleEditor=L.Control.extend({options:{position:"topleft",enabled:!1,colorRamp:["#1abc9c","#2ecc71","#3498db","#9b59b6","#34495e","#16a085","#27ae60","#2980b9","#8e44ad","#2c3e50","#f1c40f","#e67e22","#e74c3c","#ecf0f1","#95a5a6","#f39c12","#d35400","#c0392b","#bdc3c7","#7f8c8d"],defaultColor:"f39c12",currentElement:null,markerType:L.StyleEditor.marker.DefaultMarker,geometryForm:L.StyleEditor.forms.GeometryForm,editLayers:[],layerGroups:[],openOnLeafletDraw:!0,showTooltip:!0,strings:{tooltip:"Click on the element you want to style",tooltipNext:"Choose another element you want to style"},useGrouping:!0},initialize:function(t){t&&L.setOptions(this,t),this.options.util=new L.StyleEditor.Util({styleEditorOptions:this.options}),this.options.markerType=new this.options.markerType({styleEditorOptions:this.options}),this.options.markerForm=new this.options.markerType.markerForm({styleEditorOptions:this.options}),this.options.geometryForm=new this.options.geometryForm({styleEditorOptions:this.options})},onAdd:function(t){return this.options.map=t,this.createUi()},createUi:function(){var t=this.options.controlDiv=L.DomUtil.create("div","leaflet-control-styleeditor leaflet-bar");(this.options.controlUI=L.DomUtil.create("a","leaflet-control-styleeditor-interior",t)).title="Style Editor";var e=this.options.styleEditorDiv=L.DomUtil.create("div","leaflet-styleeditor",this.options.map._container);this.options.styleEditorHeader=L.DomUtil.create("div","leaflet-styleeditor-header",e);var o=L.DomUtil.create("div","leaflet-styleeditor-interior",e);return this.addDomEvents(),this.addLeafletDrawEvents(),this.addButtons(),this.options.styleForm=new L.StyleForm({styleEditorDiv:e,styleEditorInterior:o,styleEditorOptions:this.options}),t},addDomEvents:function(){L.DomEvent.addListener(this.options.controlDiv,"click",function(t){this.clickHandler(t),t.stopPropagation()},this),L.DomEvent.addListener(this.options.controlDiv,"dblclick",function(t){t.stopPropagation()},this),L.DomEvent.addListener(this.options.styleEditorDiv,"click",L.DomEvent.stopPropagation),L.DomEvent.addListener(this.options.styleEditorDiv,"mouseenter",this.disableLeafletActions,this),L.DomEvent.addListener(this.options.styleEditorDiv,"mouseleave",this.enableLeafletActions,this)},addLeafletDrawEvents:function(){this.options.openOnLeafletDraw&&L.Control.Draw&&this.options.map.on("draw:created",function(t){this.initChangeStyle({target:t.layer})},this)},addButtons:function(){var t=L.DomUtil.create("button","leaflet-styleeditor-button styleeditor-nextBtn",this.options.styleEditorHeader);t.title=this.options.strings.tooltipNext,L.DomEvent.addListener(t,"click",function(t){this.hideEditor(),L.DomUtil.hasClass(this.options.controlUI,"enabled")&&this.createTooltip(),t.stopPropagation()},this)},clickHandler:function(t){this.options.enabled=!this.options.enabled,this.options.enabled?this.enable():(L.DomUtil.removeClass(this.options.controlUI,"enabled"),this.disable())},disableLeafletActions:function(){var t=this.options.map;t.dragging.disable(),t.touchZoom.disable(),t.doubleClickZoom.disable(),t.scrollWheelZoom.disable(),t.boxZoom.disable(),t.keyboard.disable()},enableLeafletActions:function(){var t=this.options.map;t.dragging.enable(),t.touchZoom.enable(),t.doubleClickZoom.enable(),t.scrollWheelZoom.enable(),t.boxZoom.enable(),t.keyboard.enable()},enable:function(){L.DomUtil.addClass(this.options.controlUI,"enabled"),this.options.map.eachLayer(this.addEditClickEvents,this),this.createTooltip()},disable:function(){this.options.editLayers.forEach(this.removeEditClickEvents,this),this.options.editLayers=[],this.options.layerGroups=[],this.hideEditor(),this.removeTooltip()},addEditClickEvents:function(t){if(this.options.useGrouping&&t instanceof L.LayerGroup)this.options.layerGroups.push(t);else if(t instanceof L.Marker||t instanceof L.Path){var e=t.on("click",this.initChangeStyle,this);this.options.editLayers.push(e)}},removeEditClickEvents:function(t){t.off("click",this.initChangeStyle,this)},hideEditor:function(){L.DomUtil.removeClass(this.options.styleEditorDiv,"editor-enabled")},showEditor:function(){var t=this.options.styleEditorDiv;L.DomUtil.hasClass(t,"editor-enabled")||L.DomUtil.addClass(t,"editor-enabled")},initChangeStyle:function(t){this.options.currentElement=this.options.useGrouping?this.getMatchingElement(t):t,this.showEditor(),this.removeTooltip(),t.target instanceof L.Marker?this.showMarkerForm():this.showGeometryForm()},showGeometryForm:function(){this.options.styleForm.showGeometryForm()},showMarkerForm:function(){this.options.styleForm.showMarkerForm()},createTooltip:function(){this.options.showTooltip&&(this.options.tooltipWrapper||(this.options.tooltipWrapper=L.DomUtil.create("div","leaflet-styleeditor-tooltip-wrapper",this.options.map.getContainer())),this.options.tooltip||(this.options.tooltip=L.DomUtil.create("div","leaflet-styleeditor-tooltip",this.options.tooltipWrapper)),this.options.tooltip.innerHTML=this.options.strings.tooltip)},getMatchingElement:function(t){for(var e=null,o=t.target,i=0;io.includes(t))}return e},getDefaultMarkerForColor:function(t){t=this.rgbToHex(t);var e=this.getMarkersForColor(t),o=[],i=this.options.styleEditorOptions.defaultMarker;return null!=i&&("string"==typeof i&&o.push(i),Object.keys(i).includes(t)&&o.push(i[t])),void 0!=(i=this.options.styleEditorOptions.markerType.options.defaultMarker)&&("string"==typeof i&&o.push(i),Object.keys(i).includes(t)&&o.push(i[t])),o.filter(t=>e.includes(t)),o.length>0?o[0]:e[0]}}),L.StyleEditor.formElements.FormElement=L.Class.extend({initialize:function(t){t&&L.setOptions(this,t),this.options.styleOption&&(this.options.title=this.options.styleOption.charAt(0).toUpperCase()+this.options.styleOption.slice(1))},create:function(t){this.options.uiElement=L.DomUtil.create("div","leaflet-styleeditor-uiElement",t);this.createTitle(),this.createContent()},createTitle:function(){L.DomUtil.create("label","leaflet-styleeditor-label",this.options.uiElement).innerHTML=this.options.title+":"},createContent:function(){},show:function(){this.style(),this.showForm()},showForm:function(){this.options.styleEditorOptions.util.showElement(this.options.uiElement)},hide:function(){this.options.styleEditorOptions.util.hideElement(this.options.uiElement)},style:function(){},lostFocus:function(){},setStyle:function(t){var e=this.options.styleEditorOptions.util.getCurrentElement(),o=[e];e instanceof L.LayerGroup&&(o=Object.values(e._layers));for(var i=0;i=30?t[0]>=35?"l":"m":"s"},options:{markers:["circle-stroked","circle","square-stroked","square","triangle-stroked","triangle","star-stroked","star","cross","marker-stroked","marker","religious-jewish","religious-christian","religious-muslim","cemetery","rocket","airport","heliport","rail","rail-metro","rail-light","bus","fuel","parking","parking-garage","airfield","roadblock","ferry","harbor","bicycle","park","park2","museum","lodging","monument","zoo","garden","campsite","theatre","art-gallery","pitch","soccer","america-football","tennis","basketball","baseball","golf","swimming","cricket","skiing","school","college","library","post","fire-station","town-hall","police","prison","embassy","beer","restaurant","cafe","shop","fast-food","bar","bank","grocery","cinema","pharmacy","hospital","danger","industrial","warehouse","commercial","building","place-of-worship","alcohol-shop","logging","oil-well","slaughterhouse","dam","water","wetland","disability","telephone","emergency-telephone","toilets","waste-basket","music","land-use","city","town","village","farm","bakery","dog-park","lighthouse","clothing-store","polling-place","playground","entrance","heart","london-underground","minefield","rail-underground","rail-above","camera","laundry","car","suitcase","hairdresser","chemist","mobilephone","scooter"]}}),L.StyleEditor.marker.GlyphiconMarker=L.StyleEditor.marker.Marker.extend({getMarkerHtml:function(t,e,o){var i=this._getMarkerUrl(t,e);return'
'},createMarkerIcon:function(t){var e=t.iconSize;return new L.divIcon({className:"leaflet-styleeditor-glyphicon-marker-wrapper",html:this.getMarkerHtml(e,t.iconColor,t.icon),icon:t.icon,iconColor:t.iconColor,iconSize:e,iconAnchor:[e[0]/2,e[1]/2],popupAnchor:[0,-e[1]/2]})},setStyle:function(t,e){"icon"!=t&&(t="icon"+t.charAt(0).toUpperCase()+t.slice(1));var o=this.options.iconOptions;o[t]!=e&&(o[t]=e,this.setNewMarker())},createSelectHTML:function(t,e,o){t.innerHTML=this.getMarkerHtml("s",e.iconColor,o)},_size:function(t){return t[0]>=30?t[0]>=35?"l":"m":"s"},_getMarkerUrlForStyle:function(t){return this._getMarkerUrl(t.iconSize,t.iconColor,t.icon)},_getMarkerUrl:function(t,e,o){return"http://api.tiles.mapbox.com/v3/marker/pin-"+(t=this._size(t))+"+"+(e=0==e.indexOf("#")?e.replace("#",""):this.options.styleEditorOptions.util.rgbToHex(e,!0))+".png"},options:{markers:["glyphicon-plus","glyphicon-asterisk","glyphicon-plus","glyphicon-euro","glyphicon-minus","glyphicon-cloud","glyphicon-envelope","glyphicon-pencil","glyphicon-glass","glyphicon-music","glyphicon-search","glyphicon-heart","glyphicon-star","glyphicon-star-empty","glyphicon-user","glyphicon-film","glyphicon-th-large","glyphicon-th","glyphicon-th-list","glyphicon-ok","glyphicon-remove","glyphicon-zoom-in","glyphicon-zoom-out","glyphicon-off","glyphicon-signal","glyphicon-cog","glyphicon-trash","glyphicon-home","glyphicon-file","glyphicon-time","glyphicon-road","glyphicon-download-alt","glyphicon-download","glyphicon-upload","glyphicon-inbox","glyphicon-play-circle","glyphicon-repeat","glyphicon-refresh","glyphicon-list-alt","glyphicon-lock","glyphicon-flag","glyphicon-headphones","glyphicon-volume-off","glyphicon-volume-down","glyphicon-volume-up","glyphicon-qrcode","glyphicon-barcode","glyphicon-tag","glyphicon-tags","glyphicon-book","glyphicon-bookmark","glyphicon-print","glyphicon-camera","glyphicon-font","glyphicon-bold","glyphicon-italic","glyphicon-text-height","glyphicon-text-width","glyphicon-align-left","glyphicon-align-center","glyphicon-align-right","glyphicon-align-justify","glyphicon-list","glyphicon-indent-left","glyphicon-indent-right","glyphicon-facetime-video","glyphicon-picture","glyphicon-map-marker","glyphicon-adjust","glyphicon-tint","glyphicon-edit","glyphicon-share","glyphicon-check","glyphicon-move","glyphicon-chevron-right","glyphicon-plus-sign","glyphicon-minus-sign","glyphicon-remove-sign","glyphicon-ok-sign","glyphicon-question-sign","glyphicon-info-sign","glyphicon-screenshot","glyphicon-remove-circle","glyphicon-ok-circle","glyphicon-ban-circle","glyphicon-arrow-left","glyphicon-arrow-right","glyphicon-arrow-up","glyphicon-arrow-down","glyphicon-share-alt","glyphicon-resize-full","glyphicon-resize-small","glyphicon-exclamation-sign","glyphicon-gift","glyphicon-leaf","glyphicon-fire","glyphicon-eye-open","glyphicon-eye-close","glyphicon-warning-sign","glyphicon-plane","glyphicon-calendar","glyphicon-random","glyphicon-comment","glyphicon-magnet","glyphicon-chevron-up","glyphicon-chevron-down","glyphicon-retweet","glyphicon-shopping-cart","glyphicon-bullhorn","glyphicon-bell","glyphicon-certificate","glyphicon-thumbs-up","glyphicon-thumbs-down","glyphicon-hand-right","glyphicon-hand-left","glyphicon-hand-up","glyphicon-hand-down","glyphicon-circle-arrow-right","glyphicon-circle-arrow-left","glyphicon-circle-arrow-up","glyphicon-circle-arrow-down","glyphicon-globe","glyphicon-wrench","glyphicon-tasks","glyphicon-filter","glyphicon-briefcase","glyphicon-fullscreen","glyphicon-dashboard","glyphicon-paperclip","glyphicon-heart-empty","glyphicon-link","glyphicon-phone","glyphicon-pushpin","glyphicon-usd"]}}),L.StyleForm=L.Class.extend({initialize:function(t){L.setOptions(this,t),this.createMarkerForm(),this.createGeometryForm(),this.addDOMEvents()},addDOMEvents:function(){L.DomEvent.addListener(this.options.styleEditorOptions.map,"click",this.lostFocus,this),L.DomEvent.addListener(this.options.styleEditorDiv,"click",this.lostFocus,this)},clearForm:function(){this.options.styleEditorOptions.markerForm.hide(),this.options.styleEditorOptions.geometryForm.hide()},createMarkerForm:function(){var t=L.DomUtil.create("div","leaflet-styleeditor-interior-marker",this.options.styleEditorInterior);this.options.styleEditorOptions.markerForm.create(t)},createGeometryForm:function(){var t=L.DomUtil.create("div","leaflet-styleeditor-interior-geometry",this.options.styleEditorInterior);this.options.styleEditorOptions.geometryForm.create(t)},showMarkerForm:function(){this.clearForm(),this.options.styleEditorOptions.markerForm.show()},showGeometryForm:function(){this.clearForm(),this.options.styleEditorOptions.geometryForm.show()},fireChangeEvent:function(t){this.options.styleEditorOptions.map.fireEvent("styleeditor:changed",t)},lostFocus:function(t){for(var e=t.target,o=0;o<10&&e;o++){if(e.className&&L.DomUtil.hasClass(e,"leaflet-styleeditor-interior"))return;e=e.parentNode}this.options.styleEditorOptions.markerForm.lostFocus(),this.options.styleEditorOptions.geometryForm.lostFocus()}}),L.Control.StyleEditor=L.Control.extend({options:{position:"topleft",enabled:!1,colorRamp:["#1abc9c","#2ecc71","#3498db","#9b59b6","#34495e","#16a085","#27ae60","#2980b9","#8e44ad","#2c3e50","#f1c40f","#e67e22","#e74c3c","#ecf0f1","#95a5a6","#f39c12","#d35400","#c0392b","#bdc3c7","#7f8c8d"],defaultColor:null,currentElement:null,markerType:L.StyleEditor.marker.DefaultMarker,geometryForm:L.StyleEditor.forms.GeometryForm,editLayers:[],layerGroups:[],openOnLeafletDraw:!0,showTooltip:!0,strings:{tooltip:"Click on the element you want to style",tooltipNext:"Choose another element you want to style"},markers:null,defaultMarker:null,useGrouping:!0},initialize:function(t){t&&L.setOptions(this,t),this.options.util=new L.StyleEditor.Util({styleEditorOptions:this.options}),this.options.markerType=new this.options.markerType({styleEditorOptions:this.options}),this.options.markerForm=new this.options.markerType.markerForm({styleEditorOptions:this.options}),this.options.geometryForm=new this.options.geometryForm({styleEditorOptions:this.options})},onAdd:function(t){return this.options.map=t,this.createUi()},createUi:function(){var t=this.options.controlDiv=L.DomUtil.create("div","leaflet-control-styleeditor leaflet-bar");(this.options.controlUI=L.DomUtil.create("a","leaflet-control-styleeditor-interior",t)).title="Style Editor";var e=this.options.styleEditorDiv=L.DomUtil.create("div","leaflet-styleeditor",this.options.map._container);this.options.styleEditorHeader=L.DomUtil.create("div","leaflet-styleeditor-header",e);var o=L.DomUtil.create("div","leaflet-styleeditor-interior",e);return this.addDomEvents(),this.addLeafletDrawEvents(),this.addButtons(),this.options.styleForm=new L.StyleForm({styleEditorDiv:e,styleEditorInterior:o,styleEditorOptions:this.options}),t},addDomEvents:function(){L.DomEvent.addListener(this.options.controlDiv,"click",function(t){this.clickHandler(t),t.stopPropagation()},this),L.DomEvent.addListener(this.options.controlDiv,"dblclick",function(t){t.stopPropagation()},this),L.DomEvent.addListener(this.options.styleEditorDiv,"click",L.DomEvent.stopPropagation),L.DomEvent.addListener(this.options.styleEditorDiv,"mouseenter",this.disableLeafletActions,this),L.DomEvent.addListener(this.options.styleEditorDiv,"mouseleave",this.enableLeafletActions,this)},addLeafletDrawEvents:function(){this.options.openOnLeafletDraw&&L.Control.Draw&&this.options.map.on("draw:created",function(t){this.initChangeStyle({target:t.layer})},this)},addButtons:function(){var t=L.DomUtil.create("button","leaflet-styleeditor-button styleeditor-nextBtn",this.options.styleEditorHeader);t.title=this.options.strings.tooltipNext,L.DomEvent.addListener(t,"click",function(t){this.hideEditor(),L.DomUtil.hasClass(this.options.controlUI,"enabled")&&this.createTooltip(),t.stopPropagation()},this)},clickHandler:function(t){this.options.enabled=!this.options.enabled,this.options.enabled?this.enable():(L.DomUtil.removeClass(this.options.controlUI,"enabled"),this.disable())},disableLeafletActions:function(){var t=this.options.map;t.dragging.disable(),t.touchZoom.disable(),t.doubleClickZoom.disable(),t.scrollWheelZoom.disable(),t.boxZoom.disable(),t.keyboard.disable()},enableLeafletActions:function(){var t=this.options.map;t.dragging.enable(),t.touchZoom.enable(),t.doubleClickZoom.enable(),t.scrollWheelZoom.enable(),t.boxZoom.enable(),t.keyboard.enable()},enable:function(){L.DomUtil.addClass(this.options.controlUI,"enabled"),this.options.map.eachLayer(this.addEditClickEvents,this),this.createTooltip()},disable:function(){this.options.editLayers.forEach(this.removeEditClickEvents,this),this.options.editLayers=[],this.options.layerGroups=[],this.hideEditor(),this.removeTooltip()},addEditClickEvents:function(t){if(this.options.useGrouping&&t instanceof L.LayerGroup)this.options.layerGroups.push(t);else if(t instanceof L.Marker||t instanceof L.Path){var e=t.on("click",this.initChangeStyle,this);this.options.editLayers.push(e)}},removeEditClickEvents:function(t){t.off("click",this.initChangeStyle,this)},hideEditor:function(){L.DomUtil.removeClass(this.options.styleEditorDiv,"editor-enabled")},showEditor:function(){var t=this.options.styleEditorDiv;L.DomUtil.hasClass(t,"editor-enabled")||L.DomUtil.addClass(t,"editor-enabled")},initChangeStyle:function(t){this.options.currentElement=this.options.useGrouping?this.getMatchingElement(t):t,this.showEditor(),this.removeTooltip(),t.target instanceof L.Marker?this.showMarkerForm():this.showGeometryForm()},showGeometryForm:function(){this.options.styleForm.showGeometryForm()},showMarkerForm:function(){this.options.styleForm.showMarkerForm()},createTooltip:function(){this.options.showTooltip&&(this.options.tooltipWrapper||(this.options.tooltipWrapper=L.DomUtil.create("div","leaflet-styleeditor-tooltip-wrapper",this.options.map.getContainer())),this.options.tooltip||(this.options.tooltip=L.DomUtil.create("div","leaflet-styleeditor-tooltip",this.options.tooltipWrapper)),this.options.tooltip.innerHTML=this.options.strings.tooltip)},getMatchingElement:function(t){for(var e=null,o=t.target,i=0;i controlMarkers.includes(n)) + } + return markers; + }, + + /** get default marker for specific color **/ + getDefaultMarkerForColor: function(color) { + color = this.rgbToHex(color); + + var markers = this.getMarkersForColor(color); + + var defMarkers = []; + + var defaultMarker = this.options.styleEditorOptions.defaultMarker; + if (defaultMarker != null) { + if (typeof defaultMarker === 'string') { + defMarkers.push(defaultMarker); + } + if (Object.keys(defaultMarker).includes(color)) { + defMarkers.push(defaultMarker[color]); + } + + } + + defaultMarker = this.options.styleEditorOptions.markerType.options.defaultMarker; + if (defaultMarker != undefined) { + if (typeof defaultMarker === 'string') { + defMarkers.push(defaultMarker); + } + if (Object.keys(defaultMarker).includes(color)) { + defMarkers.push(defaultMarker[color]); + } + } + + defMarkers.filter((n) => markers.includes(n)); + if (defMarkers.length > 0) { + return defMarkers[0]; + } + + return markers[0]; + } + });