UNPKG

terra-draw-maplibre-gl-adapter

Version:
3 lines (2 loc) 6.24 kB
import{TerraDrawExtend as e}from"terra-draw";function t(e,i){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},t(e,i)}var i=/*#__PURE__*/function(e){function i(t){var i;return(i=e.call(this,t)||this)._renderBeforeLayerId=void 0,i._prefixId=void 0,i._initialDragPan=void 0,i._initialDragRotate=void 0,i._nextRender=void 0,i._map=void 0,i._container=void 0,i.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},i._map=t.map,i._container=i._map.getContainer(),i._initialDragRotate=i._map.dragRotate.isEnabled(),i._initialDragPan=i._map.dragPan.isEnabled(),i._renderBeforeLayerId=t.renderBelowLayerId,i._prefixId=t.prefixId||"td",i}var n,o;o=e,(n=i).prototype=Object.create(o.prototype),n.prototype.constructor=n,t(n,o);var r=i.prototype;return r._addGeoJSONSource=function(e,t){this._map.addSource(e,{type:"geojson",data:{type:"FeatureCollection",features:t},tolerance:0})},r._addFillLayer=function(e){return this._map.addLayer({id:e,source:e,type:"fill",layout:{"fill-sort-key":["get","zIndex"]},paint:{"fill-color":["get","polygonFillColor"],"fill-opacity":["get","polygonFillOpacity"]}})},r._addFillOutlineLayer=function(e){return this._map.addLayer({id:e+"-outline",source:e,type:"line",layout:{"line-sort-key":["get","zIndex"]},paint:{"line-width":["get","polygonOutlineWidth"],"line-color":["get","polygonOutlineColor"]}})},r._addLineLayer=function(e){return this._map.addLayer({id:e,source:e,type:"line",layout:{"line-sort-key":["get","zIndex"]},paint:{"line-width":["get","lineStringWidth"],"line-color":["get","lineStringColor"]}})},r._addPointLayer=function(e){return this._map.addLayer({id:e,source:e,type:"circle",layout:{"circle-sort-key":["get","zIndex"]},paint:{"circle-stroke-color":["get","pointOutlineColor"],"circle-stroke-width":["get","pointOutlineWidth"],"circle-radius":["get","pointWidth"],"circle-color":["get","pointColor"]}})},r._addLayer=function(e,t){"Point"===t&&this._addPointLayer(e),"LineString"===t&&this._addLineLayer(e),"Polygon"===t&&(this._addFillLayer(e),this._addFillOutlineLayer(e))},r._addGeoJSONLayer=function(e,t){var i=this._prefixId+"-"+e.toLowerCase();return this._addGeoJSONSource(i,t),this._addLayer(i,e),i},r._setGeoJSONLayerData=function(e,t){var i=this._prefixId+"-"+e.toLowerCase();return this._map.getSource(i).setData({type:"FeatureCollection",features:t}),i},r.updateChangedIds=function(e){var t=this;[].concat(e.updated,e.created).forEach(function(e){"Point"===e.geometry.type?t.changedIds.points=!0:"LineString"===e.geometry.type?t.changedIds.linestrings=!0:"Polygon"===e.geometry.type&&(t.changedIds.polygons=!0)}),e.deletedIds.length>0&&(this.changedIds.deletion=!0),0===e.created.length&&0===e.updated.length&&0===e.deletedIds.length&&(this.changedIds.styling=!0)},r.getLngLatFromEvent=function(e){var t=this._container.getBoundingClientRect();return this.unproject(e.clientX-t.left,e.clientY-t.top)},r.getMapEventElement=function(){return this._map.getCanvas()},r.setDraggability=function(e){e?(this._initialDragRotate&&this._map.dragRotate.enable(),this._initialDragPan&&this._map.dragPan.enable()):(this._initialDragRotate&&this._map.dragRotate.disable(),this._initialDragPan&&this._map.dragPan.disable())},r.project=function(e,t){var i=this._map.project({lng:e,lat:t});return{x:i.x,y:i.y}},r.unproject=function(e,t){var i=this._map.unproject({x:e,y:t});return{lng:i.lng,lat:i.lat}},r.setCursor=function(e){var t=this._map.getCanvas();"unset"===e?t.style.removeProperty("cursor"):t.style.cursor=e},r.setDoubleClickToZoom=function(e){e?this._map.doubleClickZoom.enable():this._map.doubleClickZoom.disable()},r.render=function(e,t){var i=this;this.updateChangedIds(e),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(function(){if(i._currentModeCallbacks){for(var n=[].concat(e.created,e.updated,e.unchanged),o=[],r=[],a=[],l=0;l<n.length;l++){var d=n[l],s=d.properties,p=t[s.mode](d);"Point"===d.geometry.type?(s.pointColor=p.pointColor,s.pointOutlineColor=p.pointOutlineColor,s.pointOutlineWidth=p.pointOutlineWidth,s.pointWidth=p.pointWidth,s.zIndex=p.zIndex,o.push(d)):"LineString"===d.geometry.type?(s.lineStringColor=p.lineStringColor,s.lineStringWidth=p.lineStringWidth,r.push(d)):"Polygon"===d.geometry.type&&(s.polygonFillColor=p.polygonFillColor,s.polygonFillOpacity=p.polygonFillOpacity,s.polygonOutlineColor=p.polygonOutlineColor,s.polygonOutlineWidth=p.polygonOutlineWidth,a.push(d))}var c=i.changedIds.deletion||i.changedIds.styling,g=c||i.changedIds.linestrings,y=c||i.changedIds.polygons;(c||i.changedIds.points)&&i._setGeoJSONLayerData("Point",o),g&&i._setGeoJSONLayerData("LineString",r),y&&i._setGeoJSONLayerData("Polygon",a),i.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1}}})},r.clear=function(){this._currentModeCallbacks&&(this._currentModeCallbacks.onClear(),this._nextRender&&(cancelAnimationFrame(this._nextRender),this._nextRender=void 0),this._setGeoJSONLayerData("Point",[]),this._setGeoJSONLayerData("LineString",[]),this._setGeoJSONLayerData("Polygon",[]))},r.getCoordinatePrecision=function(){return e.prototype.getCoordinatePrecision.call(this)},r.unregister=function(){e.prototype.unregister.call(this),this.changedIds={points:!1,linestrings:!1,polygons:!1,deletion:!1,styling:!1},this._map.removeLayer(this._prefixId+"-point"),this._map.removeSource(this._prefixId+"-point"),this._map.removeLayer(this._prefixId+"-linestring"),this._map.removeSource(this._prefixId+"-linestring"),this._map.removeLayer(this._prefixId+"-polygon"),this._map.removeLayer(this._prefixId+"-polygon-outline"),this._map.removeSource(this._prefixId+"-polygon")},r.register=function(t){var i;e.prototype.register.call(this,t);var n=this._addGeoJSONLayer("Polygon",[]),o=this._addGeoJSONLayer("LineString",[]),r=this._addGeoJSONLayer("Point",[]);this._renderBeforeLayerId&&(this._map.moveLayer(r,this._renderBeforeLayerId),this._map.moveLayer(o,r),this._map.moveLayer(n+"-outline",o),this._map.moveLayer(n,o)),null!=(i=this._currentModeCallbacks)&&i.onReady&&this._currentModeCallbacks.onReady()},i}(e.TerraDrawBaseAdapter);export{i as TerraDrawMapLibreGLAdapter}; //# sourceMappingURL=terra-draw-maplibre-gl-adapter.module.js.map