@openremote/or-map 1.15.1 → 1.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/umd/index.bundle.js +1 -1
- package/dist/umd/index.bundle.js.map +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/index.orbundle.js +2 -2
- package/dist/umd/index.orbundle.js.map +1 -1
- package/lib/mapwidget.d.ts.map +1 -1
- package/lib/mapwidget.js +1 -1
- package/lib/mapwidget.js.map +1 -1
- package/package.json +7 -6
- package/stories/map.stories.ts +106 -0
package/dist/umd/index.js
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
L ${n+i*d} ${n+i*m}
|
|
20
20
|
A ${i} ${i} 0 ${p} 0 ${n+i*c} ${n+i*s}
|
|
21
21
|
"
|
|
22
|
-
/>`}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.onClick)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.onClick)}onClick(){var t,e,n,i;return t=this,e=void 0,n=void 0,i=function*(){if(this.lng&&this.lat){let t=yield this._map.getSource("mapPoints").getClusterExpansionZoom(this._clusterId);this._map.easeTo({center:[this.lng,this.lat],zoom:t+.99,essential:!0})}},new(n||(n=Promise))(function(r,o){function a(t){try{c(i.next(t))}catch(t){o(t)}}function l(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):((e=t.value)instanceof n?e:new n(function(t){t(e)})).then(a,l)}c((i=i.apply(t,e||[])).next())})}};t2=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([tM("or-cluster-marker")],t2);var t5=function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function a(t){try{c(i.next(t))}catch(t){o(t)}}function l(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):((e=t.value)instanceof n?e:new n(function(t){t(e)})).then(a,l)}c((i=i.apply(t,e||[])).next())})};let t3=s(977),t4=s(126),t7=s(561);class t6{constructor(t,e,n,i=!1,r=!1,o=!0,a=!0,l){this._loaded=!1,this._markersJs=new Map,this._markersGl=new Map,this._geoJsonSources=[],this._geoJsonLayers=new Map,this._showGeoCodingControl=!1,this._showBoundaryBox=!1,this._useZoomControls=!0,this._showGeoJson=!0,this._clickHandlers=new Map,this._pointsMap={type:"FeatureCollection",features:[]},this._assetTypeColors={},this._cachedMarkers={},this._markersOnScreen={},this._assetsOnScreen={},this._type=t,this._styleParent=e,this._mapContainer=n,this._showGeoCodingControl=i,this._showBoundaryBox=r,this._useZoomControls=o,this._showGeoJson=a,this._clusterConfig=l}setCenter(t){switch(this._center=tj(t),this._type){case"RASTER":if(this._mapJs){let t=tj(this._center)||(this._viewSettings?tj(this._viewSettings.center):void 0);t&&this._mapJs.setView(t,void 0,{pan:{animate:!1},zoom:{animate:!1}})}break;case"VECTOR":this._mapGl&&this._center&&this._mapGl.setCenter(this._center)}return this}flyTo(t,e){switch(this._type){case"RASTER":this._mapJs;break;case"VECTOR":t||(t=this._center?this._center:this._viewSettings?this._viewSettings.center:void 0),e||(e=this._zoom?this._zoom:this._viewSettings&&this._viewSettings.zoom?this._viewSettings.zoom:void 0),this._mapGl?t&&this._mapGl.flyTo({center:t,zoom:e}):(this._center=t,this._zoom=e)}return this}resize(){switch(this._type){case"RASTER":this._mapJs;break;case"VECTOR":this._mapGl&&this._mapGl.resize()}return this}setZoom(t){switch(this._zoom=t,this._type){case"RASTER":this._mapJs&&this._zoom&&this._mapJs.setZoom(this._zoom,{animate:!1});break;case"VECTOR":this._mapGl&&this._zoom&&this._mapGl.setZoom(this._zoom)}return this}setControls(t){return this._controls=t,this._mapGl&&(this._controls?this._controls.forEach(t=>{Array.isArray(t)?this._mapGl.addControl(t[0],t[1]):this._mapGl.addControl(t)}):this._mapGl.addControl(new tH.NavigationControl)),this}setGeoJson(t){var e;return this._geoJsonConfig=t,this._mapGl&&(this._geoJsonConfig?this._loadGeoJSON(this._geoJsonConfig):this._loadGeoJSON(null==(e=this._viewSettings)?void 0:e.geoJson)),this}loadViewSettings(){return t5(this,void 0,void 0,function*(){var t;let e=("RASTER"===this._type?yield w().rest.api.MapResource.getSettingsJs():yield w().rest.api.MapResource.getSettings()).data;if(e.override)return e.override;let n=w().displayRealm||"default";return this._viewSettings=e.options?e.options[n]?e.options[n]:e.options.default:null,this._viewSettings&&(this._mapGl&&(this._mapGl.setMinZoom(this._viewSettings.minZoom),this._mapGl.setMaxZoom(this._viewSettings.maxZoom),this._viewSettings.bounds&&this._mapGl.setMaxBounds(this._viewSettings.bounds),this._geoJsonConfig?yield this._loadGeoJSON(this._geoJsonConfig):yield this._loadGeoJSON(null==(t=this._viewSettings)?void 0:t.geoJson)),this._center?this.setCenter(this._center):this.setCenter(this._viewSettings.center)),e})}build(){return t5(this,void 0,void 0,function*(){var e;if(!this._loaded){if("RASTER"===this._type){let t,e=document.createElement("style");e.id="mapboxJsStyle",e.textContent=t3,this._styleParent.appendChild(e);let n=yield this.loadViewSettings();if(this._viewSettings){if((t={}).zoom=this._viewSettings.zoom?this._viewSettings.zoom+1:void 0,this._useZoomControls&&(t.maxZoom=this._viewSettings.maxZoom?this._viewSettings.maxZoom-1:void 0,t.minZoom=this._viewSettings.minZoom?this._viewSettings.minZoom+1:void 0),t.boxZoom=this._viewSettings.boxZoom,this._viewSettings.bounds&&(t.maxBounds=tW(this._viewSettings.bounds)),this._viewSettings.center){let e=tj(this._viewSettings.center);t.center=e?L.latLng(e.lat,e.lng):void 0}if(this._center){let e=tj(this._center);t.center=e?L.latLng(e.lat,e.lng):void 0}this._zoom&&(t.zoom=this._zoom+1)}if(this._mapJs=L.mapbox.map(this._mapContainer,n,t),this._mapJs.on("click",t=>{this._onMapClick(t.latlng)}),t&&t.maxBounds){let e=this._mapJs.getBoundsZoom(t.maxBounds,!0);(!t.minZoom||t.minZoom<e)&&this._mapJs.setMinZoom(e)}}else{let n=document.createElement("style");n.id="maplibreGlStyle",n.textContent=t4,this._styleParent.appendChild(n),(n=document.createElement("style")).id="maplibreGeoCoderStyles",n.textContent=t7,this._styleParent.appendChild(n);let i=yield Promise.resolve().then(s.t.bind(s,476,23)),r=yield this.loadViewSettings(),o={attributionControl:{compact:!0},container:this._mapContainer,style:r,transformRequest:(e,n)=>{if(t||(t=new URL(e).searchParams.get("access_token")||""),0===e.indexOf("mapbox:")){var i,r,o,a,l,c,s,d,m;let p,u,h,f,g,b,v,_;return i=t,e.indexOf("/styles/")>-1&&-1===e.indexOf("/sprite")?{url:(r=e,o=i,(p=t0(r)).path=`/styles/v1${p.path}`,t1(p,o))}:e.indexOf("/sprites/")>-1?{url:(a=e,l=i,f=(h=(u=t0(a)).path.split("."))[0],g=h[1],b="",f.indexOf("@2x")&&(f=f.split("@2x")[0],b="@2x"),u.path=`/styles/v1${f}/sprite${b}.${g}`,t1(u,l))}:e.indexOf("/fonts/")>-1?{url:(c=e,s=i,(v=t0(c)).path=`/fonts/v1${v.path}`,t1(v,s))}:e.indexOf("/v4/")>-1||"Source"===n?{url:(d=e,m=i,(_=t0(d)).path=`/v4/${_.authority}.json`,_.params.push("secure"),t1(_,m))}:void 0}return{headers:new URL(window.origin).hostname===new URL(e).hostname?{Authorization:w().getAuthorizationHeader()}:{},url:e}}};if(this._viewSettings&&(this._useZoomControls&&(o.maxZoom=this._viewSettings.maxZoom,o.minZoom=this._viewSettings.minZoom),this._viewSettings.bounds&&!this._showBoundaryBox&&(o.maxBounds=this._viewSettings.bounds),o.boxZoom=this._viewSettings.boxZoom,o.zoom=this._viewSettings.zoom,o.center=this._viewSettings.center),this._center=this._center||(this._viewSettings?this._viewSettings.center:void 0),o.center=this._center,this._zoom&&(o.zoom=this._zoom),!tZ())return void console.warn("WebGL is not supported in this environment. The map cannot be initialized.");this._mapGl=new i.Map(o),yield this._styleLoaded(),this._mapGl.on("click",t=>{this._onMapClick(t.lngLat)}),this._mapGl.on("dblclick",t=>{this._onMapClick(t.lngLat,!0)}),this._showGeoCodingControl&&this._viewSettings&&this._viewSettings.geocodeUrl&&(this._geocoder=new(tU())({forwardGeocode:this._forwardGeocode.bind(this),reverseGeocode:this._reverseGeocode},{maplibregl:tV(),showResultsWhileTyping:!0}),this._geocoder._onKeyDown=tX()(t=>{if(27===t.keyCode&&this._geocoder.options.clearAndBlurOnEsc)return this._geocoder._clear(t),this._geocoder._inputEl.blur();var e=this._geocoder._inputEl.value||t.key;if(!e)return this._geocoder.fresh=!0,9!==t.keyCode&&this._geocoder.clear(t),this._geocoder._clearEl.style.display="none";if(!t.metaKey&&-1===[9,27,37,39,38,40].indexOf(t.keyCode)){if(13===t.keyCode)if(this._geocoder.options.showResultsWhileTyping){this._geocoder.options.showResultMarkers&&this._geocoder._fitBoundsForMarkers(),this._geocoder._inputEl.value=this._geocoder._typeahead.query,this._geocoder.lastSelected=null,this._geocoder._typeahead.selected=null;return}else this._geocoder._typeahead.list.selectingListItem||this._geocoder._geocode(e);e.length>=this._geocoder.options.minLength&&this._geocoder.options.showResultsWhileTyping&&this._geocoder._geocode(e)}},300),this._mapGl.addControl(this._geocoder,"top-left"),this._geocoder._inputEl.addEventListener("change",()=>{var t=this._geocoder._typeahead.selected;this._onGeocodeChange(t)})),this._controls?this._controls.forEach(t=>{Array.isArray(t)?this._mapGl.addControl(t[0],t[1]):this._mapGl.addControl(t)}):(this._mapGl.addControl(new tH.NavigationControl),this._mapGl.addControl(new tH.GeolocateControl({positionOptions:{enableHighAccuracy:!0},showAccuracyCircle:!0,showUserLocation:!0}))),this._geoJsonConfig?yield this._loadGeoJSON(this._geoJsonConfig):yield this._loadGeoJSON(null==(e=this._viewSettings)?void 0:e.geoJson),this._initLongPressEvent(),this._mapGl.on("load",()=>t5(this,void 0,void 0,function*(){return yield this.load()}))}this._mapContainer.dispatchEvent(new rD),this._loaded=!0,this.createBoundaryBox()}})}_styleLoaded(){return new Promise(t=>{this._mapGl&&this._mapGl.once("style.load",t)})}load(){return t5(this,void 0,void 0,function*(){var t,e,n,i,r,o;this._mapGl&&this._loaded?(this._mapGl.getSource("mapPoints")&&(this._mapGl.getLayer("unclustered-point")&&this._mapGl.removeLayer("unclustered-point"),this._mapGl.getLayer("clusters")&&this._mapGl.removeLayer("clusters"),this._mapGl.getLayer("cluster-count")&&this._mapGl.removeLayer("cluster-count"),this._mapGl.removeSource("mapPoints")),this._mapGl.addSource("mapPoints",{type:"geojson",cluster:null==(e=null==(t=this._clusterConfig)?void 0:t.cluster)||e,clusterRadius:null!=(i=null==(n=this._clusterConfig)?void 0:n.clusterRadius)?i:180,clusterMaxZoom:null!=(o=null==(r=this._clusterConfig)?void 0:r.clusterMaxZoom)?o:17,data:this._pointsMap,clusterProperties:Object.fromEntries(Object.keys(this._assetTypeColors).map(t=>[t,["+",["case",["==",["get","assetType"],t],1,0]]]))}),this._mapGl.getLayer("unclustered-point")||this._mapGl.addLayer({id:"unclustered-point",type:"circle",source:"mapPoints",filter:["!",["has","point_count"]],paint:{"circle-radius":0}}),this._mapGl.on("data",t=>t5(this,void 0,void 0,function*(){!this._mapGl||"mapPoints"===t.sourceId&&t.isSourceLoaded&&(this._mapGl.off("move",()=>this._updateMarkers()),this._mapGl.off("moveend",()=>this._updateMarkers()),this._mapGl.on("move",tX()(()=>this._updateMarkers())),this._mapGl.on("moveend",()=>this._updateMarkers()),this._updateMarkers())}))):console.warn("MapLibre Map not initialized!")})}unload(){this._mapGl&&(this._mapGl.remove(),this._mapGl=void 0),this._mapJs&&(this._mapJs.remove(),this._mapJs=void 0)}_onMapClick(t,e=!1){this._mapContainer.dispatchEvent(new rP(t,e))}_loadGeoJSON(t){return t5(this,void 0,void 0,function*(){if(this._geoJsonLayers.size>0&&(this._geoJsonLayers.forEach((t,e)=>this._mapGl.removeLayer(e)),this._geoJsonLayers=new Map),this._geoJsonSources.length>0&&(this._geoJsonSources.forEach(t=>this._mapGl.removeSource(t)),this._geoJsonSources=[]),this._showGeoJson&&t)if("FeatureCollection"==t.source.type){let e=this.groupSourcesByGeometryType(t.source);null==e||e.forEach((t,e)=>{let n=this.addGeoJSONSource({type:"geojson",data:{type:"FeatureCollection",features:t}});n&&this.addGeoJSONLayer(e,n.sourceId)})}else if("Feature"==t.source.type){let e=this.addGeoJSONSource(t.source);e&&this.addGeoJSONLayer(e.source.type,e.sourceId)}else console.error("Could not create layer since source type is neither 'FeatureCollection' nor 'Feature'.")})}groupSourcesByGeometryType(t){let e=new Map;return t.features.forEach(t=>{let n=e.get(t.geometry.type);void 0==n&&(n=[]),n.push(t),e.set(t.geometry.type,n)}),e}addGeoJSONSource(t){if(!this._mapGl)return void console.error("mapGl instance not found!");let e=Date.now()+"-"+(this._geoJsonSources.length+1);return this._mapGl.addSource(e,t),this._geoJsonSources.push(e),{source:t,sourceId:e}}addGeoJSONLayer(t,e){if(!this._mapGl)return void console.error("mapGl instance not found!");let n=e+"-"+t;if(void 0==this._geoJsonLayers.get(n)){let i=getComputedStyle(this._mapContainer).getPropertyValue("--or-app-color4");(void 0==i||0==i.length)&&(i=y.DefaultColor4);let r={id:n,source:e};switch(t){case"Point":case"MultiPoint":r.type="circle",r.paint={"circle-radius":12,"circle-color":i},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);break;case"LineString":case"MultiLineString":r.type="line",r.paint={"line-color":i,"line-width":4},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);break;case"Polygon":case"MultiPolygon":{r.type="fill",r.paint={"fill-color":i,"fill-opacity":.3},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);let t=n+"-outline",o={id:t,source:e,type:"line",paint:{"line-color":i,"line-width":2}};this._geoJsonLayers.set(t,o),this._mapGl.addLayer(o);break}case"GeometryCollection":return void console.error("GeometryCollection GeoJSON is not implemented yet!")}}}addMarker(t){t.hasPosition()&&this._updateMarkerElement(t,!0)}_updateMarkers(){if(!this._mapGl)return;let t={},e=this._mapGl.querySourceFeatures("mapPoints");for(let n of e){if(!n.properties.id)continue;let e=n.properties.id,i=n.geometry.coordinates,r=this._cachedMarkers[e];if(!r){let t=document.createElement("div");r=this._cachedMarkers[e]=new(tV()).Marker({element:t}).setLngLat(i)}t[e]=r,this._markersOnScreen[e]||(r.addTo(this._mapGl),this._assetsOnScreen[e]=JSON.parse(n.properties.asset))}for(let n of e){if(!n.properties.cluster)continue;let e=n.properties.cluster_id,[i,r]=n.geometry.coordinates,o=this._cachedMarkers[e];if(!o){let t=Object.entries(n.properties).filter(([t])=>this._assetTypeColors.hasOwnProperty(t)).map(([t,e])=>[t,this._assetTypeColors[t],e]);o=this._cachedMarkers[e]=new(tV()).Marker({element:new t2(t,e,i,r,this._mapGl)}).setLngLat([i,r])}t[e]=o,this._markersOnScreen[e]||o.addTo(this._mapGl)}for(let e in this._markersOnScreen){let n=t[e];(!n||n._element instanceof t2&&!n._element.hasTypes(Object.keys(this._assetTypeColors)))&&(this._markersOnScreen[e].remove(),delete this._assetsOnScreen[e])}this._markersOnScreen=t,this._mapContainer.dispatchEvent(new rH(Object.values(this._assetsOnScreen)))}addAssetMarker(t,e,n,i,r,o){var a;this._assetTypeColors[n]=null==(a=tJ(n))?void 0:a.color,this._pointsMap.features.push({type:"Feature",properties:{name:e,id:t,assetType:n,asset:o},geometry:{type:"Point",coordinates:[i,r]}})}cleanUpAssetMarkers(){this._assetTypeColors={},this._pointsMap={type:"FeatureCollection",features:[]}}removeMarker(t){this._removeMarkerRadius(t),this._updateMarkerElement(t,!1)}onMarkerChanged(t,e){if(this._loaded)switch(e){case"lat":case"lng":case"radius":t.hasPosition()?t._actualMarkerElement?this._updateMarkerPosition(t):this._updateMarkerElement(t,!0):t._actualMarkerElement&&this._updateMarkerElement(t,!1)}}_updateMarkerPosition(t){switch(this._type){case"RASTER":let e=this._markersJs.get(t);e&&e.setLatLng([t.lat,t.lng]);break;case"VECTOR":let n=this._markersGl.get(t);n&&n.setLngLat([t.lng,t.lat])}this._createMarkerRadius(t)}_updateMarkerElement(t,e){switch(this._type){case"RASTER":let n=this._markersJs.get(t);if(n&&(this._removeMarkerClickHandler(t,t.markerContainer),t._actualMarkerElement=void 0,n.removeFrom(this._mapJs),this._markersJs.delete(t)),e){let e=t._createMarkerElement();if(e){let i=L.divIcon({html:e.outerHTML,className:"or-marker-raster"});(n=L.marker([t.lat,t.lng],{icon:i,clickable:t.interactive})).addTo(this._mapJs),t._actualMarkerElement=n.getElement()?n.getElement().firstElementChild:void 0,t.interactive&&this._addMarkerClickHandler(t,t.markerContainer),this._markersJs.set(t,n)}t.radius&&this._createMarkerRadius(t)}break;case"VECTOR":let i=this._markersGl.get(t);if(i&&(t._actualMarkerElement=void 0,this._removeMarkerClickHandler(t,i.getElement()),i.remove(),this._markersGl.delete(t)),e){let e=t._createMarkerElement();e&&(i=new tH.Marker({element:e,anchor:"top-left"}).setLngLat([t.lng,t.lat]).addTo(this._mapGl),this._markersGl.set(t,i),t._actualMarkerElement=i.getElement(),t.interactive&&this._addMarkerClickHandler(t,i.getElement())),t.radius&&this._createMarkerRadius(t)}}}_removeMarkerRadius(t){this._mapGl&&this._loaded&&t.radius&&t.lat&&t.lng&&this._mapGl.getSource("circleData")&&(this._mapGl.removeLayer("marker-radius-circle"),this._mapGl.removeSource("circleData"))}_createMarkerRadius(t){this._mapGl&&this._loaded&&t.radius&&t.lat&&t.lng&&(this._removeMarkerRadius(t),this._mapGl.addSource("circleData",{type:"geojson",data:{type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{title:"You Found Me"}}]}}),this._mapGl.addLayer({id:"marker-radius-circle",type:"circle",source:"circleData",paint:{"circle-radius":["interpolate",["linear"],["zoom"],0,0,20,t.radius/.075/Math.cos(t.lat*Math.PI/180)],"circle-color":"red","circle-opacity":.3}}))}createBoundaryBox(t=[]){var e,n;if(this._mapGl&&this._loaded&&this._showBoundaryBox&&(null==(e=this._viewSettings)?void 0:e.bounds)){this._mapGl.getSource("bounds")&&(this._mapGl.removeLayer("bounds"),this._mapGl.removeSource("bounds")),4!==t.length&&(t=null==(n=this._viewSettings)?void 0:n.bounds.toString().split(","));var i=[[[t[0],t[3]],[t[2],t[3]],[t[2],t[1]],[t[0],t[1]],[t[0],t[3]]]];this._mapGl.fitBounds([parseFloat(t[0])+.01,parseFloat(t[1])-.01,parseFloat(t[2])-.01,parseFloat(t[3])+.01]),this._mapGl.addSource("bounds",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:i}}}),this._mapGl.addLayer({id:"bounds",type:"fill",source:"bounds",paint:{"fill-color":"#FF0000","fill-opacity":.4}})}}_addMarkerClickHandler(t,e){if(e){let n=e=>{e.stopPropagation(),t._onClick(e)};this._clickHandlers.set(t,n),e.addEventListener("click",n)}}_removeMarkerClickHandler(t,e){let n=this._clickHandlers.get(t);n&&e&&(e.removeEventListener("click",n),this._clickHandlers.delete(t))}_forwardGeocode(t){return t5(this,void 0,void 0,function*(){let e=[];try{let n=this._viewSettings.geocodeUrl+"/search?q="+t.query+"&format=geojson&polygon_geojson=1&addressdetails=1",i=yield fetch(n);for(let t of(yield i.json()).features){let n=[t.bbox[0]+(t.bbox[2]-t.bbox[0])/2,t.bbox[1]+(t.bbox[3]-t.bbox[1])/2],i={type:"Feature",geometry:{type:"Point",coordinates:n},place_name:t.properties.display_name,properties:t.properties,text:t.properties.display_name,place_type:["place"],center:n};e.push(i)}}catch(t){console.error(`Failed to forwardGeocode with error: ${t}`)}return{features:e}})}_reverseGeocode(t){return t5(this,void 0,void 0,function*(){let e=[];try{let n=this._viewSettings.geocodeUrl+"/reverse?lat="+t.lat+"&lon="+t.lon+"&format=geojson&polygon_geojson=1&addressdetails=1",i=yield fetch(n);for(let t of(yield i.json()).features){let n=[t.bbox[0]+(t.bbox[2]-t.bbox[0])/2,t.bbox[1]+(t.bbox[3]-t.bbox[1])/2],i={type:"Feature",geometry:{type:"Point",coordinates:n},place_name:t.properties.display_name,properties:t.properties,text:t.properties.display_name,place_type:["place"],center:n};e.push(i)}}catch(t){console.error(`Failed to reverseGeocode with error: ${t}`)}return{features:e}})}_initLongPressEvent(){if(this._mapGl){let t,e,n=()=>{t&&clearTimeout(t),t=null};this._mapGl.on("touchstart",n=>{n.originalEvent.touches.length>1||(e=n.lngLat,t=setTimeout(()=>{this._onLongPress(e)},500))}),this._mapGl.on("mousedown",n=>{t||(e=n.lngLat,t=setTimeout(()=>{this._onLongPress(e),t=null},500))}),this._mapGl.on("dragstart",n),this._mapGl.on("mouseup",n),this._mapGl.on("touchend",n),this._mapGl.on("touchcancel",n),this._mapGl.on("touchmove",n),this._mapGl.on("moveend",n),this._mapGl.on("gesturestart",n),this._mapGl.on("gesturechange",n),this._mapGl.on("gestureend",n)}}_onLongPress(t){this._mapContainer.dispatchEvent(new rF(t))}_onGeocodeChange(t){this._mapContainer.dispatchEvent(new rB(t))}}let t8="--internal-or-map-marker-color",t9="--internal-or-map-marker-active-color",et=S`
|
|
22
|
+
/>`}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this.onClick)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this.onClick)}onClick(){var t,e,n,i;return t=this,e=void 0,n=void 0,i=function*(){if(this.lng&&this.lat){let t=yield this._map.getSource("mapPoints").getClusterExpansionZoom(this._clusterId);this._map.easeTo({center:[this.lng,this.lat],zoom:t+.99,essential:!0})}},new(n||(n=Promise))(function(r,o){function a(t){try{c(i.next(t))}catch(t){o(t)}}function l(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):((e=t.value)instanceof n?e:new n(function(t){t(e)})).then(a,l)}c((i=i.apply(t,e||[])).next())})}};t2=function(t,e,n,i){var r,o=arguments.length,a=o<3?e:null===i?i=Object.getOwnPropertyDescriptor(e,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,i);else for(var l=t.length-1;l>=0;l--)(r=t[l])&&(a=(o<3?r(a):o>3?r(e,n,a):r(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}([tM("or-cluster-marker")],t2);var t5=function(t,e,n,i){return new(n||(n=Promise))(function(r,o){function a(t){try{c(i.next(t))}catch(t){o(t)}}function l(t){try{c(i.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?r(t.value):((e=t.value)instanceof n?e:new n(function(t){t(e)})).then(a,l)}c((i=i.apply(t,e||[])).next())})};let t3=s(977),t4=s(126),t7=s(561);class t6{constructor(t,e,n,i=!1,r=!1,o=!0,a=!0,l){this._loaded=!1,this._markersJs=new Map,this._markersGl=new Map,this._geoJsonSources=[],this._geoJsonLayers=new Map,this._showGeoCodingControl=!1,this._showBoundaryBox=!1,this._useZoomControls=!0,this._showGeoJson=!0,this._clickHandlers=new Map,this._pointsMap={type:"FeatureCollection",features:[]},this._assetTypeColors={},this._cachedMarkers={},this._markersOnScreen={},this._assetsOnScreen={},this._type=t,this._styleParent=e,this._mapContainer=n,this._showGeoCodingControl=i,this._showBoundaryBox=r,this._useZoomControls=o,this._showGeoJson=a,this._clusterConfig=l}setCenter(t){switch(this._center=tj(t),this._type){case"RASTER":if(this._mapJs){let t=tj(this._center)||(this._viewSettings?tj(this._viewSettings.center):void 0);t&&this._mapJs.setView(t,void 0,{pan:{animate:!1},zoom:{animate:!1}})}break;case"VECTOR":this._mapGl&&this._center&&this._mapGl.setCenter(this._center)}return this}flyTo(t,e){switch(this._type){case"RASTER":this._mapJs;break;case"VECTOR":t||(t=this._center?this._center:this._viewSettings?this._viewSettings.center:void 0),e||(e=this._zoom?this._zoom:this._viewSettings&&this._viewSettings.zoom?this._viewSettings.zoom:void 0),this._mapGl?t&&this._mapGl.flyTo({center:t,zoom:e}):(this._center=t,this._zoom=e)}return this}resize(){switch(this._type){case"RASTER":this._mapJs;break;case"VECTOR":this._mapGl&&this._mapGl.resize()}return this}setZoom(t){switch(this._zoom=t,this._type){case"RASTER":this._mapJs&&this._zoom&&this._mapJs.setZoom(this._zoom,{animate:!1});break;case"VECTOR":this._mapGl&&this._zoom&&this._mapGl.setZoom(this._zoom)}return this}setControls(t){return this._controls=t,this._mapGl&&(this._controls?this._controls.forEach(t=>{Array.isArray(t)?this._mapGl.addControl(t[0],t[1]):this._mapGl.addControl(t)}):this._mapGl.addControl(new tH.NavigationControl)),this}setGeoJson(t){var e;return this._geoJsonConfig=t,this._mapGl&&(this._geoJsonConfig?this._loadGeoJSON(this._geoJsonConfig):this._loadGeoJSON(null==(e=this._viewSettings)?void 0:e.geoJson)),this}loadViewSettings(){return t5(this,void 0,void 0,function*(){var t;let e=("RASTER"===this._type?yield w().rest.api.MapResource.getSettingsJs():yield w().rest.api.MapResource.getSettings()).data;if(e.override)return e.override;let n=w().displayRealm||"default";return this._viewSettings=e.options?e.options[n]?e.options[n]:e.options.default:null,this._viewSettings&&(this._mapGl&&(this._mapGl.setMinZoom(this._viewSettings.minZoom),this._mapGl.setMaxZoom(this._viewSettings.maxZoom),this._viewSettings.bounds&&this._mapGl.setMaxBounds(this._viewSettings.bounds),this._geoJsonConfig?yield this._loadGeoJSON(this._geoJsonConfig):yield this._loadGeoJSON(null==(t=this._viewSettings)?void 0:t.geoJson)),this._center?this.setCenter(this._center):this.setCenter(this._viewSettings.center)),e})}build(){return t5(this,void 0,void 0,function*(){var e;if(!this._loaded){if("RASTER"===this._type){let t,e=document.createElement("style");e.id="mapboxJsStyle",e.textContent=t3,this._styleParent.appendChild(e);let n=yield this.loadViewSettings();if(this._viewSettings){if((t={}).zoom=this._viewSettings.zoom?this._viewSettings.zoom+1:void 0,this._useZoomControls&&(t.maxZoom=this._viewSettings.maxZoom?this._viewSettings.maxZoom-1:void 0,t.minZoom=this._viewSettings.minZoom?this._viewSettings.minZoom+1:void 0),t.boxZoom=this._viewSettings.boxZoom,this._viewSettings.bounds&&(t.maxBounds=tW(this._viewSettings.bounds)),this._viewSettings.center){let e=tj(this._viewSettings.center);t.center=e?L.latLng(e.lat,e.lng):void 0}if(this._center){let e=tj(this._center);t.center=e?L.latLng(e.lat,e.lng):void 0}this._zoom&&(t.zoom=this._zoom+1)}if(this._mapJs=L.mapbox.map(this._mapContainer,n,t),this._mapJs.on("click",t=>{this._onMapClick(t.latlng)}),t&&t.maxBounds){let e=this._mapJs.getBoundsZoom(t.maxBounds,!0);(!t.minZoom||t.minZoom<e)&&this._mapJs.setMinZoom(e)}}else{let n=document.createElement("style");n.id="maplibreGlStyle",n.textContent=t4,this._styleParent.appendChild(n),(n=document.createElement("style")).id="maplibreGeoCoderStyles",n.textContent=t7,this._styleParent.appendChild(n);let i=yield Promise.resolve().then(s.t.bind(s,476,23)),r=yield this.loadViewSettings(),o={attributionControl:{compact:!0},container:this._mapContainer,style:r,transformRequest:(e,n)=>{if(t||(t=new URL(e).searchParams.get("access_token")||""),0===e.indexOf("mapbox:")){var i,r,o,a,l,c,s,d,m;let p,u,h,f,g,b,v,_;return i=t,e.indexOf("/styles/")>-1&&-1===e.indexOf("/sprite")?{url:(r=e,o=i,(p=t0(r)).path=`/styles/v1${p.path}`,t1(p,o))}:e.indexOf("/sprites/")>-1?{url:(a=e,l=i,f=(h=(u=t0(a)).path.split("."))[0],g=h[1],b="",f.indexOf("@2x")&&(f=f.split("@2x")[0],b="@2x"),u.path=`/styles/v1${f}/sprite${b}.${g}`,t1(u,l))}:e.indexOf("/fonts/")>-1?{url:(c=e,s=i,(v=t0(c)).path=`/fonts/v1${v.path}`,t1(v,s))}:e.indexOf("/v4/")>-1||"Source"===n?{url:(d=e,m=i,(_=t0(d)).path=`/v4/${_.authority}.json`,_.params.push("secure"),t1(_,m))}:void 0}return{headers:new URL(window.origin).hostname===new URL(e).hostname?{Authorization:w().getAuthorizationHeader()}:{},url:e}}};if(this._viewSettings&&(this._useZoomControls&&(o.maxZoom=this._viewSettings.maxZoom,o.minZoom=this._viewSettings.minZoom),this._viewSettings.bounds&&!this._showBoundaryBox&&(o.maxBounds=this._viewSettings.bounds),o.boxZoom=this._viewSettings.boxZoom,o.zoom=this._viewSettings.zoom,o.center=this._viewSettings.center),this._center=this._center||(this._viewSettings?this._viewSettings.center:void 0),o.center=this._center,this._zoom&&(o.zoom=this._zoom),!tZ())return void console.warn("WebGL is not supported in this environment. The map cannot be initialized.");this._mapGl=new i.Map(o),yield this._styleLoaded(),this._mapGl.on("click",t=>{this._onMapClick(t.lngLat)}),this._mapGl.on("dblclick",t=>{this._onMapClick(t.lngLat,!0)}),this._showGeoCodingControl&&this._viewSettings&&this._viewSettings.geocodeUrl&&(this._geocoder=new(tU())({forwardGeocode:this._forwardGeocode.bind(this),reverseGeocode:this._reverseGeocode},{maplibregl:tV(),showResultsWhileTyping:!0}),this._geocoder._onKeyDown=tX()(t=>{if(27===t.keyCode&&this._geocoder.options.clearAndBlurOnEsc)return this._geocoder._clear(t),this._geocoder._inputEl.blur();var e=this._geocoder._inputEl.value||t.key;if(!e)return this._geocoder.fresh=!0,9!==t.keyCode&&this._geocoder.clear(t),this._geocoder._clearEl.style.display="none";if(!t.metaKey&&-1===[9,27,37,39,38,40].indexOf(t.keyCode)){if(13===t.keyCode)if(this._geocoder.options.showResultsWhileTyping){this._geocoder.options.showResultMarkers&&this._geocoder._fitBoundsForMarkers(),this._geocoder._inputEl.value=this._geocoder._typeahead.query,this._geocoder.lastSelected=null,this._geocoder._typeahead.selected=null;return}else this._geocoder._typeahead.list.selectingListItem||this._geocoder._geocode(e);e.length>=this._geocoder.options.minLength&&this._geocoder.options.showResultsWhileTyping&&this._geocoder._geocode(e)}},300),this._mapGl.addControl(this._geocoder,"top-left"),this._geocoder._inputEl.addEventListener("change",()=>{var t=this._geocoder._typeahead.selected;this._onGeocodeChange(t)})),this._controls?this._controls.forEach(t=>{Array.isArray(t)?this._mapGl.addControl(t[0],t[1]):this._mapGl.addControl(t)}):(this._mapGl.addControl(new tH.NavigationControl),this._mapGl.addControl(new tH.GeolocateControl({positionOptions:{enableHighAccuracy:!0},showAccuracyCircle:!0,showUserLocation:!0}))),this._geoJsonConfig?yield this._loadGeoJSON(this._geoJsonConfig):yield this._loadGeoJSON(null==(e=this._viewSettings)?void 0:e.geoJson),this._initLongPressEvent(),this._mapGl.on("load",()=>t5(this,void 0,void 0,function*(){return yield this.load()}))}this._mapContainer.dispatchEvent(new rD),this._loaded=!0,this.createBoundaryBox()}})}_styleLoaded(){return new Promise(t=>{this._mapGl&&this._mapGl.once("style.load",t)})}load(){return t5(this,void 0,void 0,function*(){var t,e,n,i,r,o;this._mapGl&&this._loaded?(this._mapGl.getSource("mapPoints")&&(this._mapGl.getLayer("unclustered-point")&&this._mapGl.removeLayer("unclustered-point"),this._mapGl.getLayer("clusters")&&this._mapGl.removeLayer("clusters"),this._mapGl.getLayer("cluster-count")&&this._mapGl.removeLayer("cluster-count"),this._mapGl.removeSource("mapPoints")),this._mapGl.addSource("mapPoints",{type:"geojson",cluster:null==(e=null==(t=this._clusterConfig)?void 0:t.cluster)||e,clusterRadius:null!=(i=null==(n=this._clusterConfig)?void 0:n.clusterRadius)?i:180,clusterMaxZoom:null!=(o=null==(r=this._clusterConfig)?void 0:r.clusterMaxZoom)?o:17,data:this._pointsMap,clusterProperties:Object.fromEntries(Object.keys(this._assetTypeColors).map(t=>[t,["+",["case",["==",["get","assetType"],t],1,0]]]))}),this._mapGl.getLayer("unclustered-point")||this._mapGl.addLayer({id:"unclustered-point",type:"circle",source:"mapPoints",filter:["!",["has","point_count"]],paint:{"circle-radius":0}}),this._mapGl.on("data",t=>t5(this,void 0,void 0,function*(){!this._mapGl||"mapPoints"===t.sourceId&&t.isSourceLoaded&&(this._mapGl.off("move",()=>this._updateMarkers()),this._mapGl.off("moveend",()=>this._updateMarkers()),this._mapGl.on("move",tX()(()=>this._updateMarkers())),this._mapGl.on("moveend",()=>this._updateMarkers()),this._updateMarkers())}))):console.warn("MapLibre Map not initialized!")})}unload(){this._mapGl&&(this._mapGl.remove(),this._mapGl=void 0),this._mapJs&&(this._mapJs.remove(),this._mapJs=void 0)}_onMapClick(t,e=!1){this._mapContainer.dispatchEvent(new rP(t,e))}_loadGeoJSON(t){return t5(this,void 0,void 0,function*(){if(this._geoJsonLayers.size>0&&(this._geoJsonLayers.forEach((t,e)=>this._mapGl.removeLayer(e)),this._geoJsonLayers=new Map),this._geoJsonSources.length>0&&(this._geoJsonSources.forEach(t=>this._mapGl.removeSource(t)),this._geoJsonSources=[]),this._showGeoJson&&t)if("FeatureCollection"==t.source.type){let e=this.groupSourcesByGeometryType(t.source);null==e||e.forEach((t,e)=>{let n=this.addGeoJSONSource({type:"geojson",data:{type:"FeatureCollection",features:t}});n&&this.addGeoJSONLayer(e,n.sourceId)})}else if("Feature"==t.source.type){let e=this.addGeoJSONSource(t.source);e&&this.addGeoJSONLayer(e.source.type,e.sourceId)}else console.error("Could not create layer since source type is neither 'FeatureCollection' nor 'Feature'.")})}groupSourcesByGeometryType(t){let e=new Map;return t.features.forEach(t=>{let n=e.get(t.geometry.type);void 0==n&&(n=[]),n.push(t),e.set(t.geometry.type,n)}),e}addGeoJSONSource(t){if(!this._mapGl)return void console.error("mapGl instance not found!");let e=Date.now()+"-"+(this._geoJsonSources.length+1);return this._mapGl.addSource(e,t),this._geoJsonSources.push(e),{source:t,sourceId:e}}addGeoJSONLayer(t,e){if(!this._mapGl)return void console.error("mapGl instance not found!");let n=e+"-"+t;if(void 0==this._geoJsonLayers.get(n)){let i=getComputedStyle(this._mapContainer).getPropertyValue("--or-app-color4");(void 0==i||0==i.length)&&(i=y.DefaultColor4);let r={id:n,source:e};switch(t){case"Point":case"MultiPoint":r.type="circle",r.paint={"circle-radius":12,"circle-color":i},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);break;case"LineString":case"MultiLineString":r.type="line",r.paint={"line-color":i,"line-width":4},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);break;case"Polygon":case"MultiPolygon":{r.type="fill",r.paint={"fill-color":i,"fill-opacity":.3},this._geoJsonLayers.set(n,r),this._mapGl.addLayer(r);let t=n+"-outline",o={id:t,source:e,type:"line",paint:{"line-color":i,"line-width":2}};this._geoJsonLayers.set(t,o),this._mapGl.addLayer(o);break}case"GeometryCollection":return void console.error("GeometryCollection GeoJSON is not implemented yet!")}}}addMarker(t){t.hasPosition()&&this._updateMarkerElement(t,!0)}_updateMarkers(){if(!this._mapGl)return;let t={},e=this._mapGl.querySourceFeatures("mapPoints");for(let n of e){if(!n.properties.id)continue;let e=n.properties.id,i=n.geometry.coordinates,r=this._cachedMarkers[e];if(!r){let t=document.createElement("div");r=this._cachedMarkers[e]=new(tV()).Marker({element:t}).setLngLat(i)}t[e]=r,this._markersOnScreen[e]||(r.addTo(this._mapGl),this._assetsOnScreen[e]=JSON.parse(n.properties.asset))}for(let n of e){if(!n.properties.cluster)continue;let e=n.properties.cluster_id,[i,r]=n.geometry.coordinates,o=this._cachedMarkers[e];if(!o){let t=Object.entries(n.properties).filter(([t])=>this._assetTypeColors.hasOwnProperty(t)).map(([t,e])=>[t,this._assetTypeColors[t],e]);o=this._cachedMarkers[e]=new(tV()).Marker({element:new t2(t,e,i,r,this._mapGl)}).setLngLat([i,r])}t[e]=o,this._markersOnScreen[e]||o.addTo(this._mapGl)}for(let e in this._markersOnScreen){let n=t[e];(!n||n._element instanceof t2&&!n._element.hasTypes(Object.keys(this._assetTypeColors)))&&(this._markersOnScreen[e].remove(),delete this._assetsOnScreen[e])}this._markersOnScreen=t,this._mapContainer.dispatchEvent(new rH(Object.values(this._assetsOnScreen)))}addAssetMarker(t,e,n,i,r,o){var a;this._assetTypeColors[n]=null==(a=tJ(n))?void 0:a.color,this._pointsMap.features.push({type:"Feature",properties:{name:e,id:t,assetType:n,asset:o},geometry:{type:"Point",coordinates:[i,r]}})}cleanUpAssetMarkers(){this._assetTypeColors={},this._pointsMap={type:"FeatureCollection",features:[]}}removeMarker(t){this._removeMarkerRadius(t),this._updateMarkerElement(t,!1)}onMarkerChanged(t,e){if(this._loaded)switch(e){case"lat":case"lng":case"radius":t.hasPosition()?t._actualMarkerElement?this._updateMarkerPosition(t):this._updateMarkerElement(t,!0):t._actualMarkerElement&&this._updateMarkerElement(t,!1)}}_updateMarkerPosition(t){switch(this._type){case"RASTER":let e=this._markersJs.get(t);e&&e.setLatLng([t.lat,t.lng]);break;case"VECTOR":let n=this._markersGl.get(t);n&&n.setLngLat([t.lng,t.lat])}this._createMarkerRadius(t)}_updateMarkerElement(t,e){switch(this._type){case"RASTER":let n=this._markersJs.get(t);if(n&&(this._removeMarkerClickHandler(t,t.markerContainer),t._actualMarkerElement=void 0,n.removeFrom(this._mapJs),this._markersJs.delete(t)),e){let e=t._createMarkerElement();if(e){let i=L.divIcon({html:e.outerHTML,className:"or-marker-raster"});(n=L.marker([t.lat,t.lng],{icon:i,clickable:t.interactive})).addTo(this._mapJs),t._actualMarkerElement=n.getElement()?n.getElement().firstElementChild:void 0,t.interactive&&this._addMarkerClickHandler(t,t.markerContainer),this._markersJs.set(t,n)}t.radius&&this._createMarkerRadius(t)}break;case"VECTOR":let i=this._markersGl.get(t);if(i&&(t._actualMarkerElement=void 0,this._removeMarkerClickHandler(t,i.getElement()),i.remove(),this._markersGl.delete(t)),e){let e=t._createMarkerElement();e&&(i=new tH.Marker({element:e,anchor:"top-left"}).setLngLat([t.lng,t.lat]).addTo(this._mapGl),this._markersGl.set(t,i),t._actualMarkerElement=i.getElement(),t.interactive&&this._addMarkerClickHandler(t,i.getElement())),t.radius&&this._createMarkerRadius(t)}}}_removeMarkerRadius(t){this._mapGl&&this._loaded&&t.radius&&t.lat&&t.lng&&this._mapGl.getSource("circleData")&&(this._mapGl.removeLayer("marker-radius-circle"),this._mapGl.removeSource("circleData"))}_createMarkerRadius(t){this._mapGl&&this._loaded&&t.radius&&t.lat&&t.lng&&(this._removeMarkerRadius(t),this._mapGl.addSource("circleData",{type:"geojson",data:{type:"FeatureCollection",features:[{type:"Feature",geometry:{type:"Point",coordinates:[t.lng,t.lat]},properties:{}}]}}),this._mapGl.addLayer({id:"marker-radius-circle",type:"circle",source:"circleData",paint:{"circle-radius":["interpolate",["exponential",2],["zoom"],0,0,20,t.radius/.075/Math.cos(t.lat*Math.PI/180)],"circle-color":"red","circle-opacity":.3,"circle-pitch-alignment":"map"}}))}createBoundaryBox(t=[]){var e,n;if(this._mapGl&&this._loaded&&this._showBoundaryBox&&(null==(e=this._viewSettings)?void 0:e.bounds)){this._mapGl.getSource("bounds")&&(this._mapGl.removeLayer("bounds"),this._mapGl.removeSource("bounds")),4!==t.length&&(t=null==(n=this._viewSettings)?void 0:n.bounds.toString().split(","));var i=[[[t[0],t[3]],[t[2],t[3]],[t[2],t[1]],[t[0],t[1]],[t[0],t[3]]]];this._mapGl.fitBounds([parseFloat(t[0])+.01,parseFloat(t[1])-.01,parseFloat(t[2])-.01,parseFloat(t[3])+.01]),this._mapGl.addSource("bounds",{type:"geojson",data:{type:"Feature",properties:{},geometry:{type:"Polygon",coordinates:i}}}),this._mapGl.addLayer({id:"bounds",type:"fill",source:"bounds",paint:{"fill-color":"#FF0000","fill-opacity":.4}})}}_addMarkerClickHandler(t,e){if(e){let n=e=>{e.stopPropagation(),t._onClick(e)};this._clickHandlers.set(t,n),e.addEventListener("click",n)}}_removeMarkerClickHandler(t,e){let n=this._clickHandlers.get(t);n&&e&&(e.removeEventListener("click",n),this._clickHandlers.delete(t))}_forwardGeocode(t){return t5(this,void 0,void 0,function*(){let e=[];try{let n=this._viewSettings.geocodeUrl+"/search?q="+t.query+"&format=geojson&polygon_geojson=1&addressdetails=1",i=yield fetch(n);for(let t of(yield i.json()).features){let n=[t.bbox[0]+(t.bbox[2]-t.bbox[0])/2,t.bbox[1]+(t.bbox[3]-t.bbox[1])/2],i={type:"Feature",geometry:{type:"Point",coordinates:n},place_name:t.properties.display_name,properties:t.properties,text:t.properties.display_name,place_type:["place"],center:n};e.push(i)}}catch(t){console.error(`Failed to forwardGeocode with error: ${t}`)}return{features:e}})}_reverseGeocode(t){return t5(this,void 0,void 0,function*(){let e=[];try{let n=this._viewSettings.geocodeUrl+"/reverse?lat="+t.lat+"&lon="+t.lon+"&format=geojson&polygon_geojson=1&addressdetails=1",i=yield fetch(n);for(let t of(yield i.json()).features){let n=[t.bbox[0]+(t.bbox[2]-t.bbox[0])/2,t.bbox[1]+(t.bbox[3]-t.bbox[1])/2],i={type:"Feature",geometry:{type:"Point",coordinates:n},place_name:t.properties.display_name,properties:t.properties,text:t.properties.display_name,place_type:["place"],center:n};e.push(i)}}catch(t){console.error(`Failed to reverseGeocode with error: ${t}`)}return{features:e}})}_initLongPressEvent(){if(this._mapGl){let t,e,n=()=>{t&&clearTimeout(t),t=null};this._mapGl.on("touchstart",n=>{n.originalEvent.touches.length>1||(e=n.lngLat,t=setTimeout(()=>{this._onLongPress(e)},500))}),this._mapGl.on("mousedown",n=>{t||(e=n.lngLat,t=setTimeout(()=>{this._onLongPress(e),t=null},500))}),this._mapGl.on("dragstart",n),this._mapGl.on("mouseup",n),this._mapGl.on("touchend",n),this._mapGl.on("touchcancel",n),this._mapGl.on("touchmove",n),this._mapGl.on("moveend",n),this._mapGl.on("gesturestart",n),this._mapGl.on("gesturechange",n),this._mapGl.on("gestureend",n)}}_onLongPress(t){this._mapContainer.dispatchEvent(new rF(t))}_onGeocodeChange(t){this._mapContainer.dispatchEvent(new rB(t))}}let t8="--internal-or-map-marker-color",t9="--internal-or-map-marker-active-color",et=S`
|
|
23
23
|
:host {
|
|
24
24
|
--internal-or-map-width: var(--or-map-width, 100%);
|
|
25
25
|
--internal-or-map-min-height: var(--or-map-min-height, 300px);
|