我有繞多段線繪製多邊形的問題。 我有每個折線點的座標,我想獲得這條折線周圍的多邊形座標。 我使用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