Leaflet: How can i show layer only inside a polygon

假如想象 提交于 2021-01-20 09:24:07

问题


Actually i'm working with Leaflet but when i add a leaftlet.webglheatmap layer it uses the entire screen...

I need to show only the data (colour) inside a geoJson polygon, instead of all the map:

I talked with the webglheatmap developer but he told me to create a new shape with webgl, but that is not an option in this minute

I tried Leaflet.Snogylop too, but it just draw a shape outside my map and with some colours it doesnt do the effect.

Thanks in advice


回答1:


If I am interpreting your question correctly, you need to show map layer only within Polygon. Unfortunately it's not straight forward with leaflet. I stumbled with same issue an year ago and I ended up using Leaflet Snogylop Plugin. Simply put by the author:

Leaflet.snogylop is a Leaflet plugin that inverts polygons.

Basically you define a polygon where you want to show the map, this plugin will invert that polygon so that rest of map is covered while your desired area is transparent.

Inverted Polygon

Inversted MultiPolygon

Usage Include the lib in your page after leaflet, then use it by simply defining the invert option to true

L.geoJson(data, {
    invert: true
}).addTo(map);


来源:https://stackoverflow.com/questions/65676884/leaflet-how-can-i-show-layer-only-inside-a-polygon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!