我有绕多段线绘制多边形的问题。 我有每个折线点的坐标,我想获得这条折线周围的多边形坐标。 我使用MapBox的地图。 任何想法?我没有找到解决方案。 东西,看起来像这样。 我需要获取围绕线绘制多边形的坐标。多边形与半径的折线?
-2
A
回答
2
我找到了解决方案,对球员的榜样!那真是diffucult:d 根据有关草坪:)
我发现荚“SwiftTurf”
var coordsPointer = UnsafeMutablePointer<CLLocationCoordinate2D>.allocate(capacity: Int(polyline.pointCount))
polyline.getCoordinates(coordsPointer, range: NSMakeRange(0, Int(polyline.pointCount)))
// save coords
var lineCoords: [CLLocationCoordinate2D] = []
for i in 0..<polyline.pointCount {
lineCoords.append(coordsPointer[Int(i)])
}
let lineString:LineString = LineString(geometry: lineCoords)
let bufferLineString = SwiftTurf.buffer(lineString, distance: width, units: .Meters)
let outer = bufferLineString!.geometry![0]
let interiors = bufferLineString?.geometry![1..<bufferLineString!.geometry.count].map({ coords in
return MGLPolygon(coordinates: coords, count: UInt(coords.count))
})
// This polygon is solution
self.currentBufferPolygon = MGLPolygon(coordinates: outer, count: UInt(outer.count), interiorPolygons: interiors)
mapView.addAnnotation(self.currentBufferPolygon!)
U可以在github的详细信息在群的回购:)祝你好运最后一抹!
0
如果你正在寻找周围绘制在浏览器中折线多边形,我建议使用turf.js.草皮的buffer
method应该适用于这个确切的情况。
这里有一个Mapbox GL JS地图
var line = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-122.40447521209718,
37.79367718768535
],
[-122.40803718566895,
37.79171022624846
],
[-122.40769386291502,
37.79096412372944
],
[-122.40662097930908,
37.789641468930114
],
[-122.40941047668457,
37.789675383451495
],
[-122.40992546081543,
37.78875968591083
],
[-122.40962505340575,
37.78791180770003
]
]
}
};
mapboxgl.accessToken = 'pk.eyJ1IjoibWFwc2FtIiwiYSI6ImNqNzI4ODR4djBkZmczMnJzZjg3eXZhcDgifQ.5xM2OR_RvuO6YvirBVeiOg';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
zoom: 15,
center: [-122.4067, 37.7899]
});
map.on('load', function() {
map.addLayer({
"id": "route",
"type": "line",
"source": {
"type": "geojson",
"data": line
}
});
var polygon = turf.buffer(line, 50, 'meters');
map.addLayer({
"id": "poly",
"type": "fill",
"source": {
"type": "geojson",
"data": polygon
},
"layout": {},
"paint": {
"fill-color": '#d9d838',
"fill-opacity": 0.3
}
});
});
body {
margin: 0;
padding: 0;
}
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css' rel='stylesheet' />
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script>
</head>
<body>
<div id='map'></div>
</body>
</html>
+0
哇,它看起来像一个解决方案,但我如何适应它的Swift? – Denis
相关问题
- 1. 如何与周围的折线半径画多边形IOS迅速
- 2. 创建一定半径的多边形
- 3. 带边框半径的多线圆角
- 4. WPF -HitTest半径折线/路径
- 5. 在多个其他多边形的某个半径内查找多边形
- 6. QGIS折线多边形错误
- 7. 问题与边界半径
- 8. D3js - 圆形位置与圆弧或曲线路径的半径
- 9. 找到点与多边形之间最长的“直线”路径
- 10. 用不同半径的圆覆盖多边形
- 11. CSS如何使内部的div边框半径与外层div边框半径
- 12. CSS边框RADIUS,这是使用正确的样式?边界半径? -webkit-边界半径? -moz-边界半径?
- 13. 带曲线边缘的剪辑路径多边形
- 14. IE8边界半径
- 15. CSS边界半径
- 16. 边界半径Nativescript
- 17. CSS3边框半径
- 18. CSS - 边框半径
- 19. ie9边界半径
- 20. 边界半径CSS
- 21. CSS边界半径
- 22. 从中心和半径创建一个SqlGeography多边形圈
- 23. 谷歌地图自动完成:矩形边界与半径
- 24. 计算多边形内的折线的点
- 25. 从具有共线边的多边形中提取多边形
- 26. D3 js可折叠图增加弧线曲线半径
- 27. 六边形+边框半径+背景图像,我该怎么做?
- 28. Google Map Api v3折线和多边形分解
- 29. 围绕折线创建一个多边形,如缓冲区
- 30. CSS3 - 如何在矩形上创建圆形边框半径?
你是什么意思**多边形绕多段线** ?? Sry不能帮你。 –
你的意思是“超越”而不是“缩进”吗? “缩进”是向内移动,你听起来像你想向外移动。你如何处理目标?他们应该是正方形,圆形,有角度吗?也许还有一张图来说明你已经或已经尝试过的一些代码。 – ColGraff
另外,您使用的是哪些类:[UIBezierPath](https://developer.apple.com/documentation/uikit/uibezierpath),[GMSPolyline](https://developers.google.com/maps/documentation/ios- sdk/reference/interface_g_m_s_polyline),[GMSPolygon](https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_polygon),[MGLPolylineFeature](https://mapbox.github.io/mapbox- GL-天然的/的MacOS/0.5.0 /含量%20Primitives.html#/ C:objc(CS)MGLPolylineFeature)?多边形的最终用途是什么? – ColGraff