/* * Leaflet Location Picker v0.3.4 - 2022-11-18 * * Copyright 2022 Stefano Cudini * stefano.cudini@gmail.com * https://opengeo.tech/ * * Licensed under the MIT license. * * Demo: * https://opengeo.tech/maps/leaflet-locationpicker/ * * Source: * git@github.com:stefanocudini/leaflet-locationpicker.git * */ !function(a){if("function"==typeof define&&define.amd)define(["jquery","leaflet"],a);else if("undefined"!=typeof module)module.exports=a(require("jquery","leaflet"));else{if(void 0===window.jQuery)throw"jQuery must be loaded first";if(void 0===window.L)throw"Leaflet must be loaded first";a(window.jQuery,window.L)}}(function(a,b){var c=a;c.fn.leafletLocationPicker=function(a,d){function e(c){return c?b.latLng(parseFloat(c.lat).toFixed(a.locationDigits),parseFloat(c.lng).toFixed(a.locationDigits)):c}function f(d){var f=d;switch(c.type(d)){case"string":var g=d.split(a.locationSep);f=g[0]&&g[1]?b.latLng(g):null;break;case"array":f=b.latLng(d);break;case"object":var h,i;d.hasOwnProperty("lat")?h=d.lat:d.hasOwnProperty("latitude")&&(h=d.latitude),d.hasOwnProperty("lng")?i=d.lng:d.hasOwnProperty("lon")?i=d.lon:d.hasOwnProperty("longitude")&&(i=d.longitude),f=b.latLng(parseFloat(h),parseFloat(i));break;default:f=d}return e(f)}function g(d){if(d.divMap=document.createElement("div"),d.$map=c(document.createElement("div")).addClass(a.className+"-map").height(a.height).width(a.width).append(d.divMap),a.readOnly&&d.$map.addClass("read-only"),a.mapContainer&&c(a.mapContainer)?d.$map.appendTo(a.mapContainer).addClass("map-select"):d.$map.appendTo("body"),d.location&&(a.map.center=d.location),"string"==typeof a.layer&&k[a.layer]?a.map.layers=b.tileLayer(k[a.layer]):a.layer instanceof b.TileLayer||a.layer instanceof b.GridLayer||a.layer instanceof b.LayerGroup?a.map.layers=a.layer:a.map.layers=b.tileLayer(k.OSM),d.map=b.map(d.divMap,a.map).addControl(b.control.zoom({position:"bottomright"})).on(a.event,function(b){a.readOnly||d.setLocation(b.latlng)}),a.activeOnMove&&d.map.on("move",function(a){d.setLocation(a.target.getCenter())}),!0!==a.alwaysOpen){var e=b.control({position:"topright"});e.onAdd=function(c){var e=b.DomUtil.create("div","leaflet-bar"),f=b.DomUtil.create("a","leaflet-control "+a.className+"-close");return f.innerHTML="×",e.appendChild(f),b.DomEvent.on(f,"click",b.DomEvent.stop,d).on(f,"click",d.closeMap,d),e},e.addTo(d.map)}return a.locationMarker&&(d.marker=h(d.location).addTo(d.map)),d.$map}function h(c){return b.marker(f(c)||b.latLng(0,0),{icon:b.divIcon({className:a.className+"-marker",iconAnchor:b.point(0,0),html:"
'})})}var i=window.location.protocol,j="leaflet-locpicker",k={OSM:i+"//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"},l={zoom:0,center:b.latLng([40,0]),zoomControl:!1,attributionControl:!1};c.isPlainObject(a)&&c.isPlainObject(a.map)&&(l=c.extend(l,a.map));var m={alwaysOpen:!1,className:j,location:l.center,locationFormat:"{lat}{sep}{lng}",locationMarker:!0,locationDigits:6,locationSep:",",position:"topright",layer:"OSM",height:140,width:200,event:"click",cursorSize:"30px",readOnly:!1,map:l,onChangeLocation:c.noop,mapContainer:""};return a=c.isPlainObject(a)?c.extend(m,a):c.isFunction(a)?c.extend(m,{onChangeLocation:a}):m,c.isFunction(d)&&(a=c.extend(m,{onChangeLocation:d})),c(this).each(function(d,e){var h=this;h.$input=c(this),h.options=a,h.setReadOnly=function(b){a.readOnly=b,h.$map.toggleClass("read-only",b)},h.locationOri=h.$input.val(),h.onChangeLocation=function(){var b={latlng:h.location,location:h.getLocation()};h.$input.trigger(c.extend(b,{type:"changeLocation"})),a.onChangeLocation.call(h,b)},h.setLocation=function(a,b){a=a||m.location,h.location=f(a),h.marker&&h.marker.setLatLng(a),b||(h.$input.data("location",h.location),h.$input.val(h.getLocation()),h.onChangeLocation())},h.getLocation=function(){return h.location?b.Util.template(a.locationFormat,{lat:h.location.lat,lng:h.location.lng,sep:a.locationSep}):h.location},h.updatePosition=function(){switch(a.position){case"bottomleft":h.$map.css({top:h.$input.offset().top+h.$input.height()+6,left:h.$input.offset().left});break;case"topright":h.$map.css({top:h.$input.offset().top,left:h.$input.offset().left+h.$input.width()+5})}},h.openMap=function(){h.updatePosition(),h.$map.show(),h.map.invalidateSize(),h.$input.trigger("show")},h.closeMap=function(){h.$map.hide(),h.$input.trigger("hide")},h.setLocation(h.locationOri,!0),h.$map=g(h),h.$input.addClass(a.className).on("focus."+a.className,function(a){a.preventDefault(),h.openMap()}).on("blur."+a.className,function(a){a.preventDefault();for(var b=a.relatedTarget,c=!0;b;){if(b._leaflet){c=!1;break}b=b.parentElement}c&&setTimeout(function(){h.closeMap()},100)}),c(window).on("resize",function(){h.$map.is(":visible")&&h.updatePosition()}),a.alwaysOpen&&!0===a.alwaysOpen&&h.openMap()}),this}});