问题描述
我已成功使用MapBoxStatic创建了静态图像,并将记录的轨迹坐标作为GeoJson数据。
我不知道如何编辑在图像上绘制的路线的颜色-默认为黑色/灰色,我找不到改变它的方法。
我意识到必须通过编辑GeoJson属性本身来实现,但是我不知道如何迅速地做到这一点?
很想了解如何以某种方式改变颜色...
let camera = SnapshotCamera(
lookingAtCenter: CLLocationCoordinate2D(latitude: self.mapView.camera.centerCoordinate.latitude,longitude: self.mapView.camera.centerCoordinate.longitude),zoomLevel: 12)
let options = SnapshotOptions(
styleURL: self.mapView.styleURL,camera: camera,size: self.mapView.bounds.size)
let coordinates = self.viewmodel.getTrack().locations?.map { loc -> CLLocationCoordinate2D in
CLLocationCoordinate2D(latitude: loc.latitude,longitude: loc.longitude)
}
let trackLine = MGLpolyline(coordinates: coordinates!,count: UInt(coordinates!.count))
let data = trackLine.geoJSONData(usingEncoding: String.Encoding.utf8.rawValue)
let getJson = GeoJSON(objectString: String(data: data,encoding: .utf8)!)
options.overlays.append(getJson)
解决方法
您需要使用MGLPolylineFeature来控制要素属性。
所以不是
--------------------------------------------------------------------------------
^ the beginning of the string
--------------------------------------------------------------------------------
https: 'https:'
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
[^\/]+ any character except: '\/' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
(?: group,but do not capture (optional
(matching the most amount possible)):
--------------------------------------------------------------------------------
( group and capture to \2:
--------------------------------------------------------------------------------
[a-z]{1,2} any character of: 'a' to 'z' (between
1 and 2 times (matching the most
amount possible))
--------------------------------------------------------------------------------
) end of \2
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
)? end of grouping
--------------------------------------------------------------------------------
( group and capture to \3:
--------------------------------------------------------------------------------
buy 'buy'
--------------------------------------------------------------------------------
| OR
--------------------------------------------------------------------------------
kauf 'kauf'
--------------------------------------------------------------------------------
) end of \3
--------------------------------------------------------------------------------
\/ '/'
--------------------------------------------------------------------------------
( group and capture to \4:
--------------------------------------------------------------------------------
[^\/]+ any character except: '\/' (1 or more
times (matching the most amount
possible))
--------------------------------------------------------------------------------
) end of \4
--------------------------------------------------------------------------------
$ before an optional \n,and the end of the
string
它看起来应该像
let trackLine = MGLPolyline(coordinates: coordinates!,count: UInt(coordinates!.count))