地图上明亮的装饰瓷砖,黑色风格看起来不太好。有没有办法改变加载瓷砖的颜色?
答案 0 :(得分:3)
在您的应用mapLabelStyle.json
中创建raw folder
。将此json样式复制到该文件中。
[
{
"elementType": "labels",
"stylers": [
{
"lightness": 5
},
{
"visibility": "simplified"
}
]
},
{
"elementType": "labels.text",
"stylers": [
{
"color": "#400040" //You can change color of your choice
}
]
}
]
然后使用下面的代码设置样式。
GoogleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(this,R.raw.mapLabelStyle));
答案 1 :(得分:2)
您可以使用GoogleMap.setMapStyle
更改地图的主题,请尝试使用
try {
// Customise the styling of the base map using a JSON object defined
// in a raw resource file.
boolean success = googleMap.setMapStyle(
MapStyleOptions.loadRawResourceStyle(
this, R.raw.style_json));
if (!success) {
Log.e(TAG, "Style parsing failed.");
}
} catch (Resources.NotFoundException e) {
Log.e(TAG, "Can't find style. Error: ", e);
}
您可以从此official map style site获取json文件,然后将该json文件放入应用程序原始文件夹
有关在Android中设置地图样式的完整说明,您可以在official site
中查阅示例style_json
[
{
"elementType": "geometry",
"stylers": [
{
"color": "#212121"
}
]
},
{
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#757575"
}
]
},
{
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#212121"
}
]
},
{
"featureType": "administrative.country",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#9e9e9e"
}
]
},
{
"featureType": "administrative.locality",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#bdbdbd"
}
]
},
{
"featureType": "poi",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#757575"
}
]
},
{
"featureType": "poi.park",
"elementType": "geometry",
"stylers": [
{
"color": "#181818"
}
]
},
{
"featureType": "poi.park",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#616161"
}
]
},
{
"featureType": "poi.park",
"elementType": "labels.text.stroke",
"stylers": [
{
"color": "#1b1b1b"
}
]
},
{
"featureType": "road",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#2c2c2c"
}
]
},
{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#8a8a8a"
}
]
},
{
"featureType": "road.arterial",
"elementType": "geometry",
"stylers": [
{
"color": "#373737"
}
]
},
{
"featureType": "road.highway",
"elementType": "geometry",
"stylers": [
{
"color": "#3c3c3c"
}
]
},
{
"featureType": "road.highway.controlled_access",
"elementType": "geometry",
"stylers": [
{
"color": "#4e4e4e"
}
]
},
{
"featureType": "road.local",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#616161"
}
]
},
{
"featureType": "transit",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#757575"
}
]
},
{
"featureType": "water",
"elementType": "geometry",
"stylers": [
{
"color": "#000000"
}
]
},
{
"featureType": "water",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#3d3d3d"
}
]
}
]
答案 2 :(得分:1)
试试这个
map = new GMap2(document.getElementById("map"), { backgroundColor: "#000000" });
答案 3 :(得分:1)
你在评论中说“我正在编写Android的原生应用程序”,但这并没有反映在你的标签(android,google-maps)或标题或问题上。
如果您使用的是Ionic native 4.0 Framework ionicframework ,那么:
setBackgroundColor(color); //Specifies the background color of the app.
答案 4 :(得分:1)
<强>概念强>
Tile是一个矩形的strcuture,它保存图像数据。 Tile
(link)由TileProvider
(link)提供。 TileProvider
是一个为TileOverlay
(link)提供平铺图像的类。
注意:叠加本质上是透明的,具有x,y和z轴。它就像在你面前的透明玻璃。
TileProvider在TileOverlay后面提供了Tile,就像你把书放在透明玻璃下面一样。在TileOverlay
的z轴中,有一组图层,例如GroundOverlays
,Circles
,Polylines
和Polygons
。这意味着GroundOverlays
位于最后一层,而且最不透明。您可以在GroundOverlay
中提供自定义图像并更改颜色。您还可以维护所有其他顶层的透明度,可见性等属性。这样,您可以更改图块颜色。
现在,您的主要任务是创建自定义的GroundOverlay。
您GroundOverlay
图片的格式为BitmapDescriptor
。您可以使用BitmapDescriptorFactory
创建自定义BitmapDescriptor
图片,如下所示。
BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.current_position_tennis_ball)
/ *您看,current_position_tennis_ball drawable resource
,现在,您用作Tile
颜色* /
<强>实施强>
注意:MOON_MAP_URL_FORMAT是enter code here
jpg图片,tileProvider
正在引用该图片(实际上是自定义图片)
private static final String MOON_MAP_URL_FORMAT =
"http://mw1.google.com/mw-planetary/lunar/lunarmaps_v1/clem_bw/%d/%d/%d.jpg";
/ *提供上面明亮的jpg * /
TileProvider tileProvider /* ultimately it is an image */ = new UrlTileProvider(256, 256) {
@Override
public synchronized URL getTileUrl(int x, int y, int zoom) {
// The moon tile coordinate system is reversed. This is not normal.
int reversedY = (1 << zoom) - y - 1;
String s = String.format(Locale.US, MOON_MAP_URL_FORMAT, zoom, x, reversedY);
URL url = null;
try {
url = new URL(s);
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
return url;
}
};
您可以看到完整的源代码here。