简单地向html标记添加一个自定义属性,然后向其中添加数据。该数据将始终带有标记。例如:
var popup = new atlas.Popup();
//Create a HTML marker and add it to the map.
var marker = new atlas.HtmlMarker({
position: [0,0]
});
//Add your custom property with data
marker.properties = {
title: 'hello world'
};
map.markers.add(marker);
map.events.add('click',marker,function(e){
//Get the clicked marker.
var m = e.target;
//Get custom properties on the marker
var p = m.properties;
popup.setOptions({
content: `<div style="padding:10px;">${p.title}</div>`,position:m.getOptions().position,pixelOffset: [0,-18]
});
//Open the popup.
popup.open(map);
});
本文链接:https://www.f2er.com/2564941.html