@nextgis/ol-map-adapter
Advanced tools
Comparing version 1.11.10 to 1.12.0
@@ -1,2 +0,16 @@ | ||
import{EventEmitter as t}from"events";import e from"ol/Map";import o from"ol/View";import{transform as i,transformExtent as s,fromLonLat as n}from"ol/proj";import r from"ol/layer/Tile";import a from"ol/source/TileWMS";import c from"ol/format/GeoJSON";import l,{ATTRIBUTION as p}from"ol/source/OSM";import h from"ol/source/XYZ";import u from"ol/layer/Image";import m from"ol/renderer/canvas/ImageLayer";import d from"ol/source/ImageWMS";import f from"ol/source/WMSServerType";import y from"ol/Overlay";import g from"ol/layer/Vector";import _ from"ol/source/Vector";import{create as P}from"@nextgis/dom";import{getCoordinates as v,defined as C}from"@nextgis/utils";import w from"polylabel";import{getCenter as E}from"ol/extent";import x from"ol/style/Circle";import{asArray as O}from"ol/color";import{Style as L,Text as b,Fill as F,Stroke as j}from"ol/style";import S from"ol/style/IconAnchorUnits";import A from"ol/style/Icon";import{isPaintCallback as V,isPaint as M}from"@nextgis/paint";import k from"ol/control/Zoom";import I from"ol/control/Attribution";import Z from"ol/control/Control";import R from"@nextgis/control-container";function T(t,e){const o={minZoom:e.minZoom,maxZoom:e.maxZoom};return e.maxScale&&(o.minResolution=B(t,e.maxScale)),e.minScale&&(o.maxResolution=B(t,e.minScale)),o}function B(t,e){if(e)return function(t,e){return t/(39.37*e*90.71446714322)}(e,t.getView().getProjection().getMetersPerUnit()||1)}function U(t){return(new c).writeFeatureObject(t,{dataProjection:"EPSG:4326",featureProjection:"EPSG:3857"})}function D(t){const e=decodeURIComponent,o=t.split("&"),i={};let s,n;for(let r,a=0,c=o.length;a<c;++a)if(r=o[a],r.length){const t=r.indexOf("=");t<0?(s=e(r),n=""):(s=e(r.slice(0,t)),n=e(r.slice(t+1))),"string"==typeof i[s]&&(i[s]=[i[s]]),Array.isArray(i[s])?i[s].push(n):i[s]=n}return i}function z(t,e){const o=[];let i;for(i in t){const s=e?e+"["+i+"]":i,n=t[i];o.push(null!==n&&"object"==typeof n?z(n,s):encodeURIComponent(s)+"="+encodeURIComponent(n))}return o.join("&")}function G(t,e,o){const i=new XMLHttpRequest;i.open("GET",e),i.responseType="arraybuffer";for(const s in o)i.setRequestHeader(s,o[s]);i.onload=function(){const e=new Uint8Array(this.response),o=new Blob([e],{type:"image/png"}),i=(window.URL||window.webkitURL).createObjectURL(o);t.getImage().src=i},i.send()}class H{constructor(t,e){this.map=t,this.options=e}setOpacity(t){this.options.opacity=Number(t),this.layer&&this.layer.setOpacity&&this.layer.setOpacity(this.options.opacity)}}function N(t,e="EPSG:3857",o="EPSG:4326"){const[s,n]=i(t.coordinate,e,o);return{latLng:{lat:n,lng:s},lngLat:[s,n],pixel:{left:t.pixel[0],top:t.pixel[1]},source:t}}function W(t){const e=function({feature:t,dataProjection:e,featureProjection:o}){const i=(new c).readFeatures({type:"FeatureCollection",features:Array.isArray(t)?t:[t]},{dataProjection:e,featureProjection:o}),s=new _;return s.addFeatures(i),s}(t),o=e.getExtent(),i=s(o,t.featureProjection,t.dataProjection);return e.dispose(),i}function X(t){return{getBounds:()=>W(t),getCenter:()=>function(t){const e=W(t);return E(e)}(t)}}const Y={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon",Circle:"point"},q={polygon:"path",line:"path",point:"circle"};function J(t,e){const o=O(t).slice();return o[3]=void 0!==e?e:1,o}function K(t,e={}){if(V(e)){return K(t,e(U(t)))}if(M(e)){const o=t.getGeometry(),i=o&&o.getType()||"Point",s={};if(!e.type){const t=Y[i],o="polygon"===t||"line"===t?"path":"html"in e||"className"in e?"icon":q[t];o&&(e.type=o)}if("path"===e.type||"circle"===e.type){const{radius:t,fill:o,fillColor:n,fillOpacity:r,strokeColor:a,stroke:c,strokeOpacity:l}={...e};o&&n&&"string"==typeof n&&"number"==typeof r&&(s.fill=new F({color:J(n,r)})),a&&"string"==typeof a&&"number"==typeof l&&(c||-1!==["MultiLineString","LineString"].indexOf(i))&&(s.stroke=new j({width:e.weight,color:J(a,l)})),"circle"===e.type&&"number"==typeof t&&(s.image=new x({radius:t,...s}))}else if("icon"===e.type){const t=e.html;if(t){const o={src:"data:image/svg+xml,"+escape(t),anchorXUnits:S.PIXELS,anchorYUnits:S.PIXELS,anchor:e.iconAnchor,imgSize:e.iconSize};s.image=new A(o)}}return new L(s)}}const Q={collapsible:!1};const $={collapsible:!1};class tt extends Z{constructor(t){const e=new R,o=e.getContainer();super({...$,...t,element:o}),this.panelContainer=e}async addControl(t,e){const o=this.getMap();if(o){const i=this.panelContainer.newPositionContainer(e);if(i){const e=await t,s=e.element;s&&s.classList.add("webmap-ctrl"),e.setTarget(i),o.addControl(e)}}}removeControl(t){const e=this.getMap();e&&e.removeControl(t)}getContainer(){return this.panelContainer.getContainer()}}class et{constructor(){this.options={target:"map"},this.layerAdapters=et.layerAdapters,this.controlAdapters=et.controlAdapters,this.emitter=new t,this.displayProjection="EPSG:3857",this.lonlatProjection="EPSG:4326",this._mapClickEvents=[],this._forEachFeatureAtPixel=[],this._unselectCb=[],this._isLoaded=!1,this._positionMem={}}create(t){this.options={...t};const i=this.getViewOptions(this.options),s={controls:[],view:new o(i),layers:[]};t.mapAdapterOptions&&Object.assign(s,t.mapAdapterOptions);const n={...s,target:this.options.target||"map"};this.map=new e(n),this._panelControl=new tt,this.map.addControl(this._panelControl),this.map.set("_mapClickEvents",this._mapClickEvents),this.map.set("_forEachFeatureAtPixel",this._forEachFeatureAtPixel),this.map.set("_addUnselectCb",(t=>this._addUnselectCb(t))),this.emitter.emit("create",this),this._olView=this.map.getView(),this._isLoaded=!0,this._addMapListeners(),this._addViewListeners()}destroy(){this.map&&this.map.dispose()}getContainer(){if(this.options.target){let t;return"string"==typeof this.options.target?t=document.getElementById(this.options.target):this.options.target instanceof HTMLElement&&(t=this.options.target),t}}getControlContainer(){if(this._panelControl)return this._panelControl.getContainer();throw new Error("The ol-map-adapter ControlPanel has not been initialized yet")}setCenter(t){this._olView&&this._olView.setCenter(n(t))}getCenter(){if(this._olView){const t=this._olView.getCenter();if(t){return i(t,this.displayProjection,this.lonlatProjection)}}}setZoom(t){this._olView&&this._olView.setZoom(t)}getZoom(){if(this._olView)return this._olView.getZoom()}fitBounds(t,e={}){if(this._olView){const{padding:o,maxZoom:i,offset:n}=e,r=this.getZoom(),a=s(t,this.lonlatProjection,this.displayProjection),c={};i&&(c.maxZoom=i),o&&(c.padding=[o,o]),n&&(c.padding=n),this._olView.fit(a,c),this._emitMoveEndEvents({zoom:r})}}getBounds(){if(!this._olView)return;const t=this._olView.calculateExtent();return s(t,this.displayProjection,this.lonlatProjection)}setRotation(t){this._olView&&this._olView.setRotation(t)}setView(t,e){if(this.map)if(Array.isArray(t)){this._setView({zoom:e,center:n(t)})}else{const{bounds:e}=t,o=this.getViewOptions(t);Object.values(o).some(Boolean)&&this._setView(o),e&&this.fitBounds(e)}}removeLayer(t){this.map&&this.map.removeLayer(t)}showLayer(t){this.map&&this.map.addLayer(t)}hideLayer(t){this.map&&this.map.removeLayer(t)}setLayerOpacity(t,e){t.setOpacity&&t.setOpacity(Number(e))}setLayerOrder(t,e){t&&t.setZIndex&&t.setZIndex(e)}createControl(t,e){return function(t,e={},o){return new(function(i){function s(){const s=document.createElement("div");s.className=(e.addClass?e.addClass+" ":"")+"ol-unselectable"+(e.bar?" webmap-ctrl-group":"")+(e.margin?" ol-control-margin":"");const n=t.onAdd(o);n&&s.appendChild(n),i.call(this,{element:s})}return i&&(s.__proto__=i),(s.prototype=Object.create(Z&&Z.prototype)).constructor=s,s.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},s}(Z))}(t,e,this)}createButtonControl(t){return function(t){return new(function(e){function o(){const o=document.createElement("button");o.className="custom-button-control","string"==typeof t.html?o.innerHTML=t.html:t.html&&o.appendChild(t.html),"string"==typeof t.title&&(o.title=t.title);const i=document.createElement("div");i.className=(t.addClass?t.addClass+" ":"")+"ol-unselectable webmap-ctrl-group",i.appendChild(o),e.call(this,{element:i}),o.addEventListener("click",(()=>t.onClick()),!1)}return e&&(o.__proto__=e),(o.prototype=Object.create(Z&&Z.prototype)).constructor=o,o.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},o}(Z))}(t)}addControl(t,e){if(this._panelControl)return this._panelControl.addControl(t,e),t}removeControl(t){this._panelControl&&this._panelControl.removeControl(t)}onMapClick(t){const e=N(t);this.emitter.emit("preclick",e);this._callEachFeatureAtPixel(t,"click")||this._mapClickEvents.forEach((e=>{e(t)})),this.emitter.emit("click",e)}getViewOptions(t){const{zoom:e,center:o,maxBounds:i,minZoom:r,maxZoom:a}=t,c={zoom:e,minZoom:r,maxZoom:a,projection:this.displayProjection};if(o&&(c.center=n(o)),i){const t=s(i,this.lonlatProjection,this.displayProjection);c.extent=t}return c}_callEachFeatureAtPixel(t,e){if(t&&t.pixel&&this._forEachFeatureAtPixel.length&&this.map){const o=this._forEachFeatureAtPixel.sort(((t,e)=>e[0]-t[0]));for(const i of o){if(i[1](t.pixel,t,e))return!0}}return!1}_emitMoveEndEvents(t){if(this._isLoaded){const e=this.getZoom();t.zoom!==e&&this.emitter.emit("zoomend")}}_addMapListeners(){const t=this.map;if(t){t.on("click",(t=>{this.onMapClick(t)})),t.on("pointermove",(t=>{this._callEachFeatureAtPixel(t,"hover")}));const e=this.getCenter(),o=this.getZoom();["movestart","moveend"].forEach((i=>{this._positionMem[i]={center:e,zoom:o},t.on(i,(()=>{this._emitPositionChangeEvent(i)}))}))}}_addViewListeners(){this._olView&&(this._olView.on("change:resolution",(()=>{this.emitter.emit("zoom",this)})),this._olView.on("change:center",(()=>{this.emitter.emit("move",this)})))}_setView(t){const{center:e,zoom:i,extent:s,minZoom:n,maxZoom:r}=t,a=this.map;if(!a)return;const c=a.getView();if(void 0!==s){c.dispose();const e=new o(t);this._olView=e,this._addViewListeners(),a.setView(e)}else e&&c.setCenter(e),void 0!==i&&c.setZoom(i),void 0!==n&&c.setMinZoom(n),void 0!==r&&c.setMaxZoom(r)}_addUnselectCb(t){for(const e of this._unselectCb)e();this._unselectCb.length=0,this._unselectCb.push(t)}_emitPositionChangeEvent(t){const e=this._positionMem[t];let o,i;e&&(o=e.center,i=e.zoom);const s=this.getCenter(),n=this.getZoom();if(i!==n){this.emitter.emit("movestart"===t?"zoomstart":"zoomend",this)}if(o&&s){const[e,i]=s,[n,r]=o;e===n&&i===r||this.emitter.emit(t,this)}else o!==s&&this.emitter.emit(t,this);this._positionMem[t]={center:s,zoom:n}}}et.layerAdapters={IMAGE:class extends H{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(t){if(Object.assign(this.options,t),t.url){const e=void 0!==t.ratio?t.ratio:1,o={url:t.url,params:{...t.params},projection:void 0},i=t.updateWmsParams;o.imageLoadFunction=(e,o)=>{const s=o.split("?")[0],n=o.split("?")[1],{resource:r,BBOX:a,WIDTH:c,HEIGHT:l,...p}=D(n),h={resource:r,bbox:a,width:c,height:l,...p},u=z(i?i(h):p),m=t.headers,d=s+"?"+u;m?G(e,d,m):e.getImage().src=d};let s=u,n=d;if(e>1){o.ratio=e,o.serverType=f.MAPSERVER;class t extends m{renderFrame(t,o){return t.pixelRatio=e,super.renderFrame(t,o)}}class i extends u{createRenderer(){return new t(this)}}s=i;class r extends d{getImageInternal(t,o,i,s){return super.getImageInternal(t,o,e,s)}}n=r}const r=new s({source:new n(o),opacity:t.opacity,...T(this.map,t),...t.nativeOptions});return this.layer=r,r}}},TILE:class extends H{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(t){Object.assign(this.options,t);const e=function(t,e){const o=[],i="string"==typeof e?e.split(""):e;return(null==i?void 0:i.length)?i.forEach((e=>{o.push(t.replace(/{s}/,e))})):o.push(t),o}(t.url,t.subdomains),o={attributions:t.attribution?[t.attribution]:[],urls:e};t.crossOrigin&&(o.crossOrigin=t.crossOrigin);const i=new h(o),s=t.headers;s&&i.setTileLoadFunction(((t,e)=>{G(t,e,s)}));return new r({source:i,opacity:t.opacity,...T(this.map,t),...t.nativeOptions})}},WMS:class extends H{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(t){Object.assign(this.options,t);const e={url:t.url,params:{LAYERS:t.layers,VERSION:t.version},projection:void 0},o=t.updateWmsParams;o&&(e.tileLoadFunction=(e,i)=>{const s=i.split("?")[0],n=i.split("?")[1],{resource:r,BBOX:a,WIDTH:c,HEIGHT:l}=D(n),p=z(o({resource:r,bbox:a,width:c,height:l})),h=t.headers,u=s+"?"+p;h?G(e,u,h):e.getImage().src=u});const i=new a(e),s=new r({source:i,opacity:t.opacity,...T(this.map,t),...t.nativeOptions});return this.layer=s,s}},OSM:class extends H{constructor(t,e){super(t,e),this.map=t,this.options=e,this.name="OpenStreetMap"}addLayer(t){Object.assign(this.options,t),this.options.name=this.name;return new r({source:new l({attributions:[p]}),...t.nativeOptions})}},GEOJSON:class extends H{constructor(t,e){super(t,e),this.map=t,this.options=e,this.selected=!1,this.displayProjection="EPSG:3857",this.lonlatProjection="EPSG:4326",this.vectorSource=new _,this._features=[],this._selectedFeatures=[],this._openedPopup=[],this._forEachFeatureAtPixel=[],this._mapClickEvents=[],this._styleCache={},this.displayProjection=t.getView().getProjection().getCode()}get addUnselectCb(){return this.map.get("_addUnselectCb")}get mapClickEvents(){return this.map.get("_mapClickEvents")}get forEachFeatureAtPixel(){return this.map.get("_forEachFeatureAtPixel")}addLayer(t){var e;Object.assign(this.options,t),this.paint=t.paint,this.selectedPaint=t.selectedPaint;const o=t.data;o&&this.addData(o),this.layer=new g({source:this.vectorSource,style:e=>{const o=[],i=e.getId(),s=void 0!==i&&this._styleCache[i];if(s)return s;const n=K(e,t.paint);n&&o.push(n);const{labelField:r,label:a}=this.options;let c="";if("string"==typeof r?c=e.get(r):a&&(c=a(this._createLayerDefOpts(U(e)))),c=String(c),c){const e=C(c)?c:"";if(e){const i=function(t,e){let o={font:"12px Calibri,sans-serif",overflow:!0,fill:new F({color:"#000"}),stroke:new j({color:"#fff",width:3})};return"point"===t&&(o={...o,placement:"point",textBaseline:"bottom",offsetY:20}),new L({text:new b(o)})}(t.type||"polygon");i.getText().setText(e),o.push(i)}}return void 0!==i&&(this._styleCache[i]=o),o},...T(this.map,t),...t.nativeOptions});return(null===(e=t.interactive)||void 0===e||e)&&this._addEventListener(),this.layer}beforeRemove(){const t=this.forEachFeatureAtPixel;for(let o=t.length;o--;){const e=t[o][1];-1!==t.findIndex((t=>t[1]===e))&&t.splice(o,1)}this._forEachFeatureAtPixel.length=0;const e=this.mapClickEvents;for(let o=e.length;o--;){-1!==e.indexOf(e[o])&&e.splice(o,1)}this._mapClickEvents.length=0,this._removeAllPopup()}clearLayer(t){if(this.unselect(),t){const e=this.vectorSource.getFeatures().values();let o;for(;!(o=e.next()).done;){t(U(o.value))&&this.vectorSource.removeFeature(o.value)}}else this.vectorSource.clear()}setData(t){this.clearLayer(),this.addData(t)}addData(t){const e=this.options.srs,o="EPSG:"+(null!=e?e:"4326"),i=(new c).readFeatures(t,{dataProjection:o,featureProjection:this.displayProjection});if(this._features=this._features.concat(i),this._filterFun)this.filter(this._filterFun);else if(this.vectorSource.addFeatures(i),this.options.popup)for(const s of this._features)this._openPopup({feature:s,type:"api",options:this.options.popupOptions})}select(t){if("function"==typeof t){this._features.filter((e=>t(this._createLayerDefOpts(U(e))))).forEach((t=>{this._selectFeature(t)}))}else this.selected||(this.selected=!0,this.selectedPaint&&this._setPaintEachLayer(this.selectedPaint))}unselect(t){let e=this._selectedFeatures;"function"==typeof t?e=this._selectedFeatures.filter((e=>t(this._createLayerDefOpts(U(e))))):this.selected&&(this.selected=!1);for(const o of e)this._unselectFeature(o);this._removeAllPopup()}getLayers(){return this._features.map((t=>this._createLayerDefOpts(U(t))))}getSelected(){return this._selectedFeatures.map((t=>this._createLayerDefOpts(U(t))))}filter(t){this._filterFun=t;const e=this._features,o=t?e.filter((e=>t(this._createLayerDefOpts(U(e))))):e;this.vectorSource.clear();const i=o.length;for(let s=0;s<i;s++)this.vectorSource.addFeature(o[s]);return o.map((t=>this._createLayerDefOpts(U(t))))}cleanFilter(){this.filter()}getExtent(){return this.getBounds()}getBounds(){if(this.layer){const t=this.layer.getSource().getExtent();return s(t,this.displayProjection,this.lonlatProjection)}}setPaint(t){t&&(this.paint=t,this._setPaintEachLayer(this.paint))}setSelectedPaint(t){t&&(this.selectedPaint=t,this._setPaintEachLayer(this.selectedPaint))}updatePaint(t){this.paint={...this.paint,...t},this._setPaintEachLayer(this.paint)}updateSelectedPaint(t){this.selectedPaint={...this.selectedPaint,...t},this._setPaintEachLayer(this.selectedPaint)}_createLayerDefOpts(t){return{target:this,feature:t,...X({feature:t,dataProjection:this.lonlatProjection,featureProjection:this.displayProjection})}}_setPaintEachLayer(t){if(this.layer){this.layer.getSource().getFeatures().forEach((e=>{const o=K(e,t);o&&e.setStyle(o)}))}}_addEventListener(){var t;const e=this.forEachFeatureAtPixel,o=[this.options.order||0,(t,e,o)=>this._onFeatureAtPixel(t,e,o)];this._forEachFeatureAtPixel.push(o),e.push(o);(null===(t=this.options.unselectOnClick)||void 0===t||t)&&(this._mapClickEvents.push((()=>this.unselect())),this.mapClickEvents.push((()=>this.unselect())))}_onFeatureAtPixel(t,e,o){const i=t&&this.map.getFeaturesAtPixel(t,{layerFilter:t=>t===this.layer})[0],s=(t=>({layer:this,event:N(t),source:t}))(e);if(i){const t={...s,...this._createLayerDefOpts(U(i))};let e=-1!==this._selectedFeatures.indexOf(i);return this.options.selectable&&("hover"===o&&this.options.selectOnHover||"click"===o)&&(e?this.options&&this.options.unselectOnSecondClick&&(this._unselectFeature(i),e=!1):(this._selectFeature(i,t.event.lngLat),e=!0)),"click"===o&&this.options.onClick&&this.options.onClick({selected:e,...t}),"hover"===o&&(this._mouseOver=!0,this.options.onMouseOver&&this.options.onMouseOver(t)),!0}return"hover"===o&&this._mouseOver&&(this._mouseOver=!1,this.options.onMouseOut&&this.options.onMouseOut(s),this.options.selectOnHover&&this.unselect()),!1}_selectFeature(t,e){this.addUnselectCb((()=>this._unselectFeature(t)));const o=this.options,i=e?"click":"api";if(o&&!o.multiselect&&this._selectedFeatures.forEach((t=>this._unselectFeature(t))),this._selectedFeatures.push(t),this.selected=!0,o&&o.selectedPaint){const e=K(t,o.selectedPaint);e&&t.setStyle(e)}if(this.options.popupOnSelect&&this._openPopup({coordinates:e,feature:t,options:this.options.popupOptions,type:"click"}),this.options.onSelect){const e=U(t);this.options.onSelect({layer:this,features:[],type:i,...X({feature:e,dataProjection:this.lonlatProjection,featureProjection:this.displayProjection})})}}_unselectFeature(t){const e=this._selectedFeatures.indexOf(t);if(-1!==e){this._selectedFeatures.splice(e,1);const o=this._openedPopup.find((e=>e[0]===t));o&&this._removePopup(o[1])}if(this.selected=this._selectedFeatures.length>0,this.options&&this.options.paint){const e=K(t,this.options.paint);e&&t.setStyle(e)}}async _openPopup({coordinates:t,feature:e,options:o={},type:s}){const n=this.map;if(!n)return;let r;const a=[],c=()=>{r&&this._removePopup(r)},{createPopupContent:l,popupContent:p}=o,h=U(e),u=l?await l({close:c,onClose:t=>{a.push(t)},type:s,...this._createLayerDefOpts(h)}):p;if(t=t||h&&function(t){return"Polygon"===t.geometry.type?w(t.geometry.coordinates):"Point"===t.geometry.type?t.geometry.coordinates:(e=v(t)).reduce(((t,o)=>[t[0]+o[0]/e.length,t[1]+o[1]/e.length]),[0,0]);var e}(h),u&&t){const s="string"==typeof u?function(t){const e=document.createElement("div");return e.innerHTML=t,e}(u):u,l=this._createPopupElement({...o,popupContent:s,close:c});r=new y({element:l}),r.setPosition(i(t,this.lonlatProjection,this.displayProjection)),n.addOverlay(r),this._openedPopup.push([e,r,a])}}_createPopupElement({closeButton:t,popupContent:e,maxWidth:o,minWidth:i,close:s}){t=null!=t?t:!this.options.selectOnHover;const n=P("div","ol-popup");if(o&&(n.style.maxWidth=o+"px"),i&&(n.style.minWidth=i+"px"),t){const t=P("a","ol-popup-closer",n);t.setAttribute("href","#"),t.addEventListener("click",s)}return P("div","popup-content",n).appendChild(e),n}_removeAllPopup(){const t=[...this._openedPopup];this._openedPopup=[];for(const e of t)this._removePopup(e[1])}_removePopup(t){var e,o;const i=this.map;if(i){i.removeOverlay(t);const s=this._openedPopup.findIndex((e=>e[1]===t));if(-1!==s){const[t,,i]=this._openedPopup[s],n=null===(o=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===o||o;for(const e of i)e(this._createLayerDefOpts(U(t)));i.length=0,n&&this._unselectFeature(t),this._openedPopup.splice(s,1)}}}}},et.controlAdapters={ZOOM:class extends k{constructor(...t){super(...t),this.element.classList.remove("ol-control"),this.element.classList.add("webmap-ctrl-group")}},ATTRIBUTION:class extends I{constructor(t){super({...Q,...t})}}};var ot=et;export{ot as default}; | ||
import{EventEmitter as t}from"events";import e from"ol/Map";import o from"ol/View";import{transform as n,transformExtent as i,fromLonLat as r}from"ol/proj";import s from"ol/layer/Tile";import a from"ol/source/TileWMS";import p from"ol/format/GeoJSON";import c,{ATTRIBUTION as l}from"ol/source/OSM";import u from"ol/source/XYZ";import h from"ol/layer/Image";import f from"ol/renderer/canvas/ImageLayer";import m from"ol/source/ImageWMS";import d from"ol/source/WMSServerType";import y from"ol/Overlay";import v from"ol/layer/Vector";import g from"ol/source/Vector";import{create as _}from"@nextgis/dom";import{getCoordinates as P,defined as w}from"@nextgis/utils";import O from"polylabel";import{getCenter as b}from"ol/extent";import C from"ol/style/Circle";import{asArray as E}from"ol/color";import{Style as x,Text as L,Fill as j,Stroke as S}from"ol/style";import F from"ol/style/IconAnchorUnits";import A from"ol/style/Icon";import{isPaintCallback as V,isPaint as M}from"@nextgis/paint";import k from"ol/control/Zoom";import I from"ol/control/Attribution";import Z from"ol/control/Control";import T from"@nextgis/control-container"; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. | ||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | ||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | ||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | ||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | ||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var R=function(t,e){return(R=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])})(t,e)};function B(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function o(){this.constructor=t}R(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}var D=function(){return(D=Object.assign||function(t){for(var e,o=1,n=arguments.length;o<n;o++)for(var i in e=arguments[o])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function G(t,e,o,n){return new(o||(o=Promise))((function(i,r){function s(t){try{p(n.next(t))}catch(e){r(e)}}function a(t){try{p(n.throw(t))}catch(e){r(e)}}function p(t){var e;t.done?i(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(s,a)}p((n=n.apply(t,e||[])).next())}))}function U(t,e){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==r[0]&&2!==r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=e.call(t,s)}catch(a){r=[6,a],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}function H(t,e){var o={minZoom:e.minZoom,maxZoom:e.maxZoom};return e.maxScale&&(o.minResolution=z(t,e.maxScale)),e.minScale&&(o.maxResolution=z(t,e.minScale)),o}function z(t,e){if(e)return function(t,e){return t/(39.37*e*90.71446714322)}(e,t.getView().getProjection().getMetersPerUnit()||1)}function W(t){return(new p).writeFeatureObject(t,{dataProjection:"EPSG:4326",featureProjection:"EPSG:3857"})}function N(t){for(var e,o,n=decodeURIComponent,i=t.split("&"),r={},s=0,a=i.length,p=void 0;s<a;++s)if((p=i[s]).length){var c=p.indexOf("=");c<0?(e=n(p),o=""):(e=n(p.slice(0,c)),o=n(p.slice(c+1))),"string"==typeof r[e]&&(r[e]=[r[e]]),Array.isArray(r[e])?r[e].push(o):r[e]=o}return r}function X(t,e){var o,n=[];for(o in t){var i=e?e+"["+o+"]":o,r=t[o];n.push(null!==r&&"object"==typeof r?X(r,i):encodeURIComponent(i)+"="+encodeURIComponent(r))}return n.join("&")}function Y(t,e,o){var n=new XMLHttpRequest;for(var i in n.open("GET",e),n.responseType="arraybuffer",o)n.setRequestHeader(i,o[i]);n.onload=function(){var e=new Uint8Array(this.response),o=new Blob([e],{type:"image/png"}),n=(window.URL||window.webkitURL).createObjectURL(o);t.getImage().src=n},n.send()}var q=function(){function t(t,e){this.map=t,this.options=e}return t.prototype.setOpacity=function(t){this.options.opacity=Number(t),this.layer&&this.layer.setOpacity&&this.layer.setOpacity(this.options.opacity)},t}(),J=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.map=e,n.options=o,n}return B(e,t),e.prototype.addLayer=function(t){Object.assign(this.options,t);var e={url:t.url,params:{LAYERS:t.layers,VERSION:t.version},projection:void 0},o=t.updateWmsParams;o&&(e.tileLoadFunction=function(e,n){var i=n.split("?")[0],r=N(n.split("?")[1]),s=X(o({resource:r.resource,bbox:r.BBOX,width:r.WIDTH,height:r.HEIGHT})),a=t.headers,p=i+"?"+s;a?Y(e,p,a):e.getImage().src=p});var n=new a(e),i=new s(D(D({source:n,opacity:t.opacity},H(this.map,t)),t.nativeOptions));return this.layer=i,i},e}(q),K=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.map=e,n.options=o,n.name="OpenStreetMap",n}return B(e,t),e.prototype.addLayer=function(t){return Object.assign(this.options,t),this.options.name=this.name,new s(D({source:new c({attributions:[l]})},t.nativeOptions))},e}(q);var Q=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.map=e,n.options=o,n}return B(e,t),e.prototype.addLayer=function(t){Object.assign(this.options,t);var e=function(t,e){var o=[],n="string"==typeof e?e.split(""):e;return(null==n?void 0:n.length)?n.forEach((function(e){o.push(t.replace(/{s}/,e))})):o.push(t),o}(t.url,t.subdomains),o={attributions:t.attribution?[t.attribution]:[],urls:e};t.crossOrigin&&(o.crossOrigin=t.crossOrigin);var n=new u(o),i=t.headers;return i&&n.setTileLoadFunction((function(t,e){Y(t,e,i)})),new s(D(D({source:n,opacity:t.opacity},H(this.map,t)),t.nativeOptions))},e}(q),$=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.map=e,n.options=o,n}return B(e,t),e.prototype.addLayer=function(t){if(Object.assign(this.options,t),t.url){var e=void 0!==t.ratio?t.ratio:1,o={url:t.url,params:D({},t.params),projection:void 0},n=t.updateWmsParams;o.imageLoadFunction=function(e,o){var i=o.split("?")[0],r=N(o.split("?")[1]),s=r.resource,a=r.BBOX,p=r.WIDTH,c=r.HEIGHT,l=function(t,e){var o={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(o[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(o[n[i]]=t[n[i]])}return o}(r,["resource","BBOX","WIDTH","HEIGHT"]),u=D({resource:s,bbox:a,width:p,height:c},l),h=X(n?n(u):l),f=t.headers,m=i+"?"+h;f?Y(e,m,f):e.getImage().src=m};var i=h,r=m;if(e>1){o.ratio=e,o.serverType=d.MAPSERVER;var s=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return B(o,t),o.prototype.renderFrame=function(o,n){return o.pixelRatio=e,t.prototype.renderFrame.call(this,o,n)},o}(f);i=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return B(e,t),e.prototype.createRenderer=function(){return new s(this)},e}(h),r=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return B(o,t),o.prototype.getImageInternal=function(o,n,i,r){return t.prototype.getImageInternal.call(this,o,n,e,r)},o}(m)}var a=new r(o),p=new i(D(D({source:a,opacity:t.opacity},H(this.map,t)),t.nativeOptions));return this.layer=p,p}},e}(q);function tt(t,e,o){void 0===e&&(e="EPSG:3857"),void 0===o&&(o="EPSG:4326");var i=n(t.coordinate,e,o),r=i[0],s=i[1];return{latLng:{lat:s,lng:r},lngLat:[r,s],pixel:{left:t.pixel[0],top:t.pixel[1]},source:t}}function et(t){var e=function(t){var e=t.feature,o=t.dataProjection,n=t.featureProjection,i=(new p).readFeatures({type:"FeatureCollection",features:Array.isArray(e)?e:[e]},{dataProjection:o,featureProjection:n}),r=new g;return r.addFeatures(i),r}(t),o=e.getExtent(),n=i(o,t.featureProjection,t.dataProjection);return e.dispose(),n}function ot(t){return{getBounds:function(){return et(t)},getCenter:function(){return function(t){var e=et(t);return b(e)}(t)}}}var nt={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon",Circle:"point"},it={polygon:"path",line:"path",point:"circle"};function rt(t,e){var o=E(t).slice();return o[3]=void 0!==e?e:1,o}function st(t,e){if(void 0===e&&(e={}),V(e))return st(t,e(W(t)));if(M(e)){var o=t.getGeometry(),n=o&&o.getType()||"Point",i={};if(!e.type){var r=nt[n],s="polygon"===r||"line"===r?"path":"html"in e||"className"in e?"icon":it[r];s&&(e.type=s)}if("path"===e.type||"circle"===e.type){var a=D({},e),p=a.radius,c=a.fillColor,l=a.fillOpacity,u=a.strokeColor,h=a.stroke,f=a.strokeOpacity;a.fill&&c&&"string"==typeof c&&"number"==typeof l&&(i.fill=new j({color:rt(c,l)})),u&&"string"==typeof u&&"number"==typeof f&&(h||-1!==["MultiLineString","LineString"].indexOf(n))&&(i.stroke=new S({width:e.weight,color:rt(u,f)})),"circle"===e.type&&"number"==typeof p&&(i.image=new C(D({radius:p},i)))}else if("icon"===e.type){var m=e.html;if(m){var d={src:"data:image/svg+xml,"+escape(m),anchorXUnits:F.PIXELS,anchorYUnits:F.PIXELS,anchor:e.iconAnchor,imgSize:e.iconSize};i.image=new A(d)}}return new x(i)}}var at=function(t){function e(e,o){var n=t.call(this,e,o)||this;return n.map=e,n.options=o,n.selected=!1,n.displayProjection="EPSG:3857",n.lonlatProjection="EPSG:4326",n.vectorSource=new g,n._features=[],n._selectedFeatures=[],n._openedPopup=[],n._forEachFeatureAtPixel=[],n._mapClickEvents=[],n._styleCache={},n.displayProjection=e.getView().getProjection().getCode(),n}return B(e,t),Object.defineProperty(e.prototype,"addUnselectCb",{get:function(){return this.map.get("_addUnselectCb")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"mapClickEvents",{get:function(){return this.map.get("_mapClickEvents")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"forEachFeatureAtPixel",{get:function(){return this.map.get("_forEachFeatureAtPixel")},enumerable:!1,configurable:!0}),e.prototype.addLayer=function(t){var e,o=this;Object.assign(this.options,t),this.paint=t.paint,this.selectedPaint=t.selectedPaint;var n=t.data;return n&&this.addData(n),this.layer=new v(D(D({source:this.vectorSource,style:function(e){var n=[],i=e.getId(),r=void 0!==i&&o._styleCache[i];if(r)return r;var s=st(e,t.paint);s&&n.push(s);var a=o.options,p=a.labelField,c=a.label,l="";if("string"==typeof p?l=e.get(p):c&&(l=c(o._createLayerDefOpts(W(e)))),l=String(l)){var u=w(l)?l:"";if(u){var h=function(t,e){var o={font:"12px Calibri,sans-serif",overflow:!0,fill:new j({color:"#000"}),stroke:new S({color:"#fff",width:3})};return"point"===t&&(o=D(D({},o),{placement:"point",textBaseline:"bottom",offsetY:20})),new x({text:new L(o)})}(t.type||"polygon");h.getText().setText(u),n.push(h)}}return void 0!==i&&(o._styleCache[i]=n),n}},H(this.map,t)),t.nativeOptions)),(null===(e=t.interactive)||void 0===e||e)&&this._addEventListener(),this.layer},e.prototype.beforeRemove=function(){for(var t=this.forEachFeatureAtPixel,e=function(e){var o=t[e][1];-1!==t.findIndex((function(t){return t[1]===o}))&&t.splice(e,1)},o=t.length;o--;)e(o);this._forEachFeatureAtPixel.length=0;var n=this.mapClickEvents;for(o=n.length;o--;){-1!==n.indexOf(n[o])&&n.splice(o,1)}this._mapClickEvents.length=0,this._removeAllPopup()},e.prototype.clearLayer=function(t){if(this.unselect(),t)for(var e=this.vectorSource.getFeatures().values(),o=void 0;!(o=e.next()).done;){t(W(o.value))&&this.vectorSource.removeFeature(o.value)}else this.vectorSource.clear()},e.prototype.setData=function(t){this.clearLayer(),this.addData(t)},e.prototype.addData=function(t){var e=this.options.srs,o="EPSG:"+(null!=e?e:"4326"),n=(new p).readFeatures(t,{dataProjection:o,featureProjection:this.displayProjection});if(this._features=this._features.concat(n),this._filterFun)this.filter(this._filterFun);else if(this.vectorSource.addFeatures(n),this.options.popup)for(var i=0,r=this._features;i<r.length;i++){this._openPopup({feature:r[i],type:"api",options:this.options.popupOptions})}},e.prototype.select=function(t){var e=this;"function"==typeof t?this._features.filter((function(o){return t(e._createLayerDefOpts(W(o)))})).forEach((function(t){e._selectFeature(t)})):this.selected||(this.selected=!0,this.selectedPaint&&this._setPaintEachLayer(this.selectedPaint))},e.prototype.unselect=function(t){var e=this,o=this._selectedFeatures;"function"==typeof t?o=this._selectedFeatures.filter((function(o){return t(e._createLayerDefOpts(W(o)))})):this.selected&&(this.selected=!1);for(var n=0,i=o;n<i.length;n++){this._unselectFeature(i[n])}this._removeAllPopup()},e.prototype.getLayers=function(){var t=this;return this._features.map((function(e){return t._createLayerDefOpts(W(e))}))},e.prototype.getSelected=function(){var t=this;return this._selectedFeatures.map((function(e){return t._createLayerDefOpts(W(e))}))},e.prototype.filter=function(t){var e=this;this._filterFun=t;var o=this._features,n=t?o.filter((function(o){return t(e._createLayerDefOpts(W(o)))})):o;this.vectorSource.clear();for(var i=n.length,r=0;r<i;r++)this.vectorSource.addFeature(n[r]);return n.map((function(t){return e._createLayerDefOpts(W(t))}))},e.prototype.cleanFilter=function(){this.filter()},e.prototype.getExtent=function(){return this.getBounds()},e.prototype.getBounds=function(){if(this.layer){var t=this.layer.getSource().getExtent();return i(t,this.displayProjection,this.lonlatProjection)}},e.prototype.setPaint=function(t){t&&(this.paint=t,this._setPaintEachLayer(this.paint))},e.prototype.setSelectedPaint=function(t){t&&(this.selectedPaint=t,this._setPaintEachLayer(this.selectedPaint))},e.prototype.updatePaint=function(t){this.paint=D(D({},this.paint),t),this._setPaintEachLayer(this.paint)},e.prototype.updateSelectedPaint=function(t){this.selectedPaint=D(D({},this.selectedPaint),t),this._setPaintEachLayer(this.selectedPaint)},e.prototype._createLayerDefOpts=function(t){return D({target:this,feature:t},ot({feature:t,dataProjection:this.lonlatProjection,featureProjection:this.displayProjection}))},e.prototype._setPaintEachLayer=function(t){this.layer&&this.layer.getSource().getFeatures().forEach((function(e){var o=st(e,t);o&&e.setStyle(o)}))},e.prototype._addEventListener=function(){var t,e=this,o=this.forEachFeatureAtPixel,n=[this.options.order||0,function(t,o,n){return e._onFeatureAtPixel(t,o,n)}];this._forEachFeatureAtPixel.push(n),o.push(n),(null===(t=this.options.unselectOnClick)||void 0===t||t)&&(this._mapClickEvents.push((function(){return e.unselect()})),this.mapClickEvents.push((function(){return e.unselect()})))},e.prototype._onFeatureAtPixel=function(t,e,o){var n,i=this,r=t&&this.map.getFeaturesAtPixel(t,{layerFilter:function(t){return t===i.layer}})[0],s={layer:i,event:tt(n=e),source:n};if(r){var a=D(D({},s),this._createLayerDefOpts(W(r))),p=-1!==this._selectedFeatures.indexOf(r);return this.options.selectable&&("hover"===o&&this.options.selectOnHover||"click"===o)&&(p?this.options&&this.options.unselectOnSecondClick&&(this._unselectFeature(r),p=!1):(this._selectFeature(r,a.event.lngLat),p=!0)),"click"===o&&this.options.onClick&&this.options.onClick(D({selected:p},a)),"hover"===o&&(this._mouseOver=!0,this.options.onMouseOver&&this.options.onMouseOver(a)),!0}return"hover"===o&&this._mouseOver&&(this._mouseOver=!1,this.options.onMouseOut&&this.options.onMouseOut(s),this.options.selectOnHover&&this.unselect()),!1},e.prototype._selectFeature=function(t,e){var o=this;this.addUnselectCb((function(){return o._unselectFeature(t)}));var n=this.options,i=e?"click":"api";if(n&&!n.multiselect&&this._selectedFeatures.forEach((function(t){return o._unselectFeature(t)})),this._selectedFeatures.push(t),this.selected=!0,n&&n.selectedPaint){var r=st(t,n.selectedPaint);r&&t.setStyle(r)}if(this.options.popupOnSelect&&this._openPopup({coordinates:e,feature:t,options:this.options.popupOptions,type:"click"}),this.options.onSelect){var s=W(t);this.options.onSelect(D({layer:this,features:[],type:i},ot({feature:s,dataProjection:this.lonlatProjection,featureProjection:this.displayProjection})))}},e.prototype._unselectFeature=function(t){var e=this._selectedFeatures.indexOf(t);if(-1!==e){this._selectedFeatures.splice(e,1);var o=this._openedPopup.find((function(e){return e[0]===t}));o&&this._removePopup(o[1])}if(this.selected=this._selectedFeatures.length>0,this.options&&this.options.paint){var n=st(t,this.options.paint);n&&t.setStyle(n)}},e.prototype._openPopup=function(t){var e=t.coordinates,o=t.feature,i=t.options,r=void 0===i?{}:i,s=t.type;return G(this,void 0,void 0,(function(){var t,i,a,p,c,l,u,h,f,m,d,v,g=this;return U(this,(function(_){switch(_.label){case 0:return(t=this.map)?(a=[],p=function(t){a.push(t)},c=function(){i&&g._removePopup(i)},l=r.createPopupContent,u=r.popupContent,h=W(o),l?[4,l(D({close:c,onClose:p,type:s},this._createLayerDefOpts(h)))]:[3,2]):[2];case 1:return m=_.sent(),[3,3];case 2:m=u,_.label=3;case 3:return f=m,e=e||h&&function(t){return"Polygon"===t.geometry.type?O(t.geometry.coordinates):"Point"===t.geometry.type?t.geometry.coordinates:(e=P(t)).reduce((function(t,o){return[t[0]+o[0]/e.length,t[1]+o[1]/e.length]}),[0,0]);var e}(h),f&&e&&(d="string"==typeof f?(w=f,(b=document.createElement("div")).innerHTML=w,b):f,v=this._createPopupElement(D(D({},r),{popupContent:d,close:c})),(i=new y({element:v})).setPosition(n(e,this.lonlatProjection,this.displayProjection)),t.addOverlay(i),this._openedPopup.push([o,i,a])),[2]}var w,b}))}))},e.prototype._createPopupElement=function(t){var e=t.closeButton,o=t.popupContent,n=t.maxWidth,i=t.minWidth,r=t.close;e=null!=e?e:!this.options.selectOnHover;var s=_("div","ol-popup");if(n&&(s.style.maxWidth=n+"px"),i&&(s.style.minWidth=i+"px"),e){var a=_("a","ol-popup-closer",s);a.setAttribute("href","#"),a.addEventListener("click",r)}return _("div","popup-content",s).appendChild(o),s},e.prototype._removeAllPopup=function(){var t=function(t,e,o){if(o||2===arguments.length)for(var n,i=0,r=e.length;i<r;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([],this._openedPopup,!0);this._openedPopup=[];for(var e=0,o=t;e<o.length;e++){this._removePopup(o[e][1])}},e.prototype._removePopup=function(t){var e,o,n=this.map;if(n){n.removeOverlay(t);var i=this._openedPopup.findIndex((function(e){return e[1]===t}));if(-1!==i){for(var r=this._openedPopup[i],s=r[0],a=r[2],p=null===(o=null===(e=this.options.popupOptions)||void 0===e?void 0:e.unselectOnClose)||void 0===o||o,c=0,l=a;c<l.length;c++){(0,l[c])(this._createLayerDefOpts(W(s)))}a.length=0,p&&this._unselectFeature(s),this._openedPopup.splice(i,1)}}},e}(q),pt=function(t){function e(){for(var e=[],o=0;o<arguments.length;o++)e[o]=arguments[o];var n=t.apply(this,e)||this;return n.element.classList.remove("ol-control"),n.element.classList.add("webmap-ctrl-group"),n}return B(e,t),e}(k),ct={collapsible:!1},lt=function(t){function e(e){return t.call(this,D(D({},ct),e))||this}return B(e,t),e}(I),ut={collapsible:!1},ht=function(t){function e(e){var o=this,n=new T,i=n.getContainer();return(o=t.call(this,D(D(D({},ut),e),{element:i}))||this).panelContainer=n,o}return B(e,t),e.prototype.addControl=function(t,e){return G(this,void 0,void 0,(function(){var o,n,i,r;return U(this,(function(s){switch(s.label){case 0:return(o=this.getMap())&&(n=this.panelContainer.newPositionContainer(e))?[4,t]:[3,2];case 1:i=s.sent(),(r=i.element)&&r.classList.add("webmap-ctrl"),i.setTarget(n),o.addControl(i),s.label=2;case 2:return[2]}}))}))},e.prototype.removeControl=function(t){var e=this.getMap();e&&e.removeControl(t)},e.prototype.getContainer=function(){return this.panelContainer.getContainer()},e}(Z);var ft=function(){function s(){this.options={target:"map"},this.layerAdapters=s.layerAdapters,this.controlAdapters=s.controlAdapters,this.emitter=new t,this.displayProjection="EPSG:3857",this.lonlatProjection="EPSG:4326",this._mapClickEvents=[],this._forEachFeatureAtPixel=[],this._unselectCb=[],this._isLoaded=!1,this._positionMem={}}return s.prototype.create=function(t){var n=this;this.options=D({},t);var i=this.getViewOptions(this.options),r={controls:[],view:new o(i),layers:[]};t.mapAdapterOptions&&Object.assign(r,t.mapAdapterOptions);var s=D(D({},r),{target:this.options.target||"map"});this.map=new e(s),this._panelControl=new ht,this.map.addControl(this._panelControl),this.map.set("_mapClickEvents",this._mapClickEvents),this.map.set("_forEachFeatureAtPixel",this._forEachFeatureAtPixel),this.map.set("_addUnselectCb",(function(t){return n._addUnselectCb(t)})),this.emitter.emit("create",this),this._olView=this.map.getView(),this._isLoaded=!0,this._addMapListeners(),this._addViewListeners()},s.prototype.destroy=function(){this.map&&this.map.dispose()},s.prototype.getContainer=function(){if(this.options.target){var t=void 0;return"string"==typeof this.options.target?t=document.getElementById(this.options.target):this.options.target instanceof HTMLElement&&(t=this.options.target),t}},s.prototype.getControlContainer=function(){if(this._panelControl)return this._panelControl.getContainer();throw new Error("The ol-map-adapter ControlPanel has not been initialized yet")},s.prototype.setCenter=function(t){this._olView&&this._olView.setCenter(r(t))},s.prototype.getCenter=function(){if(this._olView){var t=this._olView.getCenter();if(t)return n(t,this.displayProjection,this.lonlatProjection)}},s.prototype.setZoom=function(t){this._olView&&this._olView.setZoom(t)},s.prototype.getZoom=function(){if(this._olView)return this._olView.getZoom()},s.prototype.fitBounds=function(t,e){if(void 0===e&&(e={}),this._olView){var o=e.padding,n=e.maxZoom,r=e.offset,s=this.getZoom(),a=i(t,this.lonlatProjection,this.displayProjection),p={};n&&(p.maxZoom=n),o&&(p.padding=[o,o]),r&&(p.padding=r),this._olView.fit(a,p),this._emitMoveEndEvents({zoom:s})}},s.prototype.getBounds=function(){if(this._olView){var t=this._olView.calculateExtent();return i(t,this.displayProjection,this.lonlatProjection)}},s.prototype.setRotation=function(t){this._olView&&this._olView.setRotation(t)},s.prototype.setView=function(t,e){if(this.map)if(Array.isArray(t)){this._setView({zoom:e,center:r(t)})}else{var o=t.bounds,n=this.getViewOptions(t);Object.values(n).some(Boolean)&&this._setView(n),o&&this.fitBounds(o)}},s.prototype.removeLayer=function(t){this.map&&this.map.removeLayer(t)},s.prototype.showLayer=function(t){this.map&&this.map.addLayer(t)},s.prototype.hideLayer=function(t){this.map&&this.map.removeLayer(t)},s.prototype.setLayerOpacity=function(t,e){t.setOpacity&&t.setOpacity(Number(e))},s.prototype.setLayerOrder=function(t,e){t&&t.setZIndex&&t.setZIndex(e)},s.prototype.createControl=function(t,e){return function(t,e,o){return void 0===e&&(e={}),new(function(n){function i(){var i=document.createElement("div");i.className=(e.addClass?e.addClass+" ":"")+"ol-unselectable"+(e.bar?" webmap-ctrl-group":"")+(e.margin?" ol-control-margin":"");var r=t.onAdd(o);r&&i.appendChild(r),n.call(this,{element:i})}return n&&(i.__proto__=n),(i.prototype=Object.create(Z&&Z.prototype)).constructor=i,i.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},i}(Z))}(t,e,this)},s.prototype.createButtonControl=function(t){return function(t){return new(function(e){function o(){var o=document.createElement("button");o.className="custom-button-control","string"==typeof t.html?o.innerHTML=t.html:t.html&&o.appendChild(t.html),"string"==typeof t.title&&(o.title=t.title);var n=document.createElement("div");n.className=(t.addClass?t.addClass+" ":"")+"ol-unselectable webmap-ctrl-group",n.appendChild(o),e.call(this,{element:n}),o.addEventListener("click",(function(){return t.onClick()}),!1)}return e&&(o.__proto__=e),(o.prototype=Object.create(Z&&Z.prototype)).constructor=o,o.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},o}(Z))}(t)},s.prototype.addControl=function(t,e){if(this._panelControl)return this._panelControl.addControl(t,e),t},s.prototype.removeControl=function(t){this._panelControl&&this._panelControl.removeControl(t)},s.prototype.onMapClick=function(t){var e=tt(t);this.emitter.emit("preclick",e),this._callEachFeatureAtPixel(t,"click")||this._mapClickEvents.forEach((function(e){e(t)})),this.emitter.emit("click",e)},s.prototype.getViewOptions=function(t){var e=t.center,o=t.maxBounds,n={zoom:t.zoom,minZoom:t.minZoom,maxZoom:t.maxZoom,projection:this.displayProjection};if(e&&(n.center=r(e)),o){var s=i(o,this.lonlatProjection,this.displayProjection);n.extent=s}return n},s.prototype._callEachFeatureAtPixel=function(t,e){if(t&&t.pixel&&this._forEachFeatureAtPixel.length&&this.map)for(var o=0,n=this._forEachFeatureAtPixel.sort((function(t,e){return e[0]-t[0]}));o<n.length;o++){if(n[o][1](t.pixel,t,e))return!0}return!1},s.prototype._emitMoveEndEvents=function(t){if(this._isLoaded){var e=this.getZoom();t.zoom!==e&&this.emitter.emit("zoomend")}},s.prototype._addMapListeners=function(){var t=this,e=this.map;if(e){e.on("click",(function(e){t.onMapClick(e)})),e.on("pointermove",(function(e){t._callEachFeatureAtPixel(e,"hover")}));var o=this.getCenter(),n=this.getZoom();["movestart","moveend"].forEach((function(i){t._positionMem[i]={center:o,zoom:n},e.on(i,(function(){t._emitPositionChangeEvent(i)}))}))}},s.prototype._addViewListeners=function(){var t=this;this._olView&&(this._olView.on("change:resolution",(function(){t.emitter.emit("zoom",t)})),this._olView.on("change:center",(function(){t.emitter.emit("move",t)})))},s.prototype._setView=function(t){var e=t.center,n=t.zoom,i=t.extent,r=t.minZoom,s=t.maxZoom,a=this.map;if(a){var p=a.getView();if(void 0!==i){p.dispose();var c=new o(t);this._olView=c,this._addViewListeners(),a.setView(c)}else e&&p.setCenter(e),void 0!==n&&p.setZoom(n),void 0!==r&&p.setMinZoom(r),void 0!==s&&p.setMaxZoom(s)}},s.prototype._addUnselectCb=function(t){for(var e=0,o=this._unselectCb;e<o.length;e++){(0,o[e])()}this._unselectCb.length=0,this._unselectCb.push(t)},s.prototype._emitPositionChangeEvent=function(t){var e,o,n=this._positionMem[t];n&&(e=n.center,o=n.zoom);var i=this.getCenter(),r=this.getZoom();o!==r&&this.emitter.emit("movestart"===t?"zoomstart":"zoomend",this);e&&i?i[0]===e[0]&&i[1]===e[1]||this.emitter.emit(t,this):e!==i&&this.emitter.emit(t,this);this._positionMem[t]={center:i,zoom:r}},s.layerAdapters={IMAGE:$,TILE:Q,WMS:J,OSM:K,GEOJSON:at},s.controlAdapters={ZOOM:pt,ATTRIBUTION:lt},s}();export{ft as default}; | ||
//# sourceMappingURL=ol-map-adapter.esm-bundler.prod.js.map |
{ | ||
"name": "@nextgis/ol-map-adapter", | ||
"version": "1.11.10", | ||
"version": "1.12.0", | ||
"_priority": 16, | ||
@@ -12,7 +12,7 @@ "description": "", | ||
"dependencies": { | ||
"@nextgis/control-container": "^1.11.10", | ||
"@nextgis/dom": "^1.11.10", | ||
"@nextgis/paint": "^1.11.10", | ||
"@nextgis/properties-filter": "^1.11.10", | ||
"@nextgis/webmap": "^1.11.10", | ||
"@nextgis/control-container": "^1.12.0", | ||
"@nextgis/dom": "^1.12.0", | ||
"@nextgis/paint": "^1.12.0", | ||
"@nextgis/properties-filter": "^1.12.0", | ||
"@nextgis/webmap": "^1.12.0", | ||
"@types/events": "^3.0.0", | ||
@@ -25,3 +25,3 @@ "@types/polylabel": "^1.0.5", | ||
"devDependencies": { | ||
"@nextgis/build-tools": "^1.11.10" | ||
"@nextgis/build-tools": "^1.12.0" | ||
}, | ||
@@ -67,3 +67,3 @@ "buildOptions": { | ||
}, | ||
"gitHead": "51bd939cf50df9657bbe5ed37327d641457eb417" | ||
"gitHead": "cc0e45b49ec7cfcbd3c5ce00a5e0d6682cf8f21c" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14254902
84213
Updated@nextgis/dom@^1.12.0
Updated@nextgis/paint@^1.12.0
Updated@nextgis/webmap@^1.12.0