简体   繁体   English

Mapbox重叠圆圈

[英]Mapbox Overlapping Circles

Does anyone know a way to make overlapping circles in mapbox show the same color and only have the border around the outer edge display? 有没有人知道在mapbox中制作重叠圆圈的方法显示相同的颜色,并且只有外边缘显示的边框?

I have this: 我有这个: 在此输入图像描述

And I made this in photoshop for what I want: 我在photoshop中为我想要的东西做了这个: 在此输入图像描述

While I don't think there is a way to style all the circles to show their group outline, you can achieve the effect you want by creating a union of all the circle geometries and applying your style to that. 虽然我认为没有办法对所有圆圈进行样式化以显示其组轮廓,但您可以通过创建所有圆几何的并集并将您的样式应用于此来实现所需的效果。 Unfortunately, Leaflet's L.circle class offers no way to access a circle's geometry beyond the center point, and to perform a union, you need the path of the circle itself. 不幸的是,Leaflet的L.circle无法访问中心点以外的圆的几何,并且为了执行并集,您需要圆的路径本身。 Fortunately, there is Leaflet Geodesy and its LGeo.circle class, which produces circular polygons with a given radius and number of segments. 幸运的是,有Leaflet Geodesy及其LGeo.circle类,它产生具有给定半径和段数的圆形多边形。 Once you have these polygon representations of your circles, you can use turf.union to produce the outline you want. 获得圆圈的这些多边形表示后,可以使用turf.union生成所需的轮廓。

Say you are starting with a layer of points called pointLayer (this can be a L.geoJson , L.mapbox.featureLayer , or any other class that inherits the .eachLayer method ). 假设您从一个名为pointLayer的点pointLayer (这可以是L.geoJsonL.mapbox.featureLayer ,或任何其他继承.eachLayer方法的类 )。 You can then iterate over the features, creating a circular polygon for each of them and adding it to a temporary layer group, like this: 然后,您可以迭代这些要素,为每个要素创建一个圆形多边形,并将其添加到临时图层组,如下所示:

var circleLayer = L.layerGroup();
var radius = 5000
var opts = {
  parts: 144
};
pointLayer.eachLayer(function(layer) {
  LGeo.circle(layer.getLatLng(), radius, opts).addTo(circleLayer);
});

where radius is in meters and the parts option is the number of segments you want your polygons to have. 其中radius以米为单位, parts选项是您希望多边形具有的段数。 Next, use the .getLayers method to get an array of all the layers in the temporary group, then iterate over that to create a union of all the features: 接下来,使用.getLayers方法获取临时组中所有图层的数组,然后对其进行迭代以创建所有.getLayers的并集:

var circleUnion = unify(circleLayer.getLayers()).addTo(map);

function unify(polyList) {
  for (var i = 0; i < polyList.length; ++i) {
    if (i == 0) {
      var unionTemp = polyList[i].toGeoJSON();
    } else {
      unionTemp = turf.union(unionTemp, polyList[i].toGeoJSON());
    }
  }
  return L.geoJson(unionTemp, {style: unionStyle});
}

where unionStyle is whatever style you want to apply to your newly-combined circles. 其中unionStyle是您要应用于新组合圈子的任何样式。 Here is an example fiddle showing all this with some random data: 这是一个示例小提琴,用一些随机数据显示所有这些:

http://fiddle.jshell.net/nathansnider/L2d626hn/ http://fiddle.jshell.net/nathansnider/L2d626hn/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM