scenes to be used
Custom road conditions are used to help modify the color and width of road conditions, because the internal font of the map is uniform, if you want to modify the style, you can define it through the relevant text interface
Core classes and interfaces
class | interface | Description |
---|---|---|
TrafficStyle | setCongestedStrokeColor | Set the stroke color of traffic jam |
setSeriousCongestedColor | Set the color of extremely congested traffic | |
setSeriousCongestedStrokeColor | Set the stroke color for extremely congested traffic | |
setSlowColor | Set the color of slow traffic | |
setSlowStrokeColor | Set the stroke color of easing traffic | |
setSmoothColor | Set the color of smooth traffic | |
setSmoothStrokeColor | Set the color of the smooth stroke | |
setStrokeWidth | Set the width of the traffic stroke color | |
setWidth | Set the width of the traffic fill color | |
TencentMapOptions | setTrafficStyle | Set traffic style |
setTypeface | Set custom font |
Core point explanation
1. Set custom traffic conditions
1. Initialize TrafficStyle and configure related properties
TrafficStyle trafficStyle = new TrafficStyle();
//设置路况极度拥堵的颜色
trafficStyle.setSeriousCongestedColor(0xff92000a);
//设置路况拥堵的颜色
trafficStyle.setCongestedColor(0xffea0312);
//设置路况慢行的颜色
trafficStyle.setSlowColor(0xffff7508);
//设置路况畅通的颜色
trafficStyle.setSmoothColor(0xff00a209);
//设置路况填充颜色的宽度
trafficStyle.setWidth(10);
2. Assign TrafficStyle to TencentMapOptions
TencentMapOptions tencentMapOptions = new TencentMapOptions();
tencentMapOptions.setTrafficStyle(trafficStyle);
3. Display on the map
MapView mapView = new MapView(getApplicationContext(), tencentMapOptions);
2. Set custom fonts
1. Modify the text style
tencentMapOptions.setTypeface(Typeface.DEFAULT_BOLD);
Achieve effect
Road conditions
Text
note
1. It needs to be passed in when the map is initialized, and it cannot be changed after initialization
2. After customizing the road conditions, you need to turn on the road conditions, because the map is not turned on by default
Author: CT_YJ
Link: https://my.oschina.net/u/4860187/blog/4756171
Source: OSCHINA
The copyright belongs to the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.