mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-16 07:15:12 +01:00
Add 'setDescription()' for markers (HTML popup for clicked marker)
This commit is contained in:
parent
978a203aa9
commit
e3501142cd
@ -81,4 +81,14 @@ public interface Marker {
|
||||
* Test if marker label is processed as HTML
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
@ -1054,6 +1054,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
mdata.put("icon", m.getMarkerIcon().getMarkerIconID());
|
||||
mdata.put("label", m.getLabel());
|
||||
mdata.put("markup", m.isLabelMarkup());
|
||||
if(m.getDescription() != null)
|
||||
mdata.put("desc", m.getDescription());
|
||||
/* Add to markers */
|
||||
markers.put(m.getMarkerID(), mdata);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class MarkerImpl implements Marker {
|
||||
private String markerid;
|
||||
private String label;
|
||||
private boolean markup;
|
||||
private String desc;
|
||||
private MarkerSetImpl markerset;
|
||||
private double x, y, z;
|
||||
private String world;
|
||||
@ -43,6 +44,7 @@ class MarkerImpl implements Marker {
|
||||
this.x = x; this.y = y; this.z = z;
|
||||
this.world = world;
|
||||
this.icon = icon;
|
||||
this.desc = null;
|
||||
ispersistent = persistent;
|
||||
markerset = set;
|
||||
}
|
||||
@ -56,6 +58,7 @@ class MarkerImpl implements Marker {
|
||||
markerset = set;
|
||||
label = id;
|
||||
markup = false;
|
||||
desc = null;
|
||||
x = z = 0; y = 64; world = "world";
|
||||
icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT);
|
||||
}
|
||||
@ -70,6 +73,7 @@ class MarkerImpl implements Marker {
|
||||
y = node.getDouble("y", 64);
|
||||
z = node.getDouble("z", 0);
|
||||
world = node.getString("world", "world");
|
||||
desc = node.getString("desc", null);
|
||||
icon = MarkerAPIImpl.getMarkerIconImpl(node.getString("icon", MarkerIcon.DEFAULT));
|
||||
ispersistent = true; /* Loaded from config, so must be */
|
||||
|
||||
@ -159,6 +163,8 @@ class MarkerImpl implements Marker {
|
||||
node.put("z", Double.valueOf(z));
|
||||
node.put("world", world);
|
||||
node.put("icon", icon.getMarkerIconID());
|
||||
if(desc != null)
|
||||
node.put("desc", desc);
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -192,4 +198,21 @@ class MarkerImpl implements Marker {
|
||||
public boolean isLabelMarkup() {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
});
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user