Add support for HTML-markup-encoded marker labels, with associated API
This commit is contained in:
parent
6552b49626
commit
7af362f698
6 changed files with 60 additions and 8 deletions
|
|
@ -68,7 +68,17 @@ public interface Marker {
|
||||||
*/
|
*/
|
||||||
public String getLabel();
|
public String getLabel();
|
||||||
/**
|
/**
|
||||||
* Update the marker's label
|
* Update the marker's label (plain text)
|
||||||
*/
|
*/
|
||||||
public void setLabel(String lbl);
|
public void setLabel(String lbl);
|
||||||
|
/**
|
||||||
|
* Update the marker's label and markup flag
|
||||||
|
* @param label - label string
|
||||||
|
* @param markup - if true, label is processed as HTML (innerHTML for <span> used for label); false implies plaintext
|
||||||
|
*/
|
||||||
|
public void setLabel(String lbl, boolean markup);
|
||||||
|
/**
|
||||||
|
* Test if marker label is processed as HTML
|
||||||
|
*/
|
||||||
|
public boolean isLabelMarkup();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public interface MarkerSet {
|
||||||
* Create a new marker in the marker set
|
* Create a new marker in the marker set
|
||||||
*
|
*
|
||||||
* @param id - ID of the marker - must be unique within the set: if null, unique ID is generated
|
* @param id - ID of the marker - must be unique within the set: if null, unique ID is generated
|
||||||
* @param label - Label for the marker
|
* @param label - Label for the marker (plain text)
|
||||||
* @param world - world ID
|
* @param world - world ID
|
||||||
* @param x - x coord
|
* @param x - x coord
|
||||||
* @param y - y coord
|
* @param y - y coord
|
||||||
|
|
@ -29,6 +29,21 @@ public interface MarkerSet {
|
||||||
* @return created marker, or null if cannot be created.
|
* @return created marker, or null if cannot be created.
|
||||||
*/
|
*/
|
||||||
public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent);
|
public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent);
|
||||||
|
/**
|
||||||
|
* Create a new marker in the marker set
|
||||||
|
*
|
||||||
|
* @param id - ID of the marker - must be unique within the set: if null, unique ID is generated
|
||||||
|
* @param label - Label for the marker
|
||||||
|
* @param markup - if true, label is processed as HTML. if false, label is processed as plain text.
|
||||||
|
* @param world - world ID
|
||||||
|
* @param x - x coord
|
||||||
|
* @param y - y coord
|
||||||
|
* @param z - z coord
|
||||||
|
* @param icon - Icon for the marker
|
||||||
|
* @param is_persistent - if true, marker is persistent (saved and reloaded on restart). If set is not persistent, this must be false.
|
||||||
|
* @return created marker, or null if cannot be created.
|
||||||
|
*/
|
||||||
|
public Marker createMarker(String id, String label, boolean markup, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent);
|
||||||
/**
|
/**
|
||||||
* Get marker by ID
|
* Get marker by ID
|
||||||
* @param id - ID of the marker
|
* @param id - ID of the marker
|
||||||
|
|
|
||||||
|
|
@ -1053,6 +1053,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
mdata.put("z", m.getZ());
|
mdata.put("z", m.getZ());
|
||||||
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());
|
||||||
/* Add to markers */
|
/* Add to markers */
|
||||||
markers.put(m.getMarkerID(), mdata);
|
markers.put(m.getMarkerID(), mdata);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate;
|
||||||
class MarkerImpl implements Marker {
|
class MarkerImpl implements Marker {
|
||||||
private String markerid;
|
private String markerid;
|
||||||
private String label;
|
private String label;
|
||||||
|
private boolean markup;
|
||||||
private MarkerSetImpl markerset;
|
private MarkerSetImpl markerset;
|
||||||
private double x, y, z;
|
private double x, y, z;
|
||||||
private String world;
|
private String world;
|
||||||
|
|
@ -24,6 +25,7 @@ class MarkerImpl implements Marker {
|
||||||
* Create marker
|
* Create marker
|
||||||
* @param id - marker ID
|
* @param id - marker ID
|
||||||
* @param lbl - label
|
* @param lbl - label
|
||||||
|
* @param markup - if true, label is HTML markup
|
||||||
* @param world - world id
|
* @param world - world id
|
||||||
* @param x - x coord
|
* @param x - x coord
|
||||||
* @param y - y coord
|
* @param y - y coord
|
||||||
|
|
@ -31,12 +33,13 @@ class MarkerImpl implements Marker {
|
||||||
* @param icon - marker icon
|
* @param icon - marker icon
|
||||||
* @param persistent - true if persistent
|
* @param persistent - true if persistent
|
||||||
*/
|
*/
|
||||||
MarkerImpl(String id, String lbl, String world, double x, double y, double z, MarkerIconImpl icon, boolean persistent, MarkerSetImpl set) {
|
MarkerImpl(String id, String lbl, boolean markup, String world, double x, double y, double z, MarkerIconImpl icon, boolean persistent, MarkerSetImpl set) {
|
||||||
markerid = id;
|
markerid = id;
|
||||||
if(lbl != null)
|
if(lbl != null)
|
||||||
label = lbl;
|
label = lbl;
|
||||||
else
|
else
|
||||||
label = id;
|
label = id;
|
||||||
|
this.markup = markup;
|
||||||
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;
|
||||||
|
|
@ -52,6 +55,7 @@ class MarkerImpl implements Marker {
|
||||||
markerid = id;
|
markerid = id;
|
||||||
markerset = set;
|
markerset = set;
|
||||||
label = id;
|
label = id;
|
||||||
|
markup = false;
|
||||||
x = z = 0; y = 64; world = "world";
|
x = z = 0; y = 64; world = "world";
|
||||||
icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT);
|
icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
@ -61,6 +65,7 @@ class MarkerImpl implements Marker {
|
||||||
*/
|
*/
|
||||||
boolean loadPersistentData(ConfigurationNode node) {
|
boolean loadPersistentData(ConfigurationNode node) {
|
||||||
label = node.getString("label", markerid);
|
label = node.getString("label", markerid);
|
||||||
|
markup = node.getBoolean("markup", false);
|
||||||
x = node.getDouble("x", 0);
|
x = node.getDouble("x", 0);
|
||||||
y = node.getDouble("y", 64);
|
y = node.getDouble("y", 64);
|
||||||
z = node.getDouble("z", 0);
|
z = node.getDouble("z", 0);
|
||||||
|
|
@ -127,7 +132,13 @@ class MarkerImpl implements Marker {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLabel(String lbl) {
|
public void setLabel(String lbl) {
|
||||||
|
setLabel(lbl, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLabel(String lbl, boolean markup) {
|
||||||
label = lbl;
|
label = lbl;
|
||||||
|
this.markup = markup;
|
||||||
MarkerAPIImpl.markerUpdated(this, MarkerUpdate.UPDATED);
|
MarkerAPIImpl.markerUpdated(this, MarkerUpdate.UPDATED);
|
||||||
if(ispersistent)
|
if(ispersistent)
|
||||||
MarkerAPIImpl.saveMarkers();
|
MarkerAPIImpl.saveMarkers();
|
||||||
|
|
@ -142,6 +153,7 @@ class MarkerImpl implements Marker {
|
||||||
return null;
|
return null;
|
||||||
HashMap<String, Object> node = new HashMap<String, Object>();
|
HashMap<String, Object> node = new HashMap<String, Object>();
|
||||||
node.put("label", label);
|
node.put("label", label);
|
||||||
|
node.put("markup", markup);
|
||||||
node.put("x", Double.valueOf(x));
|
node.put("x", Double.valueOf(x));
|
||||||
node.put("y", Double.valueOf(y));
|
node.put("y", Double.valueOf(y));
|
||||||
node.put("z", Double.valueOf(z));
|
node.put("z", Double.valueOf(z));
|
||||||
|
|
@ -176,4 +188,8 @@ class MarkerImpl implements Marker {
|
||||||
if(ispersistent)
|
if(ispersistent)
|
||||||
MarkerAPIImpl.saveMarkers();
|
MarkerAPIImpl.saveMarkers();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isLabelMarkup() {
|
||||||
|
return markup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,6 +59,10 @@ class MarkerSetImpl implements MarkerSet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent) {
|
public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent) {
|
||||||
|
return createMarker(id, label, false, world, x, y, z, icon, is_persistent);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Marker createMarker(String id, String label, boolean markup, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent) {
|
||||||
if(id == null) { /* If not defined, generate unique one */
|
if(id == null) { /* If not defined, generate unique one */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
do {
|
do {
|
||||||
|
|
@ -72,7 +76,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||||
if((allowedicons != null) && (allowedicons.containsKey(icon.getMarkerIconID()) == false)) return null;
|
if((allowedicons != null) && (allowedicons.containsKey(icon.getMarkerIconID()) == false)) return null;
|
||||||
/* Create marker */
|
/* Create marker */
|
||||||
is_persistent = is_persistent && this.ispersistent;
|
is_persistent = is_persistent && this.ispersistent;
|
||||||
MarkerImpl marker = new MarkerImpl(id, label, world, x, y, z, (MarkerIconImpl)icon, is_persistent, this);
|
MarkerImpl marker = new MarkerImpl(id, label, markup, world, x, y, z, (MarkerIconImpl)icon, is_persistent, this);
|
||||||
markers.put(id, marker); /* Add to set */
|
markers.put(id, marker); /* Add to set */
|
||||||
if(is_persistent)
|
if(is_persistent)
|
||||||
MarkerAPIImpl.saveMarkers();
|
MarkerAPIImpl.saveMarkers();
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,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, 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 };
|
||||||
createMarker(ms, ms.markers[mname], ts);
|
createMarker(ms, ms.markers[mname], ts);
|
||||||
});
|
});
|
||||||
|
|
@ -59,8 +59,14 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
$(div)
|
$(div)
|
||||||
.addClass('Marker')
|
.addClass('Marker')
|
||||||
.addClass('mapMarker')
|
.addClass('mapMarker')
|
||||||
.append($('<img/>').addClass('markerIcon16x16').attr({ src: dynmap.options.tileUrl+'_markers_/'+marker.icon+'.png' }))
|
.append($('<img/>').addClass('markerIcon16x16').attr({ src: dynmap.options.tileUrl+'_markers_/'+marker.icon+'.png' }));
|
||||||
.append($('<span/>')
|
if(marker.markup) {
|
||||||
|
$(div).append($('<span/>')
|
||||||
|
.addClass(configuration.showlabel?'markerName-show':'markerName')
|
||||||
|
.append(marker.label));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$(div).append($('<span/>')
|
||||||
.addClass(configuration.showlabel?'markerName-show':'markerName')
|
.addClass(configuration.showlabel?'markerName-show':'markerName')
|
||||||
.text(marker.label));
|
.text(marker.label));
|
||||||
return div;
|
return div;
|
||||||
|
|
@ -86,7 +92,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 };
|
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label, markup: msg.markup };
|
||||||
dynmapmarkersets[msg.set].markers[msg.id] = marker;
|
dynmapmarkersets[msg.set].markers[msg.id] = marker;
|
||||||
createMarker(dynmapmarkersets[msg.set], marker);
|
createMarker(dynmapmarkersets[msg.set], marker);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue