简体   繁体   English

如何使用 mapbox gl 从现有图层获取 geojson 边界数组?

[英]How I can I get geojson boundary array from existing layer using mapbox gl?

I am using one of the custom tileset of tilling service in mapbox.我正在使用 mapbox 中的耕作服务的自定义图块集之一。 I loaded that custom tile layer in map using below code.我使用以下代码在 map 中加载了该自定义切片图层。

map.addSource('california', {
type: 'vector',
url: 'mapbox://xyz.california'
});

map.addLayer({
'id': 'terrain-data',
'type': 'fill',
'source': 'california',
'source-layer': 'california',
'layout': {},
'paint': {
'fill-color': 'black',
'fill-opacity': 0.5
}
});

Above code is filling out the inner area with black color.上面的代码用黑色填充内部区域。 But I want to fill out the outer area of that polygon.但我想填写该多边形的外部区域。 Only one way I know to do that is getting difference of whole map with that polygon by using turf.js .我知道的唯一一种方法是使用turf.js获得整个 map 与该多边形的差异。 After that I will be able to fill the outside area.之后,我将能够填充外部区域。

Now the question is how can I get the geojson ploygon array of above added layer?现在的问题是如何获得上述添加层的 geojson ploygon 数组? So I can calculate the difference.所以我可以计算差异。

You can't easily get the complete geometry of a polygon from a vector tile set, because it has already been cut up into tiles.您无法从矢量切片集中轻松获得多边形的完整几何图形,因为它已经被切割成切片。 You would have to either find a way to merge them together, or get your geometry into the front end as a complete geojson first.您必须找到一种方法将它们合并在一起,或者首先将您的几何图形作为完整的 geojson 放入前端。

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

相关问题 如何从 mapbox 中的 GeoJson 源获取所有功能? - How can I get ALL features from a GeoJson source in mapbox? 如何从源是mapbox gl js中的矢量切片的图层上的queryRenderedFeatures的结果中获取特征geojson? - How to get the feature geojson from the result of queryRenderedFeatures on a layer whose source is a vector tile in mapbox gl js? 如何从geojson为mapbox GL获取'line-dasharray'值 - How to get 'line-dasharray' value from geojson for mapbox GL 我可以使用 react-map-gl 像在(mapbox-gl-js 文档)中那样添加 GeoJSON 行吗? - Can I add a GeoJSON line like they do in the (mapbox-gl-js documentation) using react-map-gl? 如何使用Mapbox-GL在弹出窗口中显示多个geojson属性? - How do I display multiple geojson properties in a popup using Mapbox-GL? 如何在React-MapBox-GL中添加GeoJson图层 - How add a GeoJson Layer in React-MapBox-GL 如何在 Mapbox GL JS 中获取相机 position? - How can I get camera position in Mapbox GL JS? 如何从 Mapbox GL JS 中的样式层获取特征? - How get features from a style's layer in Mapbox GL JS? 从 Mapbox Studio 中上传的图块集中获取 Mapbox geojson 图层边界 - Get Mapbox geojson layer bounds from tileset uploaded in Mapbox Studio 如何从Mapbox GL JS中的geojson源获取唯一要素属性? - How to get unique feature properties from geojson source in Mapbox GL JS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM