<!--StartFragment -->
var map, baiduLayer,marker,markersLayer;
init();
function init() {
map = new SuperMap.Map("map", {
controls: [
new SuperMap.Control.Navigation(),
new SuperMap.Control.Zoom(),
new SuperMap.Control.MousePosition()
]
});
baiduLayer = new SuperMap.Layer.Baidu();
map.addLayers([baiduLayer,markersLayer]);
map.setCenter(new SuperMap.LonLat(12916528, 4338068), 12);
//初始化标记图层类
markersLayer = new SuperMap.Layer.Markers("Markers");
baiduLayer.events.on({"layerInitialized": addMarker});
/* baiduLayer.addMarker();*/
}
//marker是一个点事务,markersLayer是一个图层
//定义addMarker函数,触发layerInitialized事件会调用此函数
function addMarker() {
size = new SuperMap.Size(210, 250);
offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
icon = new SuperMap.Icon('image/marker.png', size, offset);
//初始化标记覆盖物类
marker = new SuperMap.Marker(new SuperMap.LonLat(12916528, 4338068), icon);
//添加覆盖物到标记图层
markersLayer.addMarker(marker);
//注册 click 事件,触发 mouseClickHandler()方法
marker.events.on({
"click": mouseClickHandler,
"touchstart": mouseClickHandler //假如要在移动端的浏览器也实现点击弹框,则在注册touch类事件
});
}
</script>
请问一下,我想要添加一个marker但是却没有添加上,并且原来的图也变成了空白。是我添加的marker有错误吗?如何改正呢?谢谢了!