gpt4 book ai didi

swift - 使用 mapbox 自定义 MGLPolyline

转载 作者:搜寻专家 更新时间:2023-11-01 06:08:10 25 4
gpt4 key购买 nike

刚开始使用 Mapbox,设法通过在 locationManaged didUpdateLocations 中添加它来绘制 MGLPolyline

   var shape = MGLPolyline(coordinates: &a, count: UInt(a.count))
mapView.addAnnotation(shape)
  1. 改变线宽不会在屏幕上改变它

func mapView(mapView: MGLMapView, lineWidthForPolylineAnnotation 注释: MGLPolyline) -> CGFloat { return 20.0 }

  1. 如何将描边默认颜色从黑色更改为其他颜色?

最佳答案

您需要将 map 委托(delegate)设置为 self 才能使函数正常工作。这是代码:

使用 MGLMapViewDelegate 启动您的 viewController

class yourController: UIViewController, CLLocationManagerDelegate, MKMapViewDelegate, MGLMapViewDelegate{

然后在你设置好 map 之后,像这样添加self.mapView.delegate = self

mapView = MGLMapView(frame: mapViewWrapper.bounds, styleURL: NSURL(string: Mapbox.getTheme()))
mapView = Mapbox.configure(mapView)
mapView.setCenterCoordinate(appleMap.userLocation.coordinate, zoomLevel: 12, animated: true)
mapViewWrapper.addSubview(mapView)
self.mapView.delegate = self

然后你的函数就可以工作了:

func mapView(mapView: MGLMapView, alphaForShapeAnnotation annotation: MGLShape) -> CGFloat {
// Set the alpha for all shape annotations to 1 (full opacity)
return 1
}

func mapView(mapView: MGLMapView, lineWidthForPolylineAnnotation annotation: MGLPolyline) -> CGFloat {
// Set the line width for polyline annotations
return 5.0
}

func mapView(mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {
// Give our polyline a unique color by checking for its `title` property
return UIColor.redColor()
}

关于swift - 使用 mapbox 自定义 MGLPolyline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com