Add 'setDescription()' for markers (HTML popup for clicked marker)

This commit is contained in:
Mike Primm 2011-10-13 08:21:28 +08:00 committed by mikeprimm
parent 978a203aa9
commit e3501142cd
5 changed files with 64 additions and 2 deletions

View file

@ -108,5 +108,27 @@ L.CustomMarker = L.Class.extend({
_fireMouseEvent: function(e) {
this.fire(e.type);
L.DomEvent.stopPropagation(e);
},
openPopup: function() {
this._popup.setLatLng(this._latlng);
this._map.openPopup(this._popup);
return this;
},
closePopup: function() {
if (this._popup) {
this._popup._close();
}
},
bindPopup: function(content, options) {
this._popup = new L.Popup(options);
this._popup.setContent(content);
this.on('click', this.openPopup, this);
return this;
}
});

View file

@ -37,7 +37,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
dynmapmarkersets[name] = ms;
$.each(markerset.markers, function(mname, marker) {
ms.markers[mname] = { label: marker.label, markup: marker.markup, x: marker.x, y: marker.y, z:marker.z,
icon: marker.icon };
icon: marker.icon, desc: marker.desc };
createMarker(ms, ms.markers[mname], ts);
});
});
@ -74,6 +74,11 @@ componentconstructors['markers'] = function(dynmap, configuration) {
return div;
}});
marker.timestamp = ts;
if(marker.desc) {
var popup = document.createElement('div');
$(popup).addClass('MarkerPopup').append(marker.desc);
marker.our_marker.bindPopup(popup, {});
}
set.layergroup.addLayer(marker.our_marker);
}
@ -94,7 +99,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker);
delete marker.our_marker;
}
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label, markup: msg.markup };
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label, markup: msg.markup, desc: msg.desc };
dynmapmarkersets[msg.set].markers[msg.id] = marker;
createMarker(dynmapmarkersets[msg.set], marker);
}