传单:如何仅在多边形内显示图层 [英] Leaflet: How can i show layer only inside a polygon

查看:121
本文介绍了传单:如何仅在多边形内显示图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上我正在使用Leaflet,但是当我添加leaftlet.webglheatmap图层时,它将使用整个屏幕.

我只需要显示geoJson多边形内的数据(颜色),而不是所有地图:

我与webglheatmap开发人员进行了交谈,但他告诉我要使用webgl创建新形状,但这不是当前选择

我也尝试过Leaflet.Snogylop,但是它只是在我的地图外部绘制了一个形状,并且使用了一些颜色却没有效果.

解决方案

如果我正确地解释了您的问题,则只需要在Polygon中显示地图图层即可.不幸的是,传单并不简单.一年前,我偶然发现了同样的问题,最终使用了

逆多面体

用法在传单之后将lib包含在您的页面中,然后只需将 invert 选项定义为true

即可使用它

  L.geoJson(data,{反转:真}).addTo(map); 

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.

解决方案

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);

这篇关于传单:如何仅在多边形内显示图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆