@nextgis/ol-map-adapter
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -22,3 +22,3 @@ /// <reference types="node" /> | ||
import type { LngLatArray } from '@nextgis/utils'; | ||
import { LngLatBoundsArray } from '@nextgis/utils'; | ||
import type { LngLatBoundsArray } from '@nextgis/utils'; | ||
import type { MainLayerAdapter } from '@nextgis/webmap'; | ||
@@ -32,3 +32,3 @@ import { default as Map_2 } from 'ol/Map'; | ||
import { Paint } from '@nextgis/paint'; | ||
import { PropertiesFilter } from '@nextgis/properties-filter'; | ||
import type { PropertiesFilter } from '@nextgis/properties-filter'; | ||
import type { TileAdapterOptions } from '@nextgis/webmap'; | ||
@@ -88,3 +88,6 @@ import TileLayer from 'ol/layer/Tile'; | ||
cleanFilter(): void; | ||
/** @deprecated use {@link GeoJsonAdapter.getBounds} instead */ | ||
getExtent(): LngLatBoundsArray | undefined; | ||
getBounds(): LngLatBoundsArray | undefined; | ||
private _createLayerDefOpts; | ||
private setPaintEachLayer; | ||
@@ -91,0 +94,0 @@ private _addEventListener; |
@@ -1,2 +0,2 @@ | ||
/** Bundle of @nextgis/ol-map-adapter; version: 1.6.0; author: NextGIS */ | ||
/** Bundle of @nextgis/ol-map-adapter; version: 1.7.0; author: NextGIS */ | ||
import { EventEmitter } from 'events'; | ||
@@ -20,2 +20,4 @@ import Map from 'ol/Map'; | ||
import { getCoordinates, defined } from '@nextgis/utils'; | ||
import polylabel from 'polylabel'; | ||
import { getCenter } from 'ol/extent'; | ||
import CircleStyle from 'ol/style/Circle'; | ||
@@ -27,3 +29,2 @@ import { asArray } from 'ol/color'; | ||
import { isPaintCallback, isPaint } from '@nextgis/paint'; | ||
import polylabel from 'polylabel'; | ||
import Zoom from 'ol/control/Zoom'; | ||
@@ -327,2 +328,68 @@ import Attr from 'ol/control/Attribution'; | ||
function getCentroid(feature) { | ||
if (feature.geometry.type === 'Polygon') { | ||
return polylabel(feature.geometry.coordinates); | ||
} | ||
else if (feature.geometry.type === 'Point') { | ||
return feature.geometry.coordinates; | ||
} | ||
return getCoordinatesCentroid(getCoordinates(feature)); | ||
} | ||
// https://stackoverflow.com/a/22796806 | ||
function getCoordinatesCentroid(arr) { | ||
return arr.reduce((x, y) => { | ||
return [x[0] + y[0] / arr.length, x[1] + y[1] / arr.length]; | ||
}, [0, 0]); | ||
} | ||
function makeHtmlFromString(str) { | ||
const html = document.createElement('div'); | ||
html.innerHTML = str; | ||
return html; | ||
} | ||
function convertMapClickEvent(evt, displayProjection = 'EPSG:3857', lonlatProjection = 'EPSG:4326') { | ||
const [lng, lat] = transform(evt.coordinate, displayProjection, lonlatProjection); | ||
const latLng = { | ||
lat, | ||
lng, | ||
}; | ||
return { | ||
latLng, | ||
lngLat: [lng, lat], | ||
pixel: { left: evt.pixel[0], top: evt.pixel[1] }, | ||
source: evt, | ||
}; | ||
} | ||
function featuresSource({ feature, dataProjection, featureProjection, }) { | ||
const olFeatures = new GeoJSON().readFeatures({ | ||
type: 'FeatureCollection', | ||
features: Array.isArray(feature) ? feature : [feature], | ||
}, { | ||
dataProjection, | ||
featureProjection, | ||
}); | ||
const source = new VectorSource(); | ||
source.addFeatures(olFeatures); | ||
return source; | ||
} | ||
function getFeaturesBounds(opt) { | ||
const source = featuresSource(opt); | ||
const bounds = source.getExtent(); | ||
const extent = transformExtent(bounds, opt.featureProjection, opt.dataProjection); | ||
source.dispose(); | ||
return extent; | ||
} | ||
function getFeaturesCenter(opt) { | ||
const extent = getFeaturesBounds(opt); | ||
return getCenter(extent); | ||
} | ||
function createFeaturePositionOptions(opt) { | ||
return { | ||
getBounds: () => getFeaturesBounds(opt), | ||
getCenter: () => getFeaturesCenter(opt), | ||
}; | ||
} | ||
const typeAlias = { | ||
@@ -438,38 +505,2 @@ Point: 'point', | ||
function convertMapClickEvent(evt, displayProjection = 'EPSG:3857', lonlatProjection = 'EPSG:4326') { | ||
const [lng, lat] = transform(evt.coordinate, displayProjection, lonlatProjection); | ||
const latLng = { | ||
lat, | ||
lng, | ||
}; | ||
return { | ||
latLng, | ||
lngLat: [lng, lat], | ||
pixel: { left: evt.pixel[0], top: evt.pixel[1] }, | ||
source: evt, | ||
}; | ||
} | ||
function makeHtmlFromString(str) { | ||
const html = document.createElement('div'); | ||
html.innerHTML = str; | ||
return html; | ||
} | ||
function getCentroid(feature) { | ||
if (feature.geometry.type === 'Polygon') { | ||
return polylabel(feature.geometry.coordinates); | ||
} | ||
else if (feature.geometry.type === 'Point') { | ||
return feature.geometry.coordinates; | ||
} | ||
return getCoordinatesCentroid(getCoordinates(feature)); | ||
} | ||
// https://stackoverflow.com/a/22796806 | ||
function getCoordinatesCentroid(arr) { | ||
return arr.reduce((x, y) => { | ||
return [x[0] + y[0] / arr.length, x[1] + y[1] / arr.length]; | ||
}, [0, 0]); | ||
} | ||
class GeoJsonAdapter extends BaseAdapter { | ||
@@ -604,3 +635,3 @@ constructor(map, options) { | ||
if (typeof findFeatureCb === 'function') { | ||
const feature = this._features.filter((x) => findFeatureCb({ feature: getFeature(x) })); | ||
const feature = this._features.filter((x) => findFeatureCb(this._createLayerDefOpts(getFeature(x)))); | ||
feature.forEach((x) => { | ||
@@ -620,3 +651,3 @@ this._selectFeature(x); | ||
if (typeof findFeatureCb === 'function') { | ||
features = this._selectedFeatures.filter((x) => findFeatureCb({ feature: getFeature(x) })); | ||
features = this._selectedFeatures.filter((x) => findFeatureCb(this._createLayerDefOpts(getFeature(x)))); | ||
} | ||
@@ -633,3 +664,3 @@ else if (this.selected) { | ||
return this._features.map((x) => { | ||
return { feature: getFeature(x) }; | ||
return this._createLayerDefOpts(getFeature(x)); | ||
}); | ||
@@ -639,3 +670,3 @@ } | ||
return this._selectedFeatures.map((x) => { | ||
return { feature: getFeature(x) }; | ||
return this._createLayerDefOpts(getFeature(x)); | ||
}); | ||
@@ -648,3 +679,3 @@ } | ||
? features.filter((feature) => { | ||
return fun({ feature: getFeature(feature) }); | ||
return fun(this._createLayerDefOpts(getFeature(feature))); | ||
}) | ||
@@ -658,3 +689,3 @@ : features; | ||
return filtered.map((x) => { | ||
return { feature: getFeature(x) }; | ||
return this._createLayerDefOpts(getFeature(x)); | ||
}); | ||
@@ -665,3 +696,7 @@ } | ||
} | ||
/** @deprecated use {@link GeoJsonAdapter.getBounds} instead */ | ||
getExtent() { | ||
return this.getBounds(); | ||
} | ||
getBounds() { | ||
if (this.layer) { | ||
@@ -674,2 +709,13 @@ const source = this.layer.getSource(); | ||
} | ||
_createLayerDefOpts(feature) { | ||
return { | ||
target: this, | ||
feature, | ||
...createFeaturePositionOptions({ | ||
feature, | ||
dataProjection: this.lonlatProjection, | ||
featureProjection: this.displayProjection, | ||
}), | ||
}; | ||
} | ||
setPaintEachLayer(paint) { | ||
@@ -711,3 +757,2 @@ if (this.layer) { | ||
layer: this, | ||
feature: feature && getFeature(feature), | ||
event: convertMapClickEvent(e), | ||
@@ -719,2 +764,6 @@ source: e, | ||
if (feature) { | ||
const featureMouseOptions = { | ||
...mouseOptions, | ||
...this._createLayerDefOpts(getFeature(feature)), | ||
}; | ||
let isSelected = this._selectedFeatures.indexOf(feature) !== -1; | ||
@@ -731,3 +780,3 @@ if (this.options.selectable) { | ||
else { | ||
this._selectFeature(feature, mouseOptions.event.lngLat); | ||
this._selectFeature(feature, featureMouseOptions.event.lngLat); | ||
isSelected = true; | ||
@@ -741,3 +790,3 @@ } | ||
selected: isSelected, | ||
...mouseOptions, | ||
...featureMouseOptions, | ||
}); | ||
@@ -749,3 +798,3 @@ } | ||
if (this.options.onMouseOver) { | ||
this.options.onMouseOver(mouseOptions); | ||
this.options.onMouseOver(featureMouseOptions); | ||
} | ||
@@ -792,6 +841,12 @@ } | ||
if (this.options.onSelect) { | ||
const feature_ = getFeature(feature); | ||
this.options.onSelect({ | ||
layer: this, | ||
features: [getFeature(feature)], | ||
features: [], | ||
type, | ||
...createFeaturePositionOptions({ | ||
feature: feature_, | ||
dataProjection: this.lonlatProjection, | ||
featureProjection: this.displayProjection, | ||
}), | ||
}); | ||
@@ -835,7 +890,6 @@ } | ||
? await createPopupContent({ | ||
feature, | ||
target: this, | ||
close, | ||
onClose, | ||
type, | ||
...this._createLayerDefOpts(feature), | ||
}) | ||
@@ -896,3 +950,3 @@ : popupContent; | ||
for (const h of closeHandlers) { | ||
h({ feature: getFeature(feature) }); | ||
h(this._createLayerDefOpts(getFeature(feature))); | ||
} | ||
@@ -899,0 +953,0 @@ closeHandlers.length = 0; |
@@ -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 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}; | ||
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 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 F,Fill as b,Stroke as S}from"ol/style";import j from"ol/style/IconAnchorUnits";import A from"ol/style/Icon";import{isPaintCallback as M,isPaint as k}from"@nextgis/paint";import I from"ol/control/Zoom";import V from"ol/control/Attribution";import R from"ol/control/Control";import T from"@nextgis/control-container";function Z(t,e){return{minResolution:e.maxScale&&U(t,e.maxScale)||void 0,maxResolution:e.minScale&&U(t,e.minScale)||void 0}}function U(t,e){if(e)return function(t,e){return t/(39.37*e*90.71446714322)}(e,t.getView().getProjection().getMetersPerUnit()||1)}function D(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 B(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?B(n,s):encodeURIComponent(s)+"="+encodeURIComponent(n))}return o.join("&")}function z(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 l).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(M(e)){return K(t,e(D(t)))}if(k(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:l,strokeOpacity:c}={...e};o&&n&&"string"==typeof n&&"number"==typeof r&&(s.fill=new b({color:J(n,r)})),a&&"string"==typeof a&&"number"==typeof c&&(l||-1!==["MultiLineString","LineString"].indexOf(i))&&(s.stroke=new S({width:e.weight,color:J(a,c)})),"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:j.PIXELS,anchorYUnits:j.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 R{constructor(t){const e=new T,o=e.getContainer();super({...$,...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 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={...{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 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()}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(R&&R.prototype)).constructor=s,s.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},s}(R))}(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(R&&R.prototype)).constructor=o,o.prototype.handleRotateNorth=function(){this.getMap().getView().setRotation(0)},o}(R))}(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)}_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}}}et.layerAdapters={IMAGE:class extends H{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=B(i?i(h):p),m=t.headers,d=s+"?"+u;m?z(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,...Z(this.map,t)});return this.layer=r,r}}},TILE:class extends H{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)=>{z(t,e,n)}));return new r({source:s,opacity:t.opacity,...Z(this.map,t)})}},WMS:class extends H{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=B(o({resource:r,bbox:a,width:l,height:c})),h=t.headers,u=s+"?"+p;h?z(e,u,h):e.getImage().src=u});const i=new a(e),s=new r({source:i,opacity:t.opacity,...Z(this.map,t)});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(){this.options.name=this.name;return new r({source:new c({attributions:[p]})})}},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.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 g({source:this.vectorSource,style:e=>{const o=[],i=K(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 S({color:"#fff",width:3})};return"point"===t&&(o={...o,placement:"point",textBaseline:"bottom",offsetY:20}),new L({text:new F(o)})}(t.type||"polygon");e.getText().setText(n),o.push(e)}}return o},...Z(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(D(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(this._createLayerDefOpts(D(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(D(e))))):this.selected&&(this.selected=!1);for(const t of e)this._unselectFeature(t);this._removeAllPopup()}getLayers(){return this._features.map((t=>this._createLayerDefOpts(D(t))))}getSelected(){return this._selectedFeatures.map((t=>this._createLayerDefOpts(D(t))))}filter(t){this._filterFun=t;const e=this._features,o=t?e.filter((e=>t(this._createLayerDefOpts(D(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(D(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(D(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=D(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=[],l=()=>{r&&this._removePopup(r)},{createPopupContent:c,popupContent:p}=o,h=D(e),u=c?await c({close:l,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,c=this._createPopupElement({...o,popupContent:s,close:l});r=new y({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=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(D(t)));i.length=0,n&&this._unselectFeature(t),this._openedPopup.splice(s,1)}}}}},et.controlAdapters={ZOOM:class extends I{constructor(...t){super(...t),this.element.classList.remove("ol-control"),this.element.classList.add("webmap-ctrl-group")}},ATTRIBUTION:class extends V{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.6.0", | ||
"version": "1.7.0", | ||
"_priority": 16, | ||
@@ -12,15 +12,15 @@ "description": "", | ||
"dependencies": { | ||
"@nextgis/control-container": "^1.6.0", | ||
"@nextgis/dom": "^1.5.1", | ||
"@nextgis/paint": "^1.5.1", | ||
"@nextgis/properties-filter": "^1.5.1", | ||
"@nextgis/webmap": "^1.6.0", | ||
"@nextgis/control-container": "^1.7.0", | ||
"@nextgis/dom": "^1.7.0", | ||
"@nextgis/paint": "^1.7.0", | ||
"@nextgis/properties-filter": "^1.7.0", | ||
"@nextgis/webmap": "^1.7.0", | ||
"@types/events": "^3.0.0", | ||
"@types/polylabel": "^1.0.5", | ||
"events": "^3.3.0", | ||
"ol": "^6.6.1", | ||
"ol": "^6.7.0", | ||
"polylabel": "^1.1.0" | ||
}, | ||
"devDependencies": { | ||
"@nextgis/build-tools": "^1.5.1" | ||
"@nextgis/build-tools": "^1.7.0" | ||
}, | ||
@@ -66,3 +66,3 @@ "buildOptions": { | ||
}, | ||
"gitHead": "860acad4dc7ab9b174d58ab38c56268e0c26a3b2" | ||
"gitHead": "a3113b03e87540abf798c1151d3243a1e20c8607" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14072756
83066
Updated@nextgis/dom@^1.7.0
Updated@nextgis/paint@^1.7.0
Updated@nextgis/webmap@^1.7.0
Updatedol@^6.7.0