pointsight/static/js/leaflet-search/leaflet-search.js

10 lines
9.8 KiB
JavaScript
Raw Normal View History

2022-03-06 18:36:36 +01:00
/*!
* LeafletSearch 1.0.1
* (c) 2021 Sjaak Priester, Amsterdam
* MIT License
* https://github.com/sjaakp/leaflet-search
* https://sjaakpriester.nl
*/
!function(){"use strict";!function(t){if(!t||"undefined"==typeof window)return;const e=document.createElement("style");e.setAttribute("type","text/css"),e.innerHTML=t,document.head.appendChild(e)}(".geo-search svg{display:block;width:100%;height:100%;position:relative}.geo-search input{transition:width .4s;width:0;padding:2px 0;border:solid #888;border-width:1px 0;outline:0}.geo-search.open input{width:15em;padding:2px 2px;border-width:1px;border-top-left-radius:4px;border-bottom-left-radius:4px}.geo-search button{background-color:#fff;border:none;border:1px solid #ccc;width:26px;height:26px;line-height:26px;display:block;text-align:center;text-decoration:none;color:#000;background-position:50% 50%;background-repeat:no-repeat;overflow:hidden;border-top-left-radius:4px;border-top-right-radius:4px;border-bottom-left-radius:4px;border-bottom-right-radius:4px;display:block}.geo-search button:hover{background-color:#ddd}"),L.geo={Geocoder:L.Class.extend({initialize:function(t,e){this._map=t,L.setOptions(this,e)},constructUrl:function(t,e){void 0===e&&(e={});var n=Object.assign({},this.options,e),o=new URL(t);for(var r in n)o.searchParams.set(r,n[r]);return o},fetchJson:function(t){return fetch(t.href).then((function(t){return t.json()}))},placeMarker:function(t,e,n){this._map.placeMarker(t,e,n)},fire:function(t){this._map.fire(t)},suggest:function(t,e){},lookup:function(t){}})},L.geo.Nominatim=L.geo.Geocoder.extend({url:"https://nominatim.openstreetmap.org/",mark:function(t){var e=L.latLng(t.lat,t.lon),n=t.boundingbox,o=L.latLngBounds([n[0],n[2]],[n[1],n[3]]);this.placeMarker(e,o,t)},search:function(t){var e=this.constructUrl(this.url+"search",{format:"json",q:t});return this.fetchJson(e)},suggest:function(t,e){var n=this;this.search(t).then((function(t){e.innerHTML=t.reduce((function(t,e){return t+'<option data-id="'+e.osm_type.charAt(0).toUpperCase()+e.osm_id+'">'+e.display_name+"</option>"}),"")})).catch((function(t){return n.fire(t)}))},lookup:function(t){var e=this,n=this.constructUrl(this.url+"reverse",{format:"json",osm_type:t.charAt(0),osm_id:t.slice(1)});this.fetchJson(n).then((function(t){return e.mark(t)})).catch((function(t){return e.fire(t)}))},geocode:function(t){var e=this;this.search(t).then((function(t){if(t.length<1)throw"notfound";return t[0]})).then((function(t){return e.mark(t)})).catch((function(t){return e.fire(t)}))}}),L.geo.GeoNames=L.geo.Geocoder.extend({url:"http://api.geonames.org/search",fetchGeonames:function(t){return this.fetchJson(t).then((function(t){var e=t.geonames;if(!e||e.length<1)throw"notfound";return e}))},mark:function(t){var e=L.latLng(t.lat,t.lng),n=t.bbox,o=L.latLngBounds([n.north,n.west],[n.south,n.east]);this.placeMarker(e,o,t)},suggest:function(t,e){var n=this,o=this.constructUrl(this.url,{q:t,type:"json",style:"short"});this.fetchGeonames(o).then((function(t){e.innerHTML=t.reduce((function(t,e){return t+'<option data-id="'+e.geonameId+'">'+e.name+"&emsp;"+e.countryCode+"</option>"}),"")})).catch((function(t){return n.fire(t)}))},lookup:function(t){var e=this,n=this.constructUrl("http://api.geonames.org/getJSON",{geonameId:t});this.fetchJson(n).then((function(t){return e.mark(t)})).catch((function(t){return e.fire(t)}))},geocode:function(t){var e=this,n=this.constructUrl(this.url,{q:t,inclBbox:!0});this.fetchGeonames(n).then((function(t){return t.shift()})).then((function(t){return e.mark(t)})).catch((function(t){return e.fire(t)}))}}),L.geo.Here=L.geo.Geocoder.extend({mark:function(t){var e=t.displayPosition,n=L.latLng(e.latitude,e.longitude),o=t.mapView,r=o.topLeft,i=o.bottomRight,s=L.latLngBounds([r.latitude,i.longitude],[i.latitude,r.longitude]);this.placeMarker(n,s,t)},fetchData:function(t){var e=this;t.jsonattributes=1;var n=this.constructUrl("https://geocoder.ls.hereapi.com/6.2/geocode.json",t);this.fetchJson(n).then((function(t){return t.response.view.shift().result.shift()})).then((function(t){return e.mark(t.location)})).catch((function(t){return e.fire(t)}))},suggest:function(t,e){var n=this,o=this.constructUrl("https://autocomplete.geocoder.ls.hereapi.com/6.2/sugges
//# sourceMappingURL=leaflet-search.js.map