【发布时间】:2017-05-12 23:55:32
【问题描述】:
我在尝试设置 Google 地图样式时遇到了一个非常奇怪的问题。
通常要为 Google 地图设置样式,请执行以下操作:
var styledMapType = new google.maps.StyledMapType(this.jsonData,{name: "Styled Map"});
而 this.jsonData 是一个长 JSON 文件。我正在导入一个本地 JSON 文件并尝试将其注入 new google.maps.StyledMapType 对象;但是,没有任何改变!另一方面,当我将同一个本地 JSON 文件的内容分配给一个变量时,它会起作用并改变地图的样式。但是,我不想将那个长 JSON 数组保留在我的控制器的同一页面上。
我正在使用以下导入本地 JSON 文件:
mapStyleFile(){
this.http.get("assets/json/mapStyle.json")
.map((res) => res)
.subscribe(data =>{
this.jsonData = data["_body"];
});
}
模板 JSON:
[
{
"featureType": "all",
"elementType": "all",
"stylers": [
{
"hue": "#e7ecf0"
}
]
},
{
"featureType": "administrative",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#636c81"
}
]
},
{
"featureType": "administrative.neighborhood",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#636c81"
}
]
},
{
"featureType": "administrative.land_parcel",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#ff0000"
}
]
},
{
"featureType": "landscape",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#f1f4f6"
}
]
},
{
"featureType": "landscape",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#496271"
}
]
},
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road",
"elementType": "all",
"stylers": [
{
"saturation": -70
}
]
},
{
"featureType": "road",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#ffffff"
}
]
},
{
"featureType": "road",
"elementType": "geometry.stroke",
"stylers": [
{
"color": "#c6d3dc"
}
]
},
{
"featureType": "road",
"elementType": "labels.text.fill",
"stylers": [
{
"color": "#898e9b"
}
]
},
{
"featureType": "transit",
"elementType": "all",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"visibility": "simplified"
},
{
"saturation": -60
}
]
},
{
"featureType": "water",
"elementType": "geometry.fill",
"stylers": [
{
"color": "#d3eaf8"
}
]
}
]
【问题讨论】:
标签: javascript google-maps angular google-maps-api-3