2017-12-04 1 views
0

내 뷰의 오른쪽 확대/축소와 모든 뷰를 맞출 수있는 방법을 찾고 있는데,이 뷰는 주석과 사용자 위치를 연결하는 경로를 나타내는 하나의 주석과 userlocation 및 전체 폴리 라인입니다.Mapbox iOS SDK의지도보기에 맞게 폴리 라인과 사용자 위치를 포함한 모든 주석을 입력 하시겠습니까?

나는지도는지도보기로드마다 부르는 아래에이 코드가 있습니다

func mapViewDidFinishLoadingMap(_ mapView: MGLMapView) { 
     if let location = mapView.userLocation?.location?.coordinate, let annotations = mapView.annotations { 
       let coordinate = annotations.first?.coordinate 
       mapView.setVisibleCoordinateBounds(MGLCoordinateBounds(sw: location, ne: coordinate!), edgePadding: UIEdgeInsetsMake(100, 50, 100, 200), animated: true) 
     } 
    } 

이 노선은 거의 선형 좌표 잘 작동하지만이 경로는 좀 더 복잡하고 긴 경우 도움이 안돼. 줌 레벨이 다각형의 무게 중심을 잡아 Truf's centroid 기능을 사용하여 알고있는 경우

답변

0

, 다음과 같이 MGL map.flyTo에 적용 :

var centroid = turf.centroid(myCoolFeatureGeometry); 

    map.flyTo({ 
     center: centroid.geometry.coordinates, 
     zoom: 19, 
     curve: 1, 
     screenSpeed: 4, 
     easing(t) { 
     return t; 
     } 
    }); 

당신은 또한 줌 레벨이 필요하면, 당신이 그것을 사용하여 얻을 수 있습니다 Turf's bbox (또는 envelope) 및

var features = turf.featureCollection([ 
    turf.point([-75.343, 39.984], {"name": "Location A"}), 
    turf.point([-75.833, 39.284], {"name": "Location B"}), 
    turf.point([-75.534, 39.123], {"name": "Location C"}) 
]); 

var enveloped = turf.envelope(features); 

map.fitBounds(enveloped, { 
    padding: {top: 10, bottom:25, left: 15, right: 5} 
}); 
MGL map.fitbounds 그 출력을 적용
관련 문제