百度地圖API 自定義座標點及圖片
var map = new BMap.Map("allmap");
var point = new BMap.Point(105.955754,36.525109);
map.centerAndZoom(point,8);
map.enableScrollWheelZoom();
//獲得原標示陣列
// 定義標示圖片
var icon1 = new BMap.Icon("image/標示1.jpg",new BMap.Size(128,128));
var icon2 = new BMap.Icon("image/標示3.jpg",new BMap.Size(128,128));
// 設定標示
var mark1 = new BMap.Marker(new BMap.Point(116.41433,39.889031),{icon:icon1});
var mark2 = new BMap.Marker(new BMap.Point(116.303371,39.858021),{icon:icon1});
var mark3 = new BMap.Marker(new BMap.Point(116.44092,39.899991),{icon:icon1});
var mark4 = new BMap.Marker(new BMap.Point(116.409156,39.968263),{icon:icon2});
var mark5 = new BMap.Marker(new BMap.Point(116.330967,39.960742),{icon:icon2});
var mark6 = new BMap.Marker(new BMap.Point(116.450549,39.927994),{icon:icon2});
var mark7 = new BMap.Marker(new BMap.Point(116.422379,39.92224),{icon:icon2});
var mark8 = new BMap.Marker(new BMap.Point(116.383859,39.924896),{icon:icon2});
var mark9 = new BMap.Marker(new BMap.Point(106.258806,38.289461),{icon:icon2});
var marks = [mark1,mark2,mark3,mark4,mark5,mark6,mark7,mark8,mark9];
//獲得點選後的標示陣列{
// 定義標示圖片
var changeIcon1 = new BMap.Icon("image/標示2.jpg",new BMap.Size(128,128));
var changeIcon2 = new BMap.Icon("image/標示4.jpg",new BMap.Size(128,128));
// 設定標示
var changeMark1 = new BMap.Marker(new BMap.Point(116.41433,39.889031),{icon:changeIcon1});
var changeMark2 = new BMap.Marker(new BMap.Point(116.303371,39.858021),{icon:changeIcon1});
var changeMark3 = new BMap.Marker(new BMap.Point(116.44092,39.899991),{icon:changeIcon1});
var changeMark4 = new BMap.Marker(new BMap.Point(116.409156,39.968263),{icon:changeIcon2});
var changeMark5 = new BMap.Marker(new BMap.Point(116.330967,39.960742),{icon:changeIcon2});
var changeMark6 = new BMap.Marker(new BMap.Point(116.450549,39.927994),{icon:changeIcon2});
var changeMark7 = new BMap.Marker(new BMap.Point(116.422379,39.92224),{icon:changeIcon2});
var changeMark8 = new BMap.Marker(new BMap.Point(116.383859,39.924896),{icon:changeIcon2});
var changeMark9 = new BMap.Marker(new BMap.Point(116.411311,39.942932),{icon:changeIcon2});
var changeMarks = [changeMark1,changeMark2,changeMark3,changeMark4,changeMark5,changeMark6,changeMark7,changeMark8,changeMark9];
//建立Mark標示
for(var i=0;i<marks.length;i++){
// 將此標示放入地圖
map.addOverlay(marks[i]);
//var markIndex = marks[i];
(function(i){
marks[i].addEventListener("click",function(e){
for(var j=0;j<marks.length;j++){
if(j == i){
//alert("i = " + i);
var n = j+1;
doClick(n);
// 當滑鼠點選這個標示的時候,標示的顏色改
map.addOverlay(changeMarks[j]);
}else{
map.removeOverlay(changeMarks[j]);
}
}
});
})(i);
}
摘自:https://bbs.csdn.net/topics/390508734