百度地图API 自定义坐标点及图片
Posted Mr_R
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了百度地图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
以上是关于百度地图API 自定义坐标点及图片的主要内容,如果未能解决你的问题,请参考以下文章