Socket
Socket
Sign inDemoInstall

@nextgis/ol-map-adapter

Package Overview
Dependencies
44
Maintainers
3
Versions
221
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.4 to 1.10.0

6

lib/index.d.ts

@@ -91,4 +91,8 @@ /// <reference types="node" />

getBounds(): LngLatBoundsArray | undefined;
setPaint(paint?: Paint | null): void;
setSelectedPaint(paint?: Paint | null): void;
updatePaint(paint: Partial<Paint>): void;
updateSelectedPaint(paint: Partial<Paint>): void;
private _createLayerDefOpts;
private setPaintEachLayer;
private _setPaintEachLayer;
private _addEventListener;

@@ -95,0 +99,0 @@ private _onFeatureAtPixel;

54

lib/ol-map-adapter.esm-bundler.js

@@ -1,2 +0,2 @@

/** Bundle of @nextgis/ol-map-adapter; version: 1.9.4; author: NextGIS */
/** Bundle of @nextgis/ol-map-adapter; version: 1.10.0; author: NextGIS */
import { EventEmitter } from 'events';

@@ -211,2 +211,16 @@ import Map from 'ol/Map';

function getUrlsWithSubdomains(url, subdomains) {
const urls = [];
const subdomains_ = typeof subdomains === 'string' ? subdomains.split('') : subdomains;
if (subdomains_ === null || subdomains_ === void 0 ? void 0 : subdomains_.length) {
subdomains_.forEach((x) => {
urls.push(url.replace(/{s}/, x));
});
}
else {
urls.push(url);
}
return urls;
}
class TileAdapter extends BaseAdapter {

@@ -220,14 +234,3 @@ constructor(map, options) {

Object.assign(this.options, options);
const urls = [];
const subdomains = typeof options.subdomains === 'string'
? options.subdomains.split('')
: options.subdomains;
if (subdomains === null || subdomains === void 0 ? void 0 : subdomains.length) {
subdomains.forEach((x) => {
urls.push(options.url.replace(/{s}/, x));
});
}
else {
urls.push(options.url);
}
const urls = getUrlsWithSubdomains(options.url, options.subdomains);
const xyzOpt = {

@@ -666,3 +669,3 @@ attributions: options.attribution ? [options.attribution] : [],

if (this.selectedPaint) {
this.setPaintEachLayer(this.selectedPaint);
this._setPaintEachLayer(this.selectedPaint);
}

@@ -726,2 +729,22 @@ }

}
setPaint(paint) {
if (paint) {
this.paint = paint;
this._setPaintEachLayer(this.paint);
}
}
setSelectedPaint(paint) {
if (paint) {
this.selectedPaint = paint;
this._setPaintEachLayer(this.selectedPaint);
}
}
updatePaint(paint) {
this.paint = { ...this.paint, ...paint };
this._setPaintEachLayer(this.paint);
}
updateSelectedPaint(paint) {
this.selectedPaint = { ...this.selectedPaint, ...paint };
this._setPaintEachLayer(this.selectedPaint);
}
_createLayerDefOpts(feature) {

@@ -738,3 +761,3 @@ return {

}
setPaintEachLayer(paint) {
_setPaintEachLayer(paint) {
if (this.layer) {

@@ -1452,2 +1475,3 @@ const source = this.layer.getSource();

// MVT: MvtAdapter,
// COG: CogAdapter,
OSM: OsmAdapter,

@@ -1454,0 +1478,0 @@ GEOJSON: GeoJsonAdapter,

@@ -1,2 +0,2 @@

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 v}from"@nextgis/dom";import{getCoordinates as P,defined as C}from"@nextgis/utils";import w from"polylabel";import{getCenter as x}from"ol/extent";import O from"ol/style/Circle";import{asArray as E}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 z(t){const e=decodeURIComponent,o=t.split("&"),i={};let s,n;for(let t,r=0,a=o.length;r<a;++r)if(t=o[r],t.length){const o=t.indexOf("=");o<0?(s=e(t),n=""):(s=e(t.slice(0,o)),n=e(t.slice(o+1))),"string"==typeof i[s]&&(i[s]=[i[s]]),Array.isArray(i[s])?i[s].push(n):i[s]=n}return i}function D(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?D(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 t in o)i.setRequestHeader(t,o[t]);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 x(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=E(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 O({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 t of this._unselectCb)t();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}=z(n),h={resource:r,bbox:a,width:c,height:l,...p},u=D(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=[],o="string"==typeof t.subdomains?t.subdomains.split(""):t.subdomains;(null==o?void 0:o.length)?o.forEach((o=>{e.push(t.url.replace(/{s}/,o))})):e.push(t.url);const i={attributions:t.attribution?[t.attribution]:[],urls:e};t.crossOrigin&&(i.crossOrigin=t.crossOrigin);const s=new h(i),n=t.headers;n&&s.setTileLoadFunction(((t,e)=>{G(t,e,n)}));return new r({source:s,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}=z(n),p=D(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 r=this.options.labelField;if(r){const i=e.get(r),s=C(i)?String(i):"";if(s){const e=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");e.getText().setText(s),o.push(e)}}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 e=t.length;e--;){const o=t[e][1];-1!==t.findIndex((t=>t[1]===o))&&t.splice(e,1)}this._forEachFeatureAtPixel.length=0;const e=this.mapClickEvents;for(let t=e.length;t--;){-1!==e.indexOf(e[t])&&e.splice(t,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 t of this._features)this._openPopup({feature:t,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 t of e)this._unselectFeature(t);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 t=0;t<i;t++)this.vectorSource.addFeature(o[t]);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)}}_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=P(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=v("div","ol-popup");if(o&&(n.style.maxWidth=o+"px"),i&&(n.style.minWidth=i+"px"),t){const t=v("a","ol-popup-closer",n);t.setAttribute("href","#"),t.addEventListener("click",s)}return v("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 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 z(t){const e=decodeURIComponent,o=t.split("&"),i={};let s,n;for(let t,r=0,a=o.length;r<a;++r)if(t=o[r],t.length){const o=t.indexOf("=");o<0?(s=e(t),n=""):(s=e(t.slice(0,o)),n=e(t.slice(o+1))),"string"==typeof i[s]&&(i[s]=[i[s]]),Array.isArray(i[s])?i[s].push(n):i[s]=n}return i}function D(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?D(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 t in o)i.setRequestHeader(t,o[t]);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 t of this._unselectCb)t();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}=z(n),h={resource:r,bbox:a,width:c,height:l,...p},u=D(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}=z(n),p=D(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 r=this.options.labelField;if(r){const i=e.get(r),s=C(i)?String(i):"";if(s){const e=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");e.getText().setText(s),o.push(e)}}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 e=t.length;e--;){const o=t[e][1];-1!==t.findIndex((t=>t[1]===o))&&t.splice(e,1)}this._forEachFeatureAtPixel.length=0;const e=this.mapClickEvents;for(let t=e.length;t--;){-1!==e.indexOf(e[t])&&e.splice(t,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 t of this._features)this._openPopup({feature:t,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 t of e)this._unselectFeature(t);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 t=0;t<i;t++)this.vectorSource.addFeature(o[t]);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};
//# sourceMappingURL=ol-map-adapter.esm-bundler.prod.js.map
{
"name": "@nextgis/ol-map-adapter",
"version": "1.9.4",
"version": "1.10.0",
"_priority": 16,

@@ -12,7 +12,7 @@ "description": "",

"dependencies": {
"@nextgis/control-container": "^1.9.4",
"@nextgis/control-container": "^1.10.0",
"@nextgis/dom": "^1.8.4",
"@nextgis/paint": "^1.9.4",
"@nextgis/properties-filter": "^1.9.4",
"@nextgis/webmap": "^1.9.4",
"@nextgis/webmap": "^1.10.0",
"@types/events": "^3.0.0",

@@ -66,3 +66,3 @@ "@types/polylabel": "^1.0.5",

},
"gitHead": "f541d1cc46b1a76d81f5e714505b338cb3df8610"
"gitHead": "5ad7c3c18f0f06098b1032b3cefe66474a8832bd"
}

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 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc