Socket
Socket
Sign inDemoInstall

@nextgis/ol-map-adapter

Package Overview
Dependencies
Maintainers
3
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nextgis/ol-map-adapter - npm Package Compare versions

Comparing version 1.5.0 to 1.5.1

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

7

lib/index.d.ts

@@ -21,5 +21,4 @@ /// <reference types="node" />

import type { LayerDefinition } from '@nextgis/webmap';
import type { LngLatArray } from '@nextgis/webmap';
import type { LngLatArray } from '@nextgis/utils';
import { LngLatBoundsArray } from '@nextgis/utils';
import type { LngLatBoundsArray as LngLatBoundsArray_2 } from '@nextgis/webmap';
import type { MainLayerAdapter } from '@nextgis/webmap';

@@ -159,4 +158,4 @@ import { default as Map_2 } from 'ol/Map';

getZoom(): number | undefined;
fitBounds(e: LngLatBoundsArray_2, options?: FitOptions): void;
getBounds(): LngLatBoundsArray_2 | undefined;
fitBounds(e: LngLatBoundsArray, options?: FitOptions): void;
getBounds(): LngLatBoundsArray | undefined;
setRotation(angle: number): void;

@@ -163,0 +162,0 @@ removeLayer(layer: Layer): void;

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

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

@@ -9,8 +9,2 @@ import Map from 'ol/Map';

import GeoJSON from 'ol/format/GeoJSON';
import CircleStyle from 'ol/style/Circle';
import { asArray } from 'ol/color';
import { Style, Text, Fill, Stroke } from 'ol/style';
import IconAnchorUnits from 'ol/style/IconAnchorUnits';
import Icon from 'ol/style/Icon';
import { isPaintCallback, isPaint } from '@nextgis/paint';
import OSM, { ATTRIBUTION } from 'ol/source/OSM';

@@ -27,2 +21,8 @@ import XYZ from 'ol/source/XYZ';

import { getCoordinates, defined } from '@nextgis/utils';
import CircleStyle from 'ol/style/Circle';
import { asArray } from 'ol/color';
import { Style, Text, Fill, Stroke } from 'ol/style';
import IconAnchorUnits from 'ol/style/IconAnchorUnits';
import Icon from 'ol/style/Icon';
import { isPaintCallback, isPaint } from '@nextgis/paint';
import polylabel from 'polylabel';

@@ -51,16 +51,2 @@ import Zoom from 'ol/control/Zoom';

const typeAlias = {
Point: 'point',
MultiPoint: 'point',
LineString: 'line',
MultiLineString: 'line',
Polygon: 'polygon',
MultiPolygon: 'polygon',
Circle: 'point',
};
const paintTypeAlias = {
polygon: 'path',
line: 'path',
point: 'circle',
};
function getFeature(feature) {

@@ -74,96 +60,2 @@ const geojson = new GeoJSON();

}
function getColor(colorStr, opacity) {
const color = asArray(colorStr);
const colorArray = color.slice();
colorArray[3] = opacity !== undefined ? opacity : 1;
return colorArray;
}
function styleFunction(feature, paint = {}) {
if (isPaintCallback(paint)) {
const f = getFeature(feature);
return styleFunction(feature, paint(f));
}
if (isPaint(paint)) {
const geometry = feature.getGeometry();
const geomType = geometry && geometry.getType();
const type = geomType || 'Point';
const style = {};
const _type = paint.type;
if (!_type) {
const ta = typeAlias[type];
paint.type =
ta === 'polygon' || ta === 'line'
? 'path'
: 'html' in paint || 'className' in paint
? 'icon'
: paintTypeAlias[ta];
}
if (paint.type === 'path' || paint.type === 'circle') {
// const geomPaint = ;
const { radius, fill, fillColor, fillOpacity, strokeColor, stroke, strokeOpacity, } = {
...paint,
};
if (fill &&
fillColor &&
typeof fillColor === 'string' &&
typeof fillOpacity === 'number') {
style.fill = new Fill({
color: getColor(fillColor, fillOpacity),
});
}
if (strokeColor &&
typeof strokeColor === 'string' &&
typeof strokeOpacity === 'number' &&
(stroke || ['MultiLineString', 'LineString'].indexOf(type) !== -1)) {
style.stroke = new Stroke({
// @ts-ignore
width: paint.weight,
color: getColor(strokeColor, strokeOpacity),
});
}
if (paint.type === 'circle' && typeof radius === 'number') {
style.image = new CircleStyle({ radius, ...style });
}
}
else if (paint.type === 'icon') {
const svg = paint.html;
if (svg) {
const iconOptions = {
src: 'data:image/svg+xml,' + escape(svg),
anchorXUnits: IconAnchorUnits.PIXELS,
anchorYUnits: IconAnchorUnits.PIXELS,
anchor: paint.iconAnchor,
imgSize: paint.iconSize,
};
style.image = new Icon(iconOptions);
}
}
return new Style(style);
}
}
function labelStyleFunction(type, opt) {
const fontSize = 12; //* (opt.ratio || 1);
let options = {
font: fontSize + 'px Calibri,sans-serif',
overflow: true,
fill: new Fill({
color: '#000',
}),
stroke: new Stroke({
color: '#fff',
width: 3,
}),
};
if (type === 'point') {
options = {
...options,
placement: 'point',
textBaseline: 'bottom',
offsetY: 20,
};
}
return new Style({
text: new Text(options),
});
}
function queryToObject(str) {

@@ -437,2 +329,112 @@ const dec = decodeURIComponent;

const typeAlias = {
Point: 'point',
MultiPoint: 'point',
LineString: 'line',
MultiLineString: 'line',
Polygon: 'polygon',
MultiPolygon: 'polygon',
Circle: 'point',
};
const paintTypeAlias = {
polygon: 'path',
line: 'path',
point: 'circle',
};
function getColor(colorStr, opacity) {
const color = asArray(colorStr);
const colorArray = color.slice();
colorArray[3] = opacity !== undefined ? opacity : 1;
return colorArray;
}
function styleFunction(feature, paint = {}) {
if (isPaintCallback(paint)) {
const f = getFeature(feature);
return styleFunction(feature, paint(f));
}
if (isPaint(paint)) {
const geometry = feature.getGeometry();
const geomType = geometry && geometry.getType();
const type = geomType || 'Point';
const style = {};
const _type = paint.type;
if (!_type) {
const ta = typeAlias[type];
const t = ta === 'polygon' || ta === 'line'
? 'path'
: 'html' in paint || 'className' in paint
? 'icon'
: paintTypeAlias[ta];
if (t) {
paint.type = t;
}
}
if (paint.type === 'path' || paint.type === 'circle') {
const { radius, fill, fillColor, fillOpacity, strokeColor, stroke, strokeOpacity, } = {
...paint,
};
if (fill &&
fillColor &&
typeof fillColor === 'string' &&
typeof fillOpacity === 'number') {
style.fill = new Fill({
color: getColor(fillColor, fillOpacity),
});
}
if (strokeColor &&
typeof strokeColor === 'string' &&
typeof strokeOpacity === 'number' &&
(stroke || ['MultiLineString', 'LineString'].indexOf(type) !== -1)) {
style.stroke = new Stroke({
// @ts-ignore
width: paint.weight,
color: getColor(strokeColor, strokeOpacity),
});
}
if (paint.type === 'circle' && typeof radius === 'number') {
style.image = new CircleStyle({ radius, ...style });
}
}
else if (paint.type === 'icon') {
const svg = paint.html;
if (svg) {
const iconOptions = {
src: 'data:image/svg+xml,' + escape(svg),
anchorXUnits: IconAnchorUnits.PIXELS,
anchorYUnits: IconAnchorUnits.PIXELS,
anchor: paint.iconAnchor,
imgSize: paint.iconSize,
};
style.image = new Icon(iconOptions);
}
}
return new Style(style);
}
}
function labelStyleFunction(type, opt) {
const fontSize = 12; //* (opt.ratio || 1);
let options = {
font: fontSize + 'px Calibri,sans-serif',
overflow: true,
fill: new Fill({
color: '#000',
}),
stroke: new Stroke({
color: '#fff',
width: 3,
}),
};
if (type === 'point') {
options = {
...options,
placement: 'point',
textBaseline: 'bottom',
offsetY: 20,
};
}
return new Style({
text: new Text(options),
});
}
function convertMapClickEvent(evt, displayProjection = 'EPSG:3857', lonlatProjection = 'EPSG:4326') {

@@ -695,5 +697,6 @@ const [lng, lat] = transform(evt.coordinate, displayProjection, lonlatProjection);

_onFeatureAtPixel(pixel, evt, type) {
const feature = this.map.getFeaturesAtPixel(pixel, {
layerFilter: (l) => l === this.layer,
})[0];
const feature = pixel &&
this.map.getFeaturesAtPixel(pixel, {
layerFilter: (l) => l === this.layer,
})[0];
const createMouseOptions = (e) => {

@@ -1188,6 +1191,7 @@ return {

_callEachFeatureAtPixel(evt, type) {
if (this._forEachFeatureAtPixel.length) {
if (evt && evt.pixel && this._forEachFeatureAtPixel.length) {
if (this.map) {
const orderedFeatures = this._forEachFeatureAtPixel.sort((a, b) => b[0] - a[0]);
// select only top feature
for (const e of this._forEachFeatureAtPixel.sort((a, b) => b[0] - a[0])) {
for (const e of orderedFeatures) {
const stop = e[1](evt.pixel, evt, type);

@@ -1232,4 +1236,8 @@ if (stop) {

if (map) {
map.on('click', (evt) => this.onMapClick(evt));
map.on('pointermove', (evt) => this._callEachFeatureAtPixel(evt, 'hover'));
map.on('click', (evt) => {
this.onMapClick(evt);
});
map.on('pointermove', (evt) => {
this._callEachFeatureAtPixel(evt, 'hover');
});
const center = this.getCenter();

@@ -1308,1 +1316,2 @@ const zoom = this.getZoom();

export { OlMapAdapter as default };
//# sourceMappingURL=ol-map-adapter.esm-bundler.js.map

@@ -1,1 +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 l from"ol/format/GeoJSON";import c from"ol/style/Circle";import{asArray as p}from"ol/color";import{Style as h,Text as u,Fill as m,Stroke as d}from"ol/style";import f from"ol/style/IconAnchorUnits";import g from"ol/style/Icon";import{isPaintCallback as y,isPaint as _}from"@nextgis/paint";import v,{ATTRIBUTION as P}from"ol/source/OSM";import C from"ol/source/XYZ";import w from"ol/layer/Image";import E from"ol/renderer/canvas/ImageLayer";import x from"ol/source/ImageWMS";import F from"ol/source/WMSServerType";import b from"ol/Overlay";import O from"ol/layer/Vector";import S from"ol/source/Vector";import{create as L}from"@nextgis/dom";import{getCoordinates as A,defined as M}from"@nextgis/utils";import k from"polylabel";import j from"ol/control/Zoom";import I from"ol/control/Attribution";import V from"ol/control/Control";import R from"@nextgis/control-container";function T(t,e){return{minResolution:e.maxScale&&Z(t,e.maxScale)||void 0,maxResolution:e.minScale&&Z(t,e.minScale)||void 0}}function Z(t,e){if(e)return function(t,e){return t/(39.37*e*90.71446714322)}(e,t.getView().getProjection().getMetersPerUnit()||1)}const U={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon",Circle:"point"},G={polygon:"path",line:"path",point:"circle"};function z(t){return(new l).writeFeatureObject(t,{dataProjection:"EPSG:4326",featureProjection:"EPSG:3857"})}function H(t,e){const o=p(t).slice();return o[3]=void 0!==e?e:1,o}function B(t,e={}){if(y(e)){return B(t,e(z(t)))}if(_(e)){const o=t.getGeometry(),i=o&&o.getType()||"Point",s={};if(!e.type){const t=U[i];e.type="polygon"===t||"line"===t?"path":"html"in e||"className"in e?"icon":G[t]}if("path"===e.type||"circle"===e.type){const{radius:t,fill:o,fillColor:n,fillOpacity:r,strokeColor:a,stroke:l,strokeOpacity:p}={...e};o&&n&&"string"==typeof n&&"number"==typeof r&&(s.fill=new m({color:H(n,r)})),a&&"string"==typeof a&&"number"==typeof p&&(l||-1!==["MultiLineString","LineString"].indexOf(i))&&(s.stroke=new d({width:e.weight,color:H(a,p)})),"circle"===e.type&&"number"==typeof t&&(s.image=new c({radius:t,...s}))}else if("icon"===e.type){const t=e.html;if(t){const o={src:"data:image/svg+xml,"+escape(t),anchorXUnits:f.PIXELS,anchorYUnits:f.PIXELS,anchor:e.iconAnchor,imgSize:e.iconSize};s.image=new g(o)}}return new h(s)}}function N(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 W(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?W(n,s):encodeURIComponent(s)+"="+encodeURIComponent(n))}return o.join("&")}function X(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 D{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 Y(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}}const q={collapsible:!1};const J={collapsible:!1};class K extends V{constructor(t){const e=new R,o=e.getContainer();super({...J,...t,element:o}),this.panelContainer=e}async addControl(t,e){const o=this.getMap(),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){this.getMap().removeControl(t)}getContainer(){return this.panelContainer.getContainer()}}class Q{constructor(){this.options={target:"map"},this.layerAdapters=Q.layerAdapters,this.controlAdapters=Q.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={...{controls:[],view:new o({center:this.options.center,zoom:this.options.zoom,minZoom:this.options.minZoom,maxZoom:this.options.maxZoom,projection:this.displayProjection}),layers:[]},target:this.options.target||"map"};this.map=new e(i),this._panelControl=new K,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()}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),l={};i&&(l.maxZoom=i),o&&(l.padding=[o,o]),n&&(l.padding=n),this._olView.fit(a,l),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)}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(V&&V.prototype)).constructor=s,s.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},s}(V))}(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(V&&V.prototype)).constructor=o,o.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},o}(V))}(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=Y(t);this.emitter.emit("preclick",e);this._callEachFeatureAtPixel(t,"click")||this._mapClickEvents.forEach((e=>{e(t)})),this.emitter.emit("click",e)}_callEachFeatureAtPixel(t,e){if(this._forEachFeatureAtPixel.length&&this.map)for(const o of this._forEachFeatureAtPixel.sort(((t,e)=>e[0]-t[0]))){if(o[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)}))})),this._olView&&(this._olView.on("change:resolution",(()=>{this.emitter.emit("zoom",this)})),this._olView.on("change:center",(()=>{this.emitter.emit("move",this)})))}}_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}}}Q.layerAdapters={IMAGE:class extends D{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(t){if(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:l,HEIGHT:c,...p}=N(n),h={resource:r,bbox:a,width:l,height:c,...p},u=W(i?i(h):p),m=t.headers,d=s+"?"+u;m?X(e,d,m):e.getImage().src=d};let s=w,n=x;if(e>1){o.ratio=e,o.serverType=F.MAPSERVER;class t extends E{renderFrame(t,o){return t.pixelRatio=e,super.renderFrame(t,o)}}class i extends w{createRenderer(){return new t(this)}}s=i;class r extends x{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)});return this.layer=r,r}}},TILE:class extends D{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(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 C(i),n=t.headers;n&&s.setTileLoadFunction(((t,e)=>{X(t,e,n)}));return new r({source:s,opacity:t.opacity,...T(this.map,t)})}},WMS:class extends D{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(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:l,HEIGHT:c}=N(n),p=W(o({resource:r,bbox:a,width:l,height:c})),h=t.headers,u=s+"?"+p;h?X(e,u,h):e.getImage().src=u});const i=new a(e),s=new r({source:i,opacity:t.opacity,...T(this.map,t)});return this.layer=s,s}},OSM:class extends D{constructor(t,e){super(t,e),this.map=t,this.options=e,this.name="OpenStreetMap"}addLayer(){this.options.name=this.name;return new r({source:new v({attributions:[P]})})}},GEOJSON:class extends D{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 S,this._features=[],this._selectedFeatures=[],this._openedPopup=[],this._forEachFeatureAtPixel=[],this._mapClickEvents=[],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;this.options=t,this.paint=t.paint,this.selectedPaint=t.selectedPaint;const o=t.data;o&&this.addData(o),this.layer=new O({source:this.vectorSource,style:e=>{const o=[],i=B(e,t.paint);i&&o.push(i);const s=this.options.labelField;if(s){const i=e.get(s),n=M(i)?String(i):"";if(n){const e=function(t,e){let o={font:"12px Calibri,sans-serif",overflow:!0,fill:new m({color:"#000"}),stroke:new d({color:"#fff",width:3})};return"point"===t&&(o={...o,placement:"point",textBaseline:"bottom",offsetY:20}),new h({text:new u(o)})}(t.type||"polygon");e.getText().setText(n),o.push(e)}}return o},...T(this.map,t)});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(z(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 l).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({feature:z(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({feature:z(e)}))):this.selected&&(this.selected=!1);for(const t of e)this._unselectFeature(t);this._removeAllPopup()}getLayers(){return this._features.map((t=>({feature:z(t)})))}getSelected(){return this._selectedFeatures.map((t=>({feature:z(t)})))}filter(t){this._filterFun=t;const e=this._features,o=t?e.filter((e=>t({feature:z(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=>({feature:z(t)})))}cleanFilter(){this.filter()}getExtent(){if(this.layer){const t=this.layer.getSource().getExtent();return s(t,this.displayProjection,this.lonlatProjection)}}setPaintEachLayer(t){if(this.layer){this.layer.getSource().getFeatures().forEach((e=>{const o=B(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=this.map.getFeaturesAtPixel(t,{layerFilter:t=>t===this.layer})[0],s=(t=>({layer:this,feature:i&&z(i),event:Y(t),source:t}))(e);if(i){let t=-1!==this._selectedFeatures.indexOf(i);return this.options.selectable&&("hover"===o&&this.options.selectOnHover||"click"===o)&&(t?this.options&&this.options.unselectOnSecondClick&&(this._unselectFeature(i),t=!1):(this._selectFeature(i,s.event.lngLat),t=!0)),"click"===o&&this.options.onClick&&this.options.onClick({selected:t,...s}),"hover"===o&&(this._mouseOver=!0,this.options.onMouseOver&&this.options.onMouseOver(s)),!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=B(t,o.selectedPaint);e&&t.setStyle(e)}this.options.popupOnSelect&&this._openPopup({coordinates:e,feature:t,options:this.options.popupOptions,type:"click"}),this.options.onSelect&&this.options.onSelect({layer:this,features:[z(t)],type:i})}_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=B(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=[],l=()=>{r&&this._removePopup(r)},{createPopupContent:c,popupContent:p}=o,h=z(e),u=c?await c({feature:h,target:this,close:l,onClose:t=>{a.push(t)},type:s}):p;if(t=t||h&&function(t){return"Polygon"===t.geometry.type?k(t.geometry.coordinates):"Point"===t.geometry.type?t.geometry.coordinates:(e=A(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,c=this._createPopupElement({...o,popupContent:s,close:l});r=new b({element:c}),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=L("div","ol-popup");if(o&&(n.style.maxWidth=o+"px"),i&&(n.style.minWidth=i+"px"),t){const t=L("a","ol-popup-closer",n);t.setAttribute("href","#"),t.addEventListener("click",s)}return L("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({feature:z(t)});i.length=0,n&&this._unselectFeature(t),this._openedPopup.splice(s,1)}}}}},Q.controlAdapters={ZOOM:class extends j{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 $=Q;export{$ 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 l from"ol/format/GeoJSON";import c,{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 g from"ol/Overlay";import y 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"ol/style/Circle";import{asArray as E}from"ol/color";import{Style as x,Text as F,Fill as b,Stroke as O}from"ol/style";import S from"ol/style/IconAnchorUnits";import L from"ol/style/Icon";import{isPaintCallback as A,isPaint as M}from"@nextgis/paint";import k from"polylabel";import j from"ol/control/Zoom";import I from"ol/control/Attribution";import V from"ol/control/Control";import R from"@nextgis/control-container";function T(t,e){return{minResolution:e.maxScale&&Z(t,e.maxScale)||void 0,maxResolution:e.minScale&&Z(t,e.minScale)||void 0}}function Z(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 l).writeFeatureObject(t,{dataProjection:"EPSG:4326",featureProjection:"EPSG:3857"})}function G(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 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 H(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 B{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)}}const N={Point:"point",MultiPoint:"point",LineString:"line",MultiLineString:"line",Polygon:"polygon",MultiPolygon:"polygon",Circle:"point"},W={polygon:"path",line:"path",point:"circle"};function X(t,e){const o=E(t).slice();return o[3]=void 0!==e?e:1,o}function D(t,e={}){if(A(e)){return D(t,e(U(t)))}if(M(e)){const o=t.getGeometry(),i=o&&o.getType()||"Point",s={};if(!e.type){const t=N[i],o="polygon"===t||"line"===t?"path":"html"in e||"className"in e?"icon":W[t];o&&(e.type=o)}if("path"===e.type||"circle"===e.type){const{radius:t,fill:o,fillColor:n,fillOpacity:r,strokeColor:a,stroke:l,strokeOpacity:c}={...e};o&&n&&"string"==typeof n&&"number"==typeof r&&(s.fill=new b({color:X(n,r)})),a&&"string"==typeof a&&"number"==typeof c&&(l||-1!==["MultiLineString","LineString"].indexOf(i))&&(s.stroke=new O({width:e.weight,color:X(a,c)})),"circle"===e.type&&"number"==typeof t&&(s.image=new w({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 L(o)}}return new x(s)}}function Y(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}}const q={collapsible:!1};const J={collapsible:!1};class K extends V{constructor(t){const e=new R,o=e.getContainer();super({...J,...t,element:o}),this.panelContainer=e}async addControl(t,e){const o=this.getMap(),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){this.getMap().removeControl(t)}getContainer(){return this.panelContainer.getContainer()}}class Q{constructor(){this.options={target:"map"},this.layerAdapters=Q.layerAdapters,this.controlAdapters=Q.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={...{controls:[],view:new o({center:this.options.center,zoom:this.options.zoom,minZoom:this.options.minZoom,maxZoom:this.options.maxZoom,projection:this.displayProjection}),layers:[]},target:this.options.target||"map"};this.map=new e(i),this._panelControl=new K,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()}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),l={};i&&(l.maxZoom=i),o&&(l.padding=[o,o]),n&&(l.padding=n),this._olView.fit(a,l),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)}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(V&&V.prototype)).constructor=s,s.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},s}(V))}(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(V&&V.prototype)).constructor=o,o.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},o}(V))}(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=Y(t);this.emitter.emit("preclick",e);this._callEachFeatureAtPixel(t,"click")||this._mapClickEvents.forEach((e=>{e(t)})),this.emitter.emit("click",e)}_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)}))})),this._olView&&(this._olView.on("change:resolution",(()=>{this.emitter.emit("zoom",this)})),this._olView.on("change:center",(()=>{this.emitter.emit("move",this)})))}}_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}}}Q.layerAdapters={IMAGE:class extends B{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(t){if(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:l,HEIGHT:c,...p}=G(n),h={resource:r,bbox:a,width:l,height:c,...p},u=z(i?i(h):p),m=t.headers,d=s+"?"+u;m?H(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)});return this.layer=r,r}}},TILE:class extends B{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(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)=>{H(t,e,n)}));return new r({source:s,opacity:t.opacity,...T(this.map,t)})}},WMS:class extends B{constructor(t,e){super(t,e),this.map=t,this.options=e}addLayer(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:l,HEIGHT:c}=G(n),p=z(o({resource:r,bbox:a,width:l,height:c})),h=t.headers,u=s+"?"+p;h?H(e,u,h):e.getImage().src=u});const i=new a(e),s=new r({source:i,opacity:t.opacity,...T(this.map,t)});return this.layer=s,s}},OSM:class extends B{constructor(t,e){super(t,e),this.map=t,this.options=e,this.name="OpenStreetMap"}addLayer(){this.options.name=this.name;return new r({source:new c({attributions:[p]})})}},GEOJSON:class extends B{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.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;this.options=t,this.paint=t.paint,this.selectedPaint=t.selectedPaint;const o=t.data;o&&this.addData(o),this.layer=new y({source:this.vectorSource,style:e=>{const o=[],i=D(e,t.paint);i&&o.push(i);const s=this.options.labelField;if(s){const i=e.get(s),n=C(i)?String(i):"";if(n){const e=function(t,e){let o={font:"12px Calibri,sans-serif",overflow:!0,fill:new b({color:"#000"}),stroke:new O({color:"#fff",width:3})};return"point"===t&&(o={...o,placement:"point",textBaseline:"bottom",offsetY:20}),new x({text:new F(o)})}(t.type||"polygon");e.getText().setText(n),o.push(e)}}return o},...T(this.map,t)});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 l).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({feature: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({feature:U(e)}))):this.selected&&(this.selected=!1);for(const t of e)this._unselectFeature(t);this._removeAllPopup()}getLayers(){return this._features.map((t=>({feature:U(t)})))}getSelected(){return this._selectedFeatures.map((t=>({feature:U(t)})))}filter(t){this._filterFun=t;const e=this._features,o=t?e.filter((e=>t({feature: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=>({feature:U(t)})))}cleanFilter(){this.filter()}getExtent(){if(this.layer){const t=this.layer.getSource().getExtent();return s(t,this.displayProjection,this.lonlatProjection)}}setPaintEachLayer(t){if(this.layer){this.layer.getSource().getFeatures().forEach((e=>{const o=D(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,feature:i&&U(i),event:Y(t),source:t}))(e);if(i){let t=-1!==this._selectedFeatures.indexOf(i);return this.options.selectable&&("hover"===o&&this.options.selectOnHover||"click"===o)&&(t?this.options&&this.options.unselectOnSecondClick&&(this._unselectFeature(i),t=!1):(this._selectFeature(i,s.event.lngLat),t=!0)),"click"===o&&this.options.onClick&&this.options.onClick({selected:t,...s}),"hover"===o&&(this._mouseOver=!0,this.options.onMouseOver&&this.options.onMouseOver(s)),!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=D(t,o.selectedPaint);e&&t.setStyle(e)}this.options.popupOnSelect&&this._openPopup({coordinates:e,feature:t,options:this.options.popupOptions,type:"click"}),this.options.onSelect&&this.options.onSelect({layer:this,features:[U(t)],type:i})}_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=D(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=[],l=()=>{r&&this._removePopup(r)},{createPopupContent:c,popupContent:p}=o,h=U(e),u=c?await c({feature:h,target:this,close:l,onClose:t=>{a.push(t)},type:s}):p;if(t=t||h&&function(t){return"Polygon"===t.geometry.type?k(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,c=this._createPopupElement({...o,popupContent:s,close:l});r=new g({element:c}),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({feature:U(t)});i.length=0,n&&this._unselectFeature(t),this._openedPopup.splice(s,1)}}}}},Q.controlAdapters={ZOOM:class extends j{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 $=Q;export{$ as default};
//# sourceMappingURL=ol-map-adapter.esm-bundler.prod.js.map
{
"name": "@nextgis/ol-map-adapter",
"version": "1.5.0",
"version": "1.5.1",
"_priority": 16,

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

"dependencies": {
"@nextgis/control-container": "^1.5.0",
"@nextgis/dom": "^1.4.0",
"@nextgis/paint": "^1.4.0",
"@nextgis/properties-filter": "^1.4.0",
"@nextgis/webmap": "^1.5.0",
"@nextgis/control-container": "^1.5.1",
"@nextgis/dom": "^1.5.1",
"@nextgis/paint": "^1.5.1",
"@nextgis/properties-filter": "^1.5.1",
"@nextgis/webmap": "^1.5.1",
"@types/events": "^3.0.0",

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

"devDependencies": {
"@nextgis/build-tools": "^1.4.0"
"@nextgis/build-tools": "^1.5.1"
},

@@ -67,3 +67,3 @@ "buildOptions": {

},
"gitHead": "7809e0f7dfa28a9273f52ed85649e0c9d38e7375"
"gitHead": "2362b8157329a800f7e1527a19e3b30aeaa6c4b2"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc