From 1caa3e84cb8f362ead2705226466ed2ea6fee7ca Mon Sep 17 00:00:00 2001 From: Stefan Kuethe Date: Mon, 24 Jun 2024 10:15:09 +0200 Subject: [PATCH] Add interactive param draw_features_selected --- maplibre/ipywidget.py | 1 + maplibre/srcjs/ipywidget.js | 2 +- srcjs/ipywidget.js | 7 +++++++ srcjs/mapmethods.js | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/maplibre/ipywidget.py b/maplibre/ipywidget.py index be5d1740..9fe76210 100644 --- a/maplibre/ipywidget.py +++ b/maplibre/ipywidget.py @@ -41,6 +41,7 @@ class MapWidget(AnyWidget, Map): center = traitlets.Dict().tag(sync=True) zoom = traitlets.Float().tag(sync=True) bounds = traitlets.Dict().tag(sync=True) + draw_features_selected = traitlets.List().tag(sync=True) def __init__(self, map_options=MapOptions(), **kwargs) -> None: self.calls = [] diff --git a/maplibre/srcjs/ipywidget.js b/maplibre/srcjs/ipywidget.js index c2e052d4..353f7f8a 100644 --- a/maplibre/srcjs/ipywidget.js +++ b/maplibre/srcjs/ipywidget.js @@ -2463,7 +2463,7 @@ fragColor.g = outTexture.r / max(1.0, outTexture.a); `;var LR=2,vp={format:"rgba8unorm",mipmaps:!1,sampler:{minFilter:"linear",magFilter:"linear",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}},Gx=[0,0],kR={SUM:0,MEAN:1},BR={getPosition:{type:"accessor",value:t=>t.position},getWeight:{type:"accessor",value:1},intensity:{type:"number",min:0,value:1},radiusPixels:{type:"number",min:1,max:100,value:50},colorRange:At,threshold:{type:"number",min:0,max:1,value:.05},colorDomain:{type:"array",value:null,optional:!0},aggregation:"SUM",weightsTextureSize:{type:"number",min:128,max:2048,value:2048},debounceTimeout:{type:"number",min:0,max:1e3,value:500}},UR=["float32-renderable-webgl","texture-blend-float-webgl"],zR={data:{props:["radiusPixels"]}},Oa=class extends nt{static{this.layerName="HeatmapLayer"}static{this.defaultProps=BR}initializeState(){super.initializeAggregationLayer(zR),this.setState({colorDomain:Gx}),this._setupTextureParams(),this._setupAttributes(),this._setupResources()}shouldUpdateState({changeFlags:e}){return e.somethingChanged}updateState(e){super.updateState(e),this._updateHeatmapState(e)}_updateHeatmapState(e){let{props:r,oldProps:i}=e,s=this._getChangeFlags(e);(s.dataChanged||s.viewportChanged)&&(s.boundsChanged=this._updateBounds(s.dataChanged),this._updateTextureRenderingBounds()),s.dataChanged||s.boundsChanged?(clearTimeout(this.state.updateTimer),this.setState({isWeightMapDirty:!0})):s.viewportZoomChanged&&this._debouncedUpdateWeightmap(),r.colorRange!==i.colorRange&&this._updateColorTexture(e),this.state.isWeightMapDirty&&this._updateWeightmap(),this.setState({zoom:e.context.viewport.zoom})}renderLayers(){let{weightsTexture:e,triPositionBuffer:r,triTexCoordBuffer:i,maxWeightsTexture:s,colorTexture:n,colorDomain:o}=this.state,{updateTriggers:a,intensity:c,threshold:l,aggregation:u}=this.props,f=this.getSubLayerClass("triangle",Ia);return new f(this.getSubLayerProps({id:"triangle-layer",updateTriggers:a}),{coordinateSystem:q.DEFAULT,data:{attributes:{positions:r,texCoords:i}},vertexCount:4,maxTexture:s,colorTexture:n,aggregationMode:kR[u]||0,weightsTexture:e,intensity:c,threshold:l,colorDomain:o})}finalizeState(e){super.finalizeState(e);let{weightsTransform:r,weightsTexture:i,maxWeightTransform:s,maxWeightsTexture:n,triPositionBuffer:o,triTexCoordBuffer:a,colorTexture:c,updateTimer:l}=this.state;r?.destroy(),i?.destroy(),s?.destroy(),n?.destroy(),o?.destroy(),a?.destroy(),c?.destroy(),l&&clearTimeout(l)}_getAttributeManager(){return new nr(this.context.device,{id:this.props.id,stats:this.context.stats})}_getChangeFlags(e){let r={},{dimensions:i}=this.state;r.dataChanged=this.isAttributeChanged()&&"attribute changed"||this.isAggregationDirty(e,{compareAll:!0,dimension:i.data})&&"aggregation is dirty",r.viewportChanged=e.changeFlags.viewportChanged;let{zoom:s}=this.state;return(!e.context.viewport||e.context.viewport.zoom!==s)&&(r.viewportZoomChanged=!0),r}_createTextures(){let{textureSize:e,format:r}=this.state;this.setState({weightsTexture:this.context.device.createTexture({...vp,width:e,height:e,format:r}),maxWeightsTexture:this.context.device.createTexture({...vp,width:1,height:1,format:r})})}_setupAttributes(){this.getAttributeManager().add({positions:{size:3,type:"float64",accessor:"getPosition"},weights:{size:1,accessor:"getWeight"}}),this.setState({positionAttributeName:"positions"})}_setupTextureParams(){let{device:e}=this.context,{weightsTextureSize:r}=this.props,i=Math.min(r,e.limits.maxTextureDimension2D),s=UR.every(a=>e.features.has(a)),n=s?"rgba32float":"rgba8unorm",o=s?1:1/255;this.setState({textureSize:i,format:n,weightsScale:o}),s||U.warn(`HeatmapLayer: ${this.id} rendering to float texture not supported, falling back to low precision format`)()}_createWeightsTransform(e){let{weightsTransform:r}=this.state,{weightsTexture:i}=this.state,s=this.getAttributeManager();r?.destroy(),r=new $r(this.context.device,{id:`${this.id}-weights-transform`,bufferLayout:s.getBufferLayouts(),vertexCount:1,targetTexture:i,parameters:{depthWriteEnabled:!1,blendColorOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"},topology:"point-list",...e}),this.setState({weightsTransform:r})}_setupResources(){this._createTextures();let{device:e}=this.context,{textureSize:r,weightsTexture:i,maxWeightsTexture:s}=this.state,n=this.getShaders({vs:yp,fs:bp});this._createWeightsTransform(n);let o=this.getShaders({vs:Kx,fs:qx}),a=new $r(e,{id:`${this.id}-max-weights-transform`,bindings:{inTexture:i},uniforms:{textureSize:r},targetTexture:s,...o,vertexCount:r*r,topology:"point-list",parameters:{depthWriteEnabled:!1,blendColorOperation:"max",blendAlphaOperation:"max",blendColorSrcFactor:"one",blendColorDstFactor:"one",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one"}});this.setState({weightsTexture:i,maxWeightsTexture:s,maxWeightTransform:a,zoom:null,triPositionBuffer:e.createBuffer({byteLength:48}),triTexCoordBuffer:e.createBuffer({byteLength:48})})}updateShaders(e){this._createWeightsTransform({vs:yp,fs:bp,...e})}_updateMaxWeightValue(){let{maxWeightTransform:e}=this.state;e.run({parameters:{viewport:[0,0,1,1]},clearColor:[0,0,0,0]})}_updateBounds(e=!1){let{viewport:r}=this.context,i=[r.unproject([0,0]),r.unproject([r.width,0]),r.unproject([r.width,r.height]),r.unproject([0,r.height])].map(a=>a.map(Math.fround)),s=Wx(i),n={visibleWorldBounds:s,viewportCorners:i},o=!1;if(e||!this.state.worldBounds||!Hx(this.state.worldBounds,s)){let a=this._worldToCommonBounds(s),c=this._commonToWorldBounds(a);this.props.coordinateSystem===q.LNGLAT&&(c[1]=Math.max(c[1],-85.051129),c[3]=Math.min(c[3],85.051129),c[0]=Math.max(c[0],-360),c[2]=Math.min(c[2],360));let l=this._worldToCommonBounds(c);n.worldBounds=c,n.normalizedCommonBounds=l,o=!0}return this.setState(n),o}_updateTextureRenderingBounds(){let{triPositionBuffer:e,triTexCoordBuffer:r,normalizedCommonBounds:i,viewportCorners:s}=this.state,{viewport:n}=this.context;e.write(xp(s,3));let o=s.map(a=>Xx(n.projectPosition(a),i));r.write(xp(o,2))}_updateColorTexture(e){let{colorRange:r}=e.props,{colorTexture:i}=this.state,s=si(r,!1,Uint8Array);i&&i?.width===r.length?i.setSubImageData({data:s}):(i?.destroy(),i=this.context.device.createTexture({...vp,data:s,width:r.length,height:1})),this.setState({colorTexture:i})}_updateWeightmap(){let{radiusPixels:e,colorDomain:r,aggregation:i}=this.props,{worldBounds:s,textureSize:n,weightsScale:o}=this.state,a=this.state.weightsTransform;this.state.isWeightMapDirty=!1;let c=this._worldToCommonBounds(s,{useLayerCoordinateSystem:!0});if(r&&i==="SUM"){let{viewport:g}=this.context,_=g.distanceScales.metersPerUnit[2]*(c[2]-c[0])/n;this.state.colorDomain=r.map(y=>y*_*o)}else this.state.colorDomain=r||Gx;let u=this.getAttributeManager().getAttributes(),f=this.getModuleSettings(),h=u.positions.buffer,d={radiusPixels:e,commonBounds:c,textureWidth:n,weightsScale:o},p=u.weights.buffer;a.model.setAttributes({positions:h,weights:p}),a.model.setVertexCount(this.getNumInstances()),a.model.setUniforms(d),a.model.updateModuleSettings(f),a.run({parameters:{viewport:[0,0,n,n]},clearColor:[0,0,0,0]}),this._updateMaxWeightValue()}_debouncedUpdateWeightmap(e=!1){let{updateTimer:r}=this.state,{debounceTimeout:i}=this.props;e?(r=null,this._updateBounds(!0),this._updateTextureRenderingBounds(),this.setState({isWeightMapDirty:!0})):(this.setState({isWeightMapDirty:!1}),clearTimeout(r),r=setTimeout(this._debouncedUpdateWeightmap.bind(this,!0),i)),this.setState({updateTimer:r})}_worldToCommonBounds(e,r={}){let{useLayerCoordinateSystem:i=!1}=r,[s,n,o,a]=e,{viewport:c}=this.context,{textureSize:l}=this.state,{coordinateSystem:u}=this.props,f=i&&(u===q.LNGLAT_OFFSETS||u===q.METER_OFFSETS),h=f?c.projectPosition(this.props.coordinateOrigin):[0,0],d=l*LR/c.scale,p,g;return i&&!f?(p=this.projectPosition([s,n,0]),g=this.projectPosition([o,a,0])):(p=c.projectPosition([s,n,0]),g=c.projectPosition([o,a,0])),jx([p[0]-h[0],p[1]-h[1],g[0]-h[0],g[1]-h[1]],d,d)}_commonToWorldBounds(e){let[r,i,s,n]=e,{viewport:o}=this.context,a=o.unprojectPosition([r,i]),c=o.unprojectPosition([s,n]);return a.slice(0,2).concat(c.slice(0,2))}};import du from"https://esm.sh/@mapbox/mapbox-gl-draw@1.4.3";du.constants.classes.CONTROL_BASE="maplibregl-ctrl";du.constants.classes.CONTROL_PREFIX="maplibregl-ctrl-";du.constants.classes.CONTROL_GROUP="maplibregl-ctrl-group";var Zx=du;var VR=Object.prototype.toString,un=Array.isArray||function(e){return VR.call(e)==="[object Array]"};function Ep(t){return typeof t=="function"}function WR(t){return un(t)?"array":typeof t}function Sp(t){return t.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function Jx(t,e){return t!=null&&typeof t=="object"&&e in t}function HR(t,e){return t!=null&&typeof t!="object"&&t.hasOwnProperty&&t.hasOwnProperty(e)}var jR=RegExp.prototype.test;function XR(t,e){return jR.call(t,e)}var $R=/\S/;function YR(t){return!XR($R,t)}var KR={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function qR(t){return String(t).replace(/[&<>"'`=\/]/g,function(r){return KR[r]})}var GR=/\s*/,ZR=/\s+/,Qx=/\s*=/,JR=/\s*\}/,QR=/#|\^|\/|>|\{|&|=|!/;function e6(t,e){if(!t)return[];var r=!1,i=[],s=[],n=[],o=!1,a=!1,c="",l=0;function u(){if(o&&!a)for(;n.length;)delete s[n.pop()];else n=[];o=!1,a=!1}var f,h,d;function p(N){if(typeof N=="string"&&(N=N.split(ZR,2)),!un(N)||N.length!==2)throw new Error("Invalid tags: "+N);f=new RegExp(Sp(N[0])+"\\s*"),h=new RegExp("\\s*"+Sp(N[1])),d=new RegExp("\\s*"+Sp("}"+N[1]))}p(e||wt.tags);for(var g=new Fa(t),_,y,v,T,E,R;!g.eos();){if(_=g.pos,v=g.scanUntil(f),v)for(var M=0,F=v.length;M"?E=[y,v,_,g.pos,c,l,r]:E=[y,v,_,g.pos],l++,s.push(E),y==="#"||y==="^")i.push(E);else if(y==="/"){if(R=i.pop(),!R)throw new Error('Unopened section "'+v+'" at '+_);if(R[1]!==v)throw new Error('Unclosed section "'+R[1]+'" at '+_)}else y==="name"||y==="{"||y==="&"?a=!0:y==="="&&p(v)}if(u(),R=i.pop(),R)throw new Error('Unclosed section "'+R[1]+'" at '+g.pos);return r6(t6(s))}function t6(t){for(var e=[],r,i,s=0,n=t.length;s0?i[i.length-1][4]:e;break;default:r.push(s)}return e}function Fa(t){this.string=t,this.tail=t,this.pos=0}Fa.prototype.eos=function(){return this.tail===""};Fa.prototype.scan=function(e){var r=this.tail.match(e);if(!r||r.index!==0)return"";var i=r[0];return this.tail=this.tail.substring(i.length),this.pos+=i.length,i};Fa.prototype.scanUntil=function(e){var r=this.tail.search(e),i;switch(r){case-1:i=this.tail,this.tail="";break;case 0:i="";break;default:i=this.tail.substring(0,r),this.tail=this.tail.substring(r)}return this.pos+=i.length,i};function ln(t,e){this.view=t,this.cache={".":this.view},this.parent=e}ln.prototype.push=function(e){return new ln(e,this)};ln.prototype.lookup=function(e){var r=this.cache,i;if(r.hasOwnProperty(e))i=r[e];else{for(var s=this,n,o,a,c=!1;s;){if(e.indexOf(".")>0)for(n=s.view,o=e.split("."),a=0;n!=null&&a"?l=this.renderPartial(a,r,i,n):c==="&"?l=this.unescapedValue(a,r):c==="name"?l=this.escapedValue(a,r,n):c==="text"&&(l=this.rawValue(a)),l!==void 0&&(o+=l);return o};Ye.prototype.renderSection=function(e,r,i,s,n){var o=this,a="",c=r.lookup(e[1]);function l(h){return o.render(h,r,i,n)}if(c){if(un(c))for(var u=0,f=c.length;u0||!i)&&(n[o]=s+n[o]);return n.join(` -`)};Ye.prototype.renderPartial=function(e,r,i,s){if(i){var n=this.getConfigTags(s),o=Ep(i)?i(e[1]):i[e[1]];if(o!=null){var a=e[6],c=e[5],l=e[4],u=o;c==0&&l&&(u=this.indentPartial(o,l,a));var f=this.parse(u,n);return this.renderTokens(f,r,i,u,s)}}};Ye.prototype.unescapedValue=function(e,r){var i=r.lookup(e[1]);if(i!=null)return i};Ye.prototype.escapedValue=function(e,r,i){var s=this.getConfigEscape(i)||wt.escape,n=r.lookup(e[1]);if(n!=null)return typeof n=="number"&&s===wt.escape?String(n):s(n)};Ye.prototype.rawValue=function(e){return e[1]};Ye.prototype.getConfigTags=function(e){return un(e)?e:e&&typeof e=="object"?e.tags:void 0};Ye.prototype.getConfigEscape=function(e){if(e&&typeof e=="object"&&!un(e))return e.escape};var wt={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(t){Na.templateCache=t},get templateCache(){return Na.templateCache}},Na=new Ye;wt.clearCache=function(){return Na.clearCache()};wt.parse=function(e,r){return Na.parse(e,r)};wt.render=function(e,r,i,s){if(typeof e!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+WR(e)+'" was given as the first argument for mustache#render(template, view, partials)');return Na.render(e,r,i,s)};wt.escape=qR;wt.Scanner=Fa;wt.Context=ln;wt.Writer=Ye;var Ap=wt;function wp(t,e,r){return r!==null?Ap.render(r,t.properties):e===null?Object.keys(t.properties).map(s=>`${s}: ${t.properties[s]}`).join("
"):t.properties[e]}function Pp(t){let e={background:"white",color:"black","border-radius":"3px"};return({layer:r,object:i})=>{if(i){let s=typeof t=="object"?t[r.id]:t;return s&&{html:Ap.render(s,i),style:e}}return null}}var i6=new Vs({configuration:new ar({layers:Tp})});function ty(t,e){let[r,i]=e;console.log(r,i),t[r](...i)}function ey(t){return t.map(e=>i6.convert(Object.assign(e,{onHover:({object:r})=>console.log(r)})))}function ry(t,e){let r=null;return{addTooltip:function(i,s=null,n=null){let o={closeButton:!1,closeOnClick:!1},a=new t.Popup(o);e.on("mousemove",i,c=>{let l=c.features[0],u=wp(l,s,n);a.setLngLat(c.lngLat).setHTML(u).addTo(e)}),e.on("mouseleave",i,()=>{a.remove()})},addControl:function(i,s,n){e.addControl(new t[i](s),n)},addPopup:function(i,s=null,n=null){let o={closeButton:!1},a=new t.Popup(o);e.on("click",i,c=>{let l=c.features[0],u=wp(l,s,n);a.setLngLat(c.lngLat).setHTML(u).addTo(e)})},addMarker:function({lngLat:i,popup:s,options:n}){let o=new t.Marker(n).setLngLat(i);if(s){let a=new t.Popup(s.options).setHTML(s.text);o.setPopup(a)}o.addTo(e)},setSourceData:function(i,s){e.getSource(i).setData(s)},addDeckOverlay:function(i,s=null){let n=ey(i);r=new Ls({interleaved:!0,layers:n,getTooltip:s?Pp(s):null}),e.addControl(r)},setDeckLayers:function(i,s=null){console.log("Updating Deck.GL layers");let n=ey(i);r.setProps({layers:n,getTooltip:s?Pp(s):null})},addMapboxDraw(i,s){let n=new Zx(i);e.addControl(n,s)}}}var n6=new s6;pu.addProtocol("pmtiles",n6.tile);function o6(t){let e="pymaplibregl",r=document.createElement("div");return r.id=e,r.style.height=t.get("height"),r}function Cp(t,e){t.set("center",e.getCenter()),t.set("zoom",e.getZoom()),t.set("bounds",e.getBounds()),t.save_changes()}function a6(t,e){let r=new pu.Map(t);return r.on("mouseover",()=>{r.getCanvas().style.cursor="pointer"}),r.on("mouseout",()=>{r.getCanvas().style.cursor=""}),r.on("click",i=>{e.set("clicked",i.lngLat),e.save_changes()}),r.on("zoomend",i=>{Cp(e,r)}),r.on("moveend",i=>{Cp(e,r)}),r.once("load",()=>{r.resize(),Cp(e,r)}),r}function c6({model:t,el:e}){console.log("maplibregl",pu.version);let r=o6(t),i=Object.assign({container:r},t.get("map_options"));console.log(i);let s=a6(i,t),n=ry(pu,s),o=c=>{c.forEach(l=>{if(Object.keys(n).includes(l[0])){console.log("internal call",l);let[u,f]=l;n[u](...f);return}ty(s,l)})},a=t.get("calls");s.on("load",()=>{console.log("init calls",a),o(a),t.set("_rendered",!0),t.save_changes()}),t.on("msg:custom",c=>{console.log("custom msg",c),o(c.calls)}),e.appendChild(r)}var nQ={render:c6};export{nQ as default}; +`)};Ye.prototype.renderPartial=function(e,r,i,s){if(i){var n=this.getConfigTags(s),o=Ep(i)?i(e[1]):i[e[1]];if(o!=null){var a=e[6],c=e[5],l=e[4],u=o;c==0&&l&&(u=this.indentPartial(o,l,a));var f=this.parse(u,n);return this.renderTokens(f,r,i,u,s)}}};Ye.prototype.unescapedValue=function(e,r){var i=r.lookup(e[1]);if(i!=null)return i};Ye.prototype.escapedValue=function(e,r,i){var s=this.getConfigEscape(i)||wt.escape,n=r.lookup(e[1]);if(n!=null)return typeof n=="number"&&s===wt.escape?String(n):s(n)};Ye.prototype.rawValue=function(e){return e[1]};Ye.prototype.getConfigTags=function(e){return un(e)?e:e&&typeof e=="object"?e.tags:void 0};Ye.prototype.getConfigEscape=function(e){if(e&&typeof e=="object"&&!un(e))return e.escape};var wt={name:"mustache.js",version:"4.2.0",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,Scanner:void 0,Context:void 0,Writer:void 0,set templateCache(t){Na.templateCache=t},get templateCache(){return Na.templateCache}},Na=new Ye;wt.clearCache=function(){return Na.clearCache()};wt.parse=function(e,r){return Na.parse(e,r)};wt.render=function(e,r,i,s){if(typeof e!="string")throw new TypeError('Invalid template! Template should be a "string" but "'+WR(e)+'" was given as the first argument for mustache#render(template, view, partials)');return Na.render(e,r,i,s)};wt.escape=qR;wt.Scanner=Fa;wt.Context=ln;wt.Writer=Ye;var Ap=wt;function wp(t,e,r){return r!==null?Ap.render(r,t.properties):e===null?Object.keys(t.properties).map(s=>`${s}: ${t.properties[s]}`).join("
"):t.properties[e]}function Pp(t){let e={background:"white",color:"black","border-radius":"3px"};return({layer:r,object:i})=>{if(i){let s=typeof t=="object"?t[r.id]:t;return s&&{html:Ap.render(s,i),style:e}}return null}}var i6=new Vs({configuration:new ar({layers:Tp})});function ty(t,e){let[r,i]=e;console.log(r,i),t[r](...i)}function ey(t){return t.map(e=>i6.convert(Object.assign(e,{onHover:({object:r})=>console.log(r)})))}function ry(t,e){let r=null;return{addTooltip:function(i,s=null,n=null){let o={closeButton:!1,closeOnClick:!1},a=new t.Popup(o);e.on("mousemove",i,c=>{let l=c.features[0],u=wp(l,s,n);a.setLngLat(c.lngLat).setHTML(u).addTo(e)}),e.on("mouseleave",i,()=>{a.remove()})},addControl:function(i,s,n){e.addControl(new t[i](s),n)},addPopup:function(i,s=null,n=null){let o={closeButton:!1},a=new t.Popup(o);e.on("click",i,c=>{let l=c.features[0],u=wp(l,s,n);a.setLngLat(c.lngLat).setHTML(u).addTo(e)})},addMarker:function({lngLat:i,popup:s,options:n}){let o=new t.Marker(n).setLngLat(i);if(s){let a=new t.Popup(s.options).setHTML(s.text);o.setPopup(a)}o.addTo(e)},setSourceData:function(i,s){e.getSource(i).setData(s)},addDeckOverlay:function(i,s=null){let n=ey(i);r=new Ls({interleaved:!0,layers:n,getTooltip:s?Pp(s):null}),e.addControl(r)},setDeckLayers:function(i,s=null){console.log("Updating Deck.GL layers");let n=ey(i);r.setProps({layers:n,getTooltip:s?Pp(s):null})},addMapboxDraw(i,s){let n=new Zx(i);e.addControl(n,s)}}}var n6=new s6;pu.addProtocol("pmtiles",n6.tile);function o6(t){let e="pymaplibregl",r=document.createElement("div");return r.id=e,r.style.height=t.get("height"),r}function Cp(t,e){t.set("center",e.getCenter()),t.set("zoom",e.getZoom()),t.set("bounds",e.getBounds()),t.save_changes()}function a6(t,e){let r=new pu.Map(t);return r.on("mouseover",()=>{r.getCanvas().style.cursor="pointer"}),r.on("mouseout",()=>{r.getCanvas().style.cursor=""}),r.on("click",i=>{e.set("clicked",i.lngLat),e.save_changes()}),r.on("zoomend",i=>{Cp(e,r)}),r.on("moveend",i=>{Cp(e,r)}),r.once("load",()=>{r.resize(),Cp(e,r)}),r.on("draw.selectionchange",i=>{let s=i.features;console.log("selection changed",s),e.set("draw_features_selected",s),e.save_changes()}),r}function c6({model:t,el:e}){console.log("maplibregl",pu.version);let r=o6(t),i=Object.assign({container:r},t.get("map_options"));console.log(i);let s=a6(i,t),n=ry(pu,s),o=c=>{c.forEach(l=>{if(Object.keys(n).includes(l[0])){console.log("internal call",l);let[u,f]=l;n[u](...f);return}ty(s,l)})},a=t.get("calls");s.on("load",()=>{console.log("init calls",a),o(a),t.set("_rendered",!0),t.save_changes()}),t.on("msg:custom",c=>{console.log("custom msg",c),o(c.calls)}),e.appendChild(r)}var nQ={render:c6};export{nQ as default}; /*! Bundled license information: hammerjs/hammer.js: diff --git a/srcjs/ipywidget.js b/srcjs/ipywidget.js index 02792ef0..0e8974d4 100644 --- a/srcjs/ipywidget.js +++ b/srcjs/ipywidget.js @@ -60,6 +60,13 @@ function createMap(mapOptions, model) { updateModel(model, map); }); + map.on("draw.selectionchange", (e) => { + const features = e.features; + console.log("selection changed", features); + model.set("draw_features_selected", features); + model.save_changes(); + }); + return map; } diff --git a/srcjs/mapmethods.js b/srcjs/mapmethods.js index 722ff721..9db051a3 100644 --- a/srcjs/mapmethods.js +++ b/srcjs/mapmethods.js @@ -38,6 +38,7 @@ function _convertDeckLayer(deckLayers) { } // TODO: Duplicated code, use for Shiny and Ipywidget +// At the moment it is only used for Ipywidget // Custom map methods function getCustomMapMethods(maplibregl, map) { let deckOverlay = null;