2017-08-31 20 views
-2

ポリラインの周囲にポリゴンを描画する際に問題があります。 私はすべてのポリラインの点の座標を持っており、このポリラインの周囲にポリゴンの座標を取得したいと思います。 私はMapBoxのマップを使用します。 アイデア私は解決策を見いださなかった。 何か、これはこのように思えます。 線の周りにポリゴンを描画するための座標を取得する必要があります。半径がポリラインのポリゴン?

enter image description here

+1

ポリライン**の周りに**ポリゴンとは何を意味しますか? Sry cantはあなたを得る。 –

+0

「インデント」ではなく「アウトデント」を意味しますか? 「インデント」は内側に移動することです。外側に移動したいと思うように聞こえます。あなたはどのように終わりを扱いますか?彼らは正方形、丸い、斜めにする必要がありますか?また、あなたがすでに持っている、または試したコードを説明するための図でもあります。 – ColGraff

+0

また、どのクラスを使用していますか:[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-native/macos/0.5.0/Content%20Primitives.html#/ c:objc(cs)MGLPolylineFeature)?あなたの最終的なポリゴンの用途は何ですか? – ColGraff

答えて

2

Mapbox GL JSマップ上の例です!それは本当にdiffucultだった:D 私はポッドのレポにgithubの上のより多くの情報を見つけることができますU

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

をポッド「SwiftTurf」

を見つけ

ターフ:) :)幸運についての最後のヒントによると!

0

ブラウザでポリラインの周りのポリゴンを描画するために探しているなら、私はturf.js.を使用することをお勧め芝生のbuffer methodは、この正確な場合にうまくいくはずです。

は、ここで私は、みんなに解決策を見つけた

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