UNPKG

terra-draw-mapbox-gl-adapter

Version:
3 lines (2 loc) 5.96 kB
import{TerraDrawExtend as e}from"terra-draw";function t(e,n){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},t(e,n)}var n=/*#__PURE__*/function(e){function n(t){var n;return(n=e.call(this,t)||this)._renderBeforeLayerId=void 0,n._initialDragPan=void 0,n._initialDragRotate=void 0,n._nextRender=void 0,n._map=void 0,n._container=void 0,n.changedIds={deletion:!1,points:!1,linestrings:!1,polygons:!1,styling:!1},n._map=t.map,n._container=n._map.getContainer(),n._initialDragRotate=n._map.dragRotate.isEnabled(),n._initialDragPan=n._map.dragPan.isEnabled(),n._renderBeforeLayerId=t.renderBelowLayerId,n}var i,o;o=e,(i=n).prototype=Object.create(o.prototype),i.prototype.constructor=i,t(i,o);var r=n.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 n="td-"+e.toLowerCase();return this._addGeoJSONSource(n,t),this._addLayer(n,e),n},r._setGeoJSONLayerData=function(e,t){var n="td-"+e.toLowerCase();return this._map.getSource(n).setData({type:"FeatureCollection",features:t}),n},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 n=this._map.project({lng:e,lat:t});return{x:n.x,y:n.y}},r.unproject=function(e,t){var n=this._map.unproject({x:e,y:t});return{lng:n.lng,lat:n.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 n=this;this.updateChangedIds(e),this._nextRender&&cancelAnimationFrame(this._nextRender),this._nextRender=requestAnimationFrame(function(){for(var i=[].concat(e.created,e.updated,e.unchanged),o=[],r=[],a=[],l=0;l<i.length;l++){var d=i[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=n.changedIds.deletion||n.changedIds.styling,g=c||n.changedIds.linestrings,y=c||n.changedIds.polygons;(c||n.changedIds.points)&&n._setGeoJSONLayerData("Point",o),g&&n._setGeoJSONLayerData("LineString",r),y&&n._setGeoJSONLayerData("Polygon",a),n.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._map.removeLayer("td-point"),this._map.removeSource("td-point"),this._map.removeLayer("td-linestring"),this._map.removeSource("td-linestring"),this._map.removeLayer("td-polygon"),this._map.removeLayer("td-polygon-outline"),this._map.removeSource("td-polygon")},r.register=function(t){var n;e.prototype.register.call(this,t);var i=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(i+"-outline",o),this._map.moveLayer(i,o)),null!=(n=this._currentModeCallbacks)&&n.onReady&&this._currentModeCallbacks.onReady()},n}(e.TerraDrawBaseAdapter);export{n as TerraDrawMapboxGLAdapter}; //# sourceMappingURL=terra-draw-mapbox-gl-adapter.module.js.map