@eox/drawtools 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4228,7 +4228,7 @@ var Aa = class extends j {
4228
4228
  attribute: "layer-id",
4229
4229
  type: String
4230
4230
  },
4231
- featureStyles: { attribute: !1 },
4231
+ featureStyles: { type: Object },
4232
4232
  modify: {
4233
4233
  attribute: !1,
4234
4234
  state: !0
@@ -247,7 +247,7 @@
247
247
  .hidden {
248
248
  display: none;
249
249
  }
250
- `,pa=e=>{(()=>{if(e.emitDrawnFeatures(),!e.multipleFeatures)e.draw?.setActive(!1),e.selectionEvents.removeSelectionEvent(),e.currentlyDrawing=!1;else if(e.continuous)if(!e.layerId)e.drawLayer.getSource().clear(),e.drawnFeatures=[];else{let t=e.drawLayer.getSource().getFeatures().at(-1);if(e.drawLayer.getSource().clear(),!t)return;e.drawLayer.getSource().addFeature(t),e.drawnFeatures=[t]}})(),e.requestUpdate()},ma=e=>{e.drawLayer.set(`isDrawingEnabled`,!0),e.draw?.setActive(!0),e.selectionEvents.addSelectionEvent(),e.currentlyDrawing=!0,e.requestUpdate()},ha=(e,t,n)=>{if(!n||!t)return;let r=t.getLayerById(n),i=r?JSON.parse(JSON.stringify(r.get(`_jsonDefinition`))):null;if(!i){console.error(`Layer with id ${n} not found`);return}i.interactions=[{type:`select`,active:!1,options:{id:`SelectLayerHoverInteraction`,condition:`pointermove`,active:!1,style:e.featureStyles?.hover||{"fill-color":`rgba(0, 0, 0,0.0)`,"stroke-color":`#3399CC`,"stroke-width":2.5}}},{type:`select`,options:{id:`SelectLayerClickInteraction`,condition:`click`,multi:e.multipleFeatures,modify:e.allowModify,active:!1,style:e.featureStyles?.click||{"fill-color":`rgba(0, 0, 0,0.0)`,"stroke-color":`rgba(0, 0, 0,0.0)`}}}],t.addOrUpdateLayer(i),ga(t.layers,n,[i]);let a=e.draw;e.draw=t.selectInteractions.SelectLayerClickInteraction,a?.setActive(!1),t.selectInteractions.SelectLayerClickInteraction?.setActive(!1),t.selectInteractions.SelectLayerHoverInteraction?.setActive(!1)};function ga(e,t,n){let r=e.findIndex(e=>e.properties.id===t);if(r!==-1)return e.splice(r,1,...n),e;for(let r of e)if(r.type===`Group`){let e=ga(r.layers,t,n);e?.length&&(r.layers=e)}return e}var $=e=>{let t=e.getGeometry();if(!t)return;let n=``;if(t.getType()===`Polygon`||t.getType()===`MultiPolygon`){let e=Bn(t);n=e>1e6?(e/1e6).toFixed(2)+` km²`:e.toFixed(2)+` m²`}else if(t.getType()===`LineString`||t.getType()===`MultiLineString`){let e=Rn(t);n=e>1e3?(e/1e3).toFixed(2)+` km`:e.toFixed(2)+` m`}else if(t.getType()===`Circle`){let e=t.getRadius(),r=Math.PI*e**2;n=r>1e6?(r/1e6).toFixed(2)+` km²`:r.toFixed(2)+` m²`}n&&e.get(`measure`)!==n&&e.set(`measure`,n)},_a=e=>{let t=e.drawLayer.getSource();t.on(`addfeature`,e=>{let t=e.feature;t&&($(t),t.getGeometry().on(`change`,()=>$(t)))}),t.getFeatures().forEach(e=>{$(e),e.getGeometry().on(`change`,()=>$(e))})},va=(e,t)=>{let n=da(e.for),r=n.map,i=`0, 65, 112`;e.drawLayer=n.addOrUpdateLayer({zIndex:100,type:`Vector`,properties:{id:`drawLayer`,layerControlHide:!0,isDrawingEnabled:!1,multipleFeatures:t},source:{type:`Vector`},style:e.featureStyles?.layer||{"fill-color":`rgba(${i}, 0.1)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2,"circle-radius":5,"circle-fill-color":`rgba(${i}, 1)`,...e.measure&&{"text-value":[`coalesce`,[`get`,`measure`],``],"text-fill-color":`rgba(${i}, 1)`,"text-stroke-color":`white`,"text-stroke-width":3,"text-font":`bold 14px sans-serif`,"text-overflow":!0}},interactions:[{type:`draw`,options:{active:!1,id:`drawInteraction`,type:e.type,modify:e.allowModify,stopClick:!0,style:e.featureStyles?.layer||{"fill-color":`rgba(${i}, 0.1)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":1,"stroke-line-dash":[7,3],"circle-radius":5,"circle-fill-color":`rgba(${i}, 1)`,...e.measure&&{"text-value":[`coalesce`,[`get`,`measure`],``],"text-fill-color":`rgba(${i}, 1)`,"text-stroke-color":`white`,"text-stroke-width":3,"text-font":`bold 14px sans-serif`,"text-overflow":!0}}}},...e.layerId?[]:[{type:`select`,options:{id:`SelectLayerHoverInteraction`,condition:`pointermove`,style:e.featureStyles?.hover||{"fill-color":`rgba(${i}, 0.2)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2},tooltip:!1}},{type:`select`,options:{id:`SelectLayerClickInteraction`,condition:`click`,panIn:!0,style:e.featureStyles?.click||{"fill-color":`rgba(${i}, 0.2)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2}}}]]}),e.draw=n.interactions.drawInteraction,e.modify=n.interactions.drawInteraction_modify,ha(e,n,e.layerId),e.measure&&_a(e);let a=()=>e.onModifyEnd(),o=()=>pa(e);return e.modify?.on(`modifyend`,a),e.measure&&e.draw&&typeof e.draw.on==`function`&&e.draw.on(`drawstart`,e=>{let t=e.feature;$(t),t.getGeometry().on(`change`,()=>$(t))}),n.addEventListener(`addfeatures`,o),{EoxMap:n,OlMap:r,reset:e=>{!e.eoxMap||!e.drawLayer||(e.drawLayer.getSource().clear(),e.eoxMap.map.removeLayer(e.drawLayer),e.modify?.un(`modifyend`,a),e.eoxMap.removeEventListener(`addfeatures`,o),e.layerId||(e.draw=null),e.modify=null)}}},ya=e=>{e.drawnFeatures=[],e.draw?.setActive(!1),e.layerId&&e.selectionEvents.removeSelectionEvent(),e.drawLayer.getSource().clear(),e.geoJSON=null,e.emitDrawnFeatures(),e.currentlyDrawing=!1,e.requestUpdate()},ba=(e,t)=>{setTimeout(()=>{let n=e.drawLayer.getSource().getFeatures(),r=e.eoxMap.projection||`EPSG:3857`,i=e.projection,a=i?n.map(e=>{e=e.clone();let t=e.getGeometry().transform(r,i);return e.setGeometry(t),e}):n;e.setDrawnFeaturesInternal?e.setDrawnFeaturesInternal(a):e.drawnFeatures=a;let o;switch(e.format){case`geojson`:o=Ri(e.drawnFeatures);break;case`wkt`:o=oa(e.drawnFeatures);break;case`feature`:o=e.drawnFeatures;break;default:o=e.drawnFeatures;break}e.updateGeoJSON(),e.requestUpdate(),t(o)},0)},xa=e=>{let t=t=>{t?.detail.id!==`SelectLayerClickInteraction`||!t.detail.feature||(typeof t.detail.feature.getGeometry().getCoordinates!=`function`&&(t.detail.feature=li(t.detail.feature)),e.drawLayer.getSource().addFeature(t.detail.feature),e.eoxMap.dispatchEvent(new CustomEvent(`addfeatures`,{detail:t.detail})))};return{addSelectionEvent:()=>{e.layerId&&(e.eoxMap.selectInteractions.SelectLayerHoverInteraction?.setActive(!0),e.eoxMap.addEventListener(`select`,t))},removeSelectionEvent:()=>{let n=e.eoxMap.selectInteractions?.SelectLayerHoverInteraction;n&&(n.selectedFids=[],n?.setActive(!1)),e.eoxMap.removeEventListener(`select`,t)}}},Sa=(e,t,n,r)=>{if(t){if(n){r&&n!==r&&Ca(e,t),ha(e,t,n);return}if(!n&&r){Ca(e,t);return}}};function Ca(e,t){t&&(e.discardDrawing(),e.selectionEvents.removeSelectionEvent(),e.draw=t.interactions.drawInteraction,t.selectInteractions.SelectLayerClickInteraction.remove(),t.selectInteractions.SelectLayerHoverInteraction.remove())}var wa=(e,t)=>{e.key===`Escape`&&t.currentlyDrawing&&(t.draw?.setActive(!1),t.currentlyDrawing=!1,t.requestUpdate())};function Ta(e,t){let n=e.drawnFeatures.indexOf(t);n>-1&&Ea(e,n)}function Ea(e,t){if(t>-1&&t<e.drawnFeatures.length){let n=[...e.drawnFeatures];n.splice(t,1),e.drawnFeatures=n,e.emitDrawnFeatures()}}function Da(e,t){function n(e){e.preventDefault(),e.stopPropagation()}function r(e){e.srcElement.style.opacity=`0.4`}function i(e){e.srcElement.style.opacity=`1`}[`dragenter`,`dragover`,`dragleave`,`drop`].forEach(e=>{t.addEventListener(e,n,!1),[`dragenter`,`dragover`].includes(e)?t.addEventListener(e,r,!1):t.addEventListener(e,i,!1)}),t.addEventListener(`drop`,t=>ka(t,e),!1)}function Oa(e){e.preventDefault(),e.stopPropagation()}function ka(e,t){Oa(e);let n;n=`dataTransfer`in e&&e.dataTransfer?e.dataTransfer.files:e.target&&`files`in e.target?e.target.files:[],Array.from(n).forEach(e=>Aa(e,t)),e.target&&`value`in e.target&&(e.target.value=``)}function Aa(e,t){let n=new FileReader;n.readAsText(e),n.onloadend=function(){typeof n.result==`string`&&t.handleFeatureChange(n.result)}}var ja=class extends M{static get properties(){return{allowModify:{attribute:`allow-modify`,type:Boolean},for:{type:String},currentlyDrawing:{attribute:!1,state:!0,type:Boolean},continuous:{type:Boolean},draw:{attribute:!1,state:!0},drawLayer:{attribute:!1,state:!0},drawnFeatures:{attribute:!1,state:!0,type:Array},featureName:{attribute:`feature-name`,type:String},featureNameKey:{attribute:`feature-name-key`,type:String},layerId:{attribute:`layer-id`,type:String},featureStyles:{attribute:!1},modify:{attribute:!1,state:!0},multipleFeatures:{attribute:`multiple-features`,type:Boolean},measure:{type:Boolean},importFeatures:{attribute:`import-features`,type:Boolean},showEditor:{attribute:`show-editor`,type:Boolean},showList:{attribute:`show-list`,type:Boolean},projection:{type:String},noShadow:{attribute:`no-shadow`,type:Boolean},format:{type:String},type:{type:String},unstyled:{type:Boolean}}}#e;#t;#n;#r;#i=!1;#a;#o=[];#s=e=>wa(e,this);constructor(){super(),this.allowModify=!1,this.for=`eox-map`,this.currentlyDrawing=!1,this.draw=null,this.drawLayer=null,this.layerId=``,this.featureName=`Feature`,this.featureNameKey=null,this.featureStyles=null,this.modify=null,this.multipleFeatures=!1,this.measure=!1,this.importFeatures=!1,this.showEditor=!1,this.showList=!1,this.projection=`EPSG:4326`,this.type=`Polygon`,this.selectionEvents=null,this.format=`feature`,this.unstyled=!1,this.noShadow=!1}set continuous(e){this.#a=e,e&&(this.multipleFeatures=!0)}get continuous(){return this.#a}setDrawnFeaturesInternal(e){this.#i=!0,this.drawnFeatures=e,this.#i=!1}set drawnFeatures(e){let t=this.#o;if(this.#o=e,this.drawLayer&&!this.#i){if(this.drawLayer.getSource().clear(),e?.length){let t=this.eoxMap?.projection||`EPSG:3857`,n=this.projection||`EPSG:4326`,r=e;t&&n&&t!==n&&(r=e.map(e=>{e=e.clone();let r=e.getGeometry().transform(n,t);return e.setGeometry(r),e})),this.drawLayer.getSource().addFeatures(r)}this.updateGeoJSON()}this.requestUpdate(`drawnFeatures`,t)}get drawnFeatures(){return this.#o}set layerId(e){Sa(this,this.eoxMap,e,this.#r),this.#r=e}get layerId(){return this.#r}startDrawing(){ma(this)}discardDrawing(){ya(this)}removeFeature(e){Ta(this,e)}removeFeatureByIndex(e){Ea(this,e)}handleFeatureChange(e,t=!1,n=!0){this.eoxMap.parseTextToFeature(e||JSON.stringify(Ue),this.drawLayer,this.eoxMap,t,n)}handleFilesChange(e){ka(e,this)}onModifyEnd(){this.emitDrawnFeatures()}updateGeoJSON(){this.#n=JSON.stringify(this.eoxMap.parseFeature(this.drawnFeatures)||Ue,void 0,2)}emitDrawnFeatures(){ba(this,e=>{this.dispatchEvent(new CustomEvent(`drawupdate`,{detail:e}))})}createRenderRoot(){return this.noShadow?this:super.createRenderRoot()}updateLayer(){this.resetLayer&&this.resetLayer(this);let{EoxMap:e,OlMap:t,reset:n}=va(this,this.multipleFeatures);this.resetLayer=n,this.eoxMap=e,this.#t=t}firstUpdated(){this.updateLayer(),this.selectionEvents=xa(this),this.importFeatures&&Da(this,this.eoxMap),this.drawnFeatures?.length>0?this.drawnFeatures=[...this.drawnFeatures]:this.updateGeoJSON(),this.requestUpdate()}updated(e){((t=>e.has(t)&&e.get(t)!==void 0)(`for`)||e.has(`type`)&&e.get(`type`)!==this.type||e.has(`measure`)&&e.get(`measure`)!==this.measure)&&(this.updateLayer(),this.currentlyDrawing=!1)}get eoxMap(){return this.#e}set eoxMap(e){let t=this.#e;this.#e=e,this.requestUpdate(`eoxMap`,t)}connectedCallback(){if(super.connectedCallback(),document.addEventListener(`keydown`,this.#s),this.drawLayer&&this.eoxMap){let{reset:e}=va(this,this.multipleFeatures);this.resetLayer=e}}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`keydown`,this.#s),this.resetLayer?.(this)}render(){return D`
250
+ `,pa=e=>{(()=>{if(e.emitDrawnFeatures(),!e.multipleFeatures)e.draw?.setActive(!1),e.selectionEvents.removeSelectionEvent(),e.currentlyDrawing=!1;else if(e.continuous)if(!e.layerId)e.drawLayer.getSource().clear(),e.drawnFeatures=[];else{let t=e.drawLayer.getSource().getFeatures().at(-1);if(e.drawLayer.getSource().clear(),!t)return;e.drawLayer.getSource().addFeature(t),e.drawnFeatures=[t]}})(),e.requestUpdate()},ma=e=>{e.drawLayer.set(`isDrawingEnabled`,!0),e.draw?.setActive(!0),e.selectionEvents.addSelectionEvent(),e.currentlyDrawing=!0,e.requestUpdate()},ha=(e,t,n)=>{if(!n||!t)return;let r=t.getLayerById(n),i=r?JSON.parse(JSON.stringify(r.get(`_jsonDefinition`))):null;if(!i){console.error(`Layer with id ${n} not found`);return}i.interactions=[{type:`select`,active:!1,options:{id:`SelectLayerHoverInteraction`,condition:`pointermove`,active:!1,style:e.featureStyles?.hover||{"fill-color":`rgba(0, 0, 0,0.0)`,"stroke-color":`#3399CC`,"stroke-width":2.5}}},{type:`select`,options:{id:`SelectLayerClickInteraction`,condition:`click`,multi:e.multipleFeatures,modify:e.allowModify,active:!1,style:e.featureStyles?.click||{"fill-color":`rgba(0, 0, 0,0.0)`,"stroke-color":`rgba(0, 0, 0,0.0)`}}}],t.addOrUpdateLayer(i),ga(t.layers,n,[i]);let a=e.draw;e.draw=t.selectInteractions.SelectLayerClickInteraction,a?.setActive(!1),t.selectInteractions.SelectLayerClickInteraction?.setActive(!1),t.selectInteractions.SelectLayerHoverInteraction?.setActive(!1)};function ga(e,t,n){let r=e.findIndex(e=>e.properties.id===t);if(r!==-1)return e.splice(r,1,...n),e;for(let r of e)if(r.type===`Group`){let e=ga(r.layers,t,n);e?.length&&(r.layers=e)}return e}var $=e=>{let t=e.getGeometry();if(!t)return;let n=``;if(t.getType()===`Polygon`||t.getType()===`MultiPolygon`){let e=Bn(t);n=e>1e6?(e/1e6).toFixed(2)+` km²`:e.toFixed(2)+` m²`}else if(t.getType()===`LineString`||t.getType()===`MultiLineString`){let e=Rn(t);n=e>1e3?(e/1e3).toFixed(2)+` km`:e.toFixed(2)+` m`}else if(t.getType()===`Circle`){let e=t.getRadius(),r=Math.PI*e**2;n=r>1e6?(r/1e6).toFixed(2)+` km²`:r.toFixed(2)+` m²`}n&&e.get(`measure`)!==n&&e.set(`measure`,n)},_a=e=>{let t=e.drawLayer.getSource();t.on(`addfeature`,e=>{let t=e.feature;t&&($(t),t.getGeometry().on(`change`,()=>$(t)))}),t.getFeatures().forEach(e=>{$(e),e.getGeometry().on(`change`,()=>$(e))})},va=(e,t)=>{let n=da(e.for),r=n.map,i=`0, 65, 112`;e.drawLayer=n.addOrUpdateLayer({zIndex:100,type:`Vector`,properties:{id:`drawLayer`,layerControlHide:!0,isDrawingEnabled:!1,multipleFeatures:t},source:{type:`Vector`},style:e.featureStyles?.layer||{"fill-color":`rgba(${i}, 0.1)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2,"circle-radius":5,"circle-fill-color":`rgba(${i}, 1)`,...e.measure&&{"text-value":[`coalesce`,[`get`,`measure`],``],"text-fill-color":`rgba(${i}, 1)`,"text-stroke-color":`white`,"text-stroke-width":3,"text-font":`bold 14px sans-serif`,"text-overflow":!0}},interactions:[{type:`draw`,options:{active:!1,id:`drawInteraction`,type:e.type,modify:e.allowModify,stopClick:!0,style:e.featureStyles?.layer||{"fill-color":`rgba(${i}, 0.1)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":1,"stroke-line-dash":[7,3],"circle-radius":5,"circle-fill-color":`rgba(${i}, 1)`,...e.measure&&{"text-value":[`coalesce`,[`get`,`measure`],``],"text-fill-color":`rgba(${i}, 1)`,"text-stroke-color":`white`,"text-stroke-width":3,"text-font":`bold 14px sans-serif`,"text-overflow":!0}}}},...e.layerId?[]:[{type:`select`,options:{id:`SelectLayerHoverInteraction`,condition:`pointermove`,style:e.featureStyles?.hover||{"fill-color":`rgba(${i}, 0.2)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2},tooltip:!1}},{type:`select`,options:{id:`SelectLayerClickInteraction`,condition:`click`,panIn:!0,style:e.featureStyles?.click||{"fill-color":`rgba(${i}, 0.2)`,"stroke-color":`rgba(${i}, 1)`,"stroke-width":2}}}]]}),e.draw=n.interactions.drawInteraction,e.modify=n.interactions.drawInteraction_modify,ha(e,n,e.layerId),e.measure&&_a(e);let a=()=>e.onModifyEnd(),o=()=>pa(e);return e.modify?.on(`modifyend`,a),e.measure&&e.draw&&typeof e.draw.on==`function`&&e.draw.on(`drawstart`,e=>{let t=e.feature;$(t),t.getGeometry().on(`change`,()=>$(t))}),n.addEventListener(`addfeatures`,o),{EoxMap:n,OlMap:r,reset:e=>{!e.eoxMap||!e.drawLayer||(e.drawLayer.getSource().clear(),e.eoxMap.map.removeLayer(e.drawLayer),e.modify?.un(`modifyend`,a),e.eoxMap.removeEventListener(`addfeatures`,o),e.layerId||(e.draw=null),e.modify=null)}}},ya=e=>{e.drawnFeatures=[],e.draw?.setActive(!1),e.layerId&&e.selectionEvents.removeSelectionEvent(),e.drawLayer.getSource().clear(),e.geoJSON=null,e.emitDrawnFeatures(),e.currentlyDrawing=!1,e.requestUpdate()},ba=(e,t)=>{setTimeout(()=>{let n=e.drawLayer.getSource().getFeatures(),r=e.eoxMap.projection||`EPSG:3857`,i=e.projection,a=i?n.map(e=>{e=e.clone();let t=e.getGeometry().transform(r,i);return e.setGeometry(t),e}):n;e.setDrawnFeaturesInternal?e.setDrawnFeaturesInternal(a):e.drawnFeatures=a;let o;switch(e.format){case`geojson`:o=Ri(e.drawnFeatures);break;case`wkt`:o=oa(e.drawnFeatures);break;case`feature`:o=e.drawnFeatures;break;default:o=e.drawnFeatures;break}e.updateGeoJSON(),e.requestUpdate(),t(o)},0)},xa=e=>{let t=t=>{t?.detail.id!==`SelectLayerClickInteraction`||!t.detail.feature||(typeof t.detail.feature.getGeometry().getCoordinates!=`function`&&(t.detail.feature=li(t.detail.feature)),e.drawLayer.getSource().addFeature(t.detail.feature),e.eoxMap.dispatchEvent(new CustomEvent(`addfeatures`,{detail:t.detail})))};return{addSelectionEvent:()=>{e.layerId&&(e.eoxMap.selectInteractions.SelectLayerHoverInteraction?.setActive(!0),e.eoxMap.addEventListener(`select`,t))},removeSelectionEvent:()=>{let n=e.eoxMap.selectInteractions?.SelectLayerHoverInteraction;n&&(n.selectedFids=[],n?.setActive(!1)),e.eoxMap.removeEventListener(`select`,t)}}},Sa=(e,t,n,r)=>{if(t){if(n){r&&n!==r&&Ca(e,t),ha(e,t,n);return}if(!n&&r){Ca(e,t);return}}};function Ca(e,t){t&&(e.discardDrawing(),e.selectionEvents.removeSelectionEvent(),e.draw=t.interactions.drawInteraction,t.selectInteractions.SelectLayerClickInteraction.remove(),t.selectInteractions.SelectLayerHoverInteraction.remove())}var wa=(e,t)=>{e.key===`Escape`&&t.currentlyDrawing&&(t.draw?.setActive(!1),t.currentlyDrawing=!1,t.requestUpdate())};function Ta(e,t){let n=e.drawnFeatures.indexOf(t);n>-1&&Ea(e,n)}function Ea(e,t){if(t>-1&&t<e.drawnFeatures.length){let n=[...e.drawnFeatures];n.splice(t,1),e.drawnFeatures=n,e.emitDrawnFeatures()}}function Da(e,t){function n(e){e.preventDefault(),e.stopPropagation()}function r(e){e.srcElement.style.opacity=`0.4`}function i(e){e.srcElement.style.opacity=`1`}[`dragenter`,`dragover`,`dragleave`,`drop`].forEach(e=>{t.addEventListener(e,n,!1),[`dragenter`,`dragover`].includes(e)?t.addEventListener(e,r,!1):t.addEventListener(e,i,!1)}),t.addEventListener(`drop`,t=>ka(t,e),!1)}function Oa(e){e.preventDefault(),e.stopPropagation()}function ka(e,t){Oa(e);let n;n=`dataTransfer`in e&&e.dataTransfer?e.dataTransfer.files:e.target&&`files`in e.target?e.target.files:[],Array.from(n).forEach(e=>Aa(e,t)),e.target&&`value`in e.target&&(e.target.value=``)}function Aa(e,t){let n=new FileReader;n.readAsText(e),n.onloadend=function(){typeof n.result==`string`&&t.handleFeatureChange(n.result)}}var ja=class extends M{static get properties(){return{allowModify:{attribute:`allow-modify`,type:Boolean},for:{type:String},currentlyDrawing:{attribute:!1,state:!0,type:Boolean},continuous:{type:Boolean},draw:{attribute:!1,state:!0},drawLayer:{attribute:!1,state:!0},drawnFeatures:{attribute:!1,state:!0,type:Array},featureName:{attribute:`feature-name`,type:String},featureNameKey:{attribute:`feature-name-key`,type:String},layerId:{attribute:`layer-id`,type:String},featureStyles:{type:Object},modify:{attribute:!1,state:!0},multipleFeatures:{attribute:`multiple-features`,type:Boolean},measure:{type:Boolean},importFeatures:{attribute:`import-features`,type:Boolean},showEditor:{attribute:`show-editor`,type:Boolean},showList:{attribute:`show-list`,type:Boolean},projection:{type:String},noShadow:{attribute:`no-shadow`,type:Boolean},format:{type:String},type:{type:String},unstyled:{type:Boolean}}}#e;#t;#n;#r;#i=!1;#a;#o=[];#s=e=>wa(e,this);constructor(){super(),this.allowModify=!1,this.for=`eox-map`,this.currentlyDrawing=!1,this.draw=null,this.drawLayer=null,this.layerId=``,this.featureName=`Feature`,this.featureNameKey=null,this.featureStyles=null,this.modify=null,this.multipleFeatures=!1,this.measure=!1,this.importFeatures=!1,this.showEditor=!1,this.showList=!1,this.projection=`EPSG:4326`,this.type=`Polygon`,this.selectionEvents=null,this.format=`feature`,this.unstyled=!1,this.noShadow=!1}set continuous(e){this.#a=e,e&&(this.multipleFeatures=!0)}get continuous(){return this.#a}setDrawnFeaturesInternal(e){this.#i=!0,this.drawnFeatures=e,this.#i=!1}set drawnFeatures(e){let t=this.#o;if(this.#o=e,this.drawLayer&&!this.#i){if(this.drawLayer.getSource().clear(),e?.length){let t=this.eoxMap?.projection||`EPSG:3857`,n=this.projection||`EPSG:4326`,r=e;t&&n&&t!==n&&(r=e.map(e=>{e=e.clone();let r=e.getGeometry().transform(n,t);return e.setGeometry(r),e})),this.drawLayer.getSource().addFeatures(r)}this.updateGeoJSON()}this.requestUpdate(`drawnFeatures`,t)}get drawnFeatures(){return this.#o}set layerId(e){Sa(this,this.eoxMap,e,this.#r),this.#r=e}get layerId(){return this.#r}startDrawing(){ma(this)}discardDrawing(){ya(this)}removeFeature(e){Ta(this,e)}removeFeatureByIndex(e){Ea(this,e)}handleFeatureChange(e,t=!1,n=!0){this.eoxMap.parseTextToFeature(e||JSON.stringify(Ue),this.drawLayer,this.eoxMap,t,n)}handleFilesChange(e){ka(e,this)}onModifyEnd(){this.emitDrawnFeatures()}updateGeoJSON(){this.#n=JSON.stringify(this.eoxMap.parseFeature(this.drawnFeatures)||Ue,void 0,2)}emitDrawnFeatures(){ba(this,e=>{this.dispatchEvent(new CustomEvent(`drawupdate`,{detail:e}))})}createRenderRoot(){return this.noShadow?this:super.createRenderRoot()}updateLayer(){this.resetLayer&&this.resetLayer(this);let{EoxMap:e,OlMap:t,reset:n}=va(this,this.multipleFeatures);this.resetLayer=n,this.eoxMap=e,this.#t=t}firstUpdated(){this.updateLayer(),this.selectionEvents=xa(this),this.importFeatures&&Da(this,this.eoxMap),this.drawnFeatures?.length>0?this.drawnFeatures=[...this.drawnFeatures]:this.updateGeoJSON(),this.requestUpdate()}updated(e){((t=>e.has(t)&&e.get(t)!==void 0)(`for`)||e.has(`type`)&&e.get(`type`)!==this.type||e.has(`measure`)&&e.get(`measure`)!==this.measure)&&(this.updateLayer(),this.currentlyDrawing=!1)}get eoxMap(){return this.#e}set eoxMap(e){let t=this.#e;this.#e=e,this.requestUpdate(`eoxMap`,t)}connectedCallback(){if(super.connectedCallback(),document.addEventListener(`keydown`,this.#s),this.drawLayer&&this.eoxMap){let{reset:e}=va(this,this.multipleFeatures);this.resetLayer=e}}disconnectedCallback(){super.disconnectedCallback(),document.removeEventListener(`keydown`,this.#s),this.resetLayer?.(this)}render(){return D`
251
251
  <style>
252
252
  :host { display: block; }
253
253
  ${!this.unstyled&&fa}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/drawtools",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
package/src/main.js CHANGED
@@ -64,7 +64,7 @@ export class EOxDrawTools extends LitElement {
64
64
  featureName: { attribute: "feature-name", type: String },
65
65
  featureNameKey: { attribute: "feature-name-key", type: String },
66
66
  layerId: { attribute: "layer-id", type: String },
67
- featureStyles: { attribute: false },
67
+ featureStyles: { type: Object },
68
68
  modify: { attribute: false, state: true },
69
69
  multipleFeatures: { attribute: "multiple-features", type: Boolean },
70
70
  measure: { type: Boolean },
package/types/main.d.ts CHANGED
@@ -72,7 +72,7 @@ export class EOxDrawTools extends LitElement {
72
72
  type: StringConstructor;
73
73
  };
74
74
  featureStyles: {
75
- attribute: boolean;
75
+ type: ObjectConstructor;
76
76
  };
77
77
  modify: {
78
78
  attribute: boolean;