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

@ -81,4 +81,14 @@ public interface Marker {
* Test if marker label is processed as HTML * Test if marker label is processed as HTML
*/ */
public boolean isLabelMarkup(); public boolean isLabelMarkup();
/**
* Set marker description (HTML markup shown in popup when clicked)
* @param desc - HTML markup description
*/
public void setDescription(String desc);
/**
* Get marker description
* @return descrption
*/
public String getDescription();
} }

View File

@ -1054,6 +1054,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
mdata.put("icon", m.getMarkerIcon().getMarkerIconID()); mdata.put("icon", m.getMarkerIcon().getMarkerIconID());
mdata.put("label", m.getLabel()); mdata.put("label", m.getLabel());
mdata.put("markup", m.isLabelMarkup()); mdata.put("markup", m.isLabelMarkup());
if(m.getDescription() != null)
mdata.put("desc", m.getDescription());
/* Add to markers */ /* Add to markers */
markers.put(m.getMarkerID(), mdata); markers.put(m.getMarkerID(), mdata);
} }

View File

@ -15,6 +15,7 @@ class MarkerImpl implements Marker {
private String markerid; private String markerid;
private String label; private String label;
private boolean markup; private boolean markup;
private String desc;
private MarkerSetImpl markerset; private MarkerSetImpl markerset;
private double x, y, z; private double x, y, z;
private String world; private String world;
@ -43,6 +44,7 @@ class MarkerImpl implements Marker {
this.x = x; this.y = y; this.z = z; this.x = x; this.y = y; this.z = z;
this.world = world; this.world = world;
this.icon = icon; this.icon = icon;
this.desc = null;
ispersistent = persistent; ispersistent = persistent;
markerset = set; markerset = set;
} }
@ -56,6 +58,7 @@ class MarkerImpl implements Marker {
markerset = set; markerset = set;
label = id; label = id;
markup = false; markup = false;
desc = null;
x = z = 0; y = 64; world = "world"; x = z = 0; y = 64; world = "world";
icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT); icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT);
} }
@ -70,6 +73,7 @@ class MarkerImpl implements Marker {
y = node.getDouble("y", 64); y = node.getDouble("y", 64);
z = node.getDouble("z", 0); z = node.getDouble("z", 0);
world = node.getString("world", "world"); world = node.getString("world", "world");
desc = node.getString("desc", null);
icon = MarkerAPIImpl.getMarkerIconImpl(node.getString("icon", MarkerIcon.DEFAULT)); icon = MarkerAPIImpl.getMarkerIconImpl(node.getString("icon", MarkerIcon.DEFAULT));
ispersistent = true; /* Loaded from config, so must be */ ispersistent = true; /* Loaded from config, so must be */
@ -159,6 +163,8 @@ class MarkerImpl implements Marker {
node.put("z", Double.valueOf(z)); node.put("z", Double.valueOf(z));
node.put("world", world); node.put("world", world);
node.put("icon", icon.getMarkerIconID()); node.put("icon", icon.getMarkerIconID());
if(desc != null)
node.put("desc", desc);
return node; return node;
} }
@ -192,4 +198,21 @@ class MarkerImpl implements Marker {
public boolean isLabelMarkup() { public boolean isLabelMarkup() {
return markup; return markup;
} }
@Override
public void setDescription(String desc) {
if((this.desc == null) || (this.desc.equals(desc) == false)) {
this.desc = desc;
MarkerAPIImpl.markerUpdated(this, MarkerUpdate.UPDATED);
if(ispersistent)
MarkerAPIImpl.saveMarkers();
}
}
/**
* Get marker description
* @return descrption
*/
public String getDescription() {
return this.desc;
}
} }

View File

@ -108,5 +108,27 @@ L.CustomMarker = L.Class.extend({
_fireMouseEvent: function(e) { _fireMouseEvent: function(e) {
this.fire(e.type); this.fire(e.type);
L.DomEvent.stopPropagation(e); 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; dynmapmarkersets[name] = ms;
$.each(markerset.markers, function(mname, marker) { $.each(markerset.markers, function(mname, marker) {
ms.markers[mname] = { label: marker.label, markup: marker.markup, x: marker.x, y: marker.y, z:marker.z, 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); createMarker(ms, ms.markers[mname], ts);
}); });
}); });
@ -74,6 +74,11 @@ componentconstructors['markers'] = function(dynmap, configuration) {
return div; return div;
}}); }});
marker.timestamp = ts; 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); set.layergroup.addLayer(marker.our_marker);
} }
@ -94,7 +99,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker); dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker);
delete 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; dynmapmarkersets[msg.set].markers[msg.id] = marker;
createMarker(dynmapmarkersets[msg.set], marker); createMarker(dynmapmarkersets[msg.set], marker);
} }