引入百度地圖api就不用多說了吧!
https://developer.baidu.com/map/custom/
//這個網址可以去模擬修改百度地圖樣式
當修改到心儀的樣式時,點擊生成JSON,就會彈出樣式,
接着你就可以在你代碼地圖實例化的時候進行修改
var style_map=[ {
// 地圖背景
"featureType": "land",
"elementType": "all",
"stylers": {
"color": "#93c47dff",
"lightness": -1
}
}, {
// 水路背景
"featureType": "water",
"elementType": "all",
"stylers": {
"color": "#a2c4c9ff",
"lightness": -1
}
}, {
// 綠地背景
"featureType": "green",
"elementType": "all",
"stylers": {
"color": "#ffffccff",
"lightness": -1
}
},{
// 教育地區
"featureType": "education",
"elementType": "all",
"stylers": {
"color": "#d5a6bdff",
"lightness": -1
}
} ]
//將樣式加載到地圖中
map.setMapStyle({styleJson:eval("style_map")});
然後地圖樣式就修改了
百度地圖api 也有自己寫好的樣式,不過個人觀點感覺不太好搭,
var style_map=['normal','light','dark','redalert','googlelite','grassgreen','midnight','pink','darkgreen','bluish','grayscale','hardedge'];
//分別風格是:默認地圖樣式,清新藍風格,黑夜風格,紅色警戒風格,精簡風格,自然綠風格,午夜藍風格,浪漫粉風格,青春綠風格,清新藍綠風格,高端灰風格,強邊界風格
用來沒啥問題就是顏色有點尷尬,總覺得不太舒服,個人建議還是去自己調一下!!!
//首先定義對象,style就是上面數組內的東西
var mapStyle = {
features: ["road", "building", "water", "land"], //隱藏地圖上的"poi",
style: "grassgreen"
};
map.setMapStyle(mapStyle);
數組中前三個不需要引入第三方庫
其他的則需要引入
<script type="text/javascript" src="http://developer.baidu.com/map/custom/stylelist.js"></script>
success,結束!