Complete area marker API, command line and UI support
This commit is contained in:
parent
22324f6c48
commit
7b5e35aeaf
2 changed files with 133 additions and 43 deletions
|
|
@ -99,11 +99,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
public double ytop, ybottom;
|
public double ytop, ybottom;
|
||||||
public double[] x;
|
public double[] x;
|
||||||
public double[] z;
|
public double[] z;
|
||||||
public int strokeWeight;
|
public int weight;
|
||||||
public double strokeOpacity;
|
public double opacity;
|
||||||
public int strokeColor;
|
public String color;
|
||||||
public double fillOpacity;
|
public double fillopacity;
|
||||||
public int fillColor;
|
public String fillcolor;
|
||||||
public String id;
|
public String id;
|
||||||
public String label;
|
public String label;
|
||||||
public String set;
|
public String set;
|
||||||
|
|
@ -120,17 +120,17 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
x[i] = m.getCornerX(i);
|
x[i] = m.getCornerX(i);
|
||||||
z[i] = m.getCornerZ(i);
|
z[i] = m.getCornerZ(i);
|
||||||
}
|
}
|
||||||
strokeColor = m.getLineColor();
|
color = String.format("#%06X", m.getLineColor());
|
||||||
strokeWeight = m.getLineWeight();
|
weight = m.getLineWeight();
|
||||||
strokeOpacity = m.getFillOpacity();
|
opacity = m.getLineOpacity();
|
||||||
fillColor = m.getFillColor();
|
fillcolor = String.format("#%06X", m.getFillColor());
|
||||||
fillOpacity = m.getFillOpacity();
|
fillopacity = m.getFillOpacity();
|
||||||
|
|
||||||
this.set = m.getMarkerSet().getMarkerSetID();
|
this.set = m.getMarkerSet().getMarkerSetID();
|
||||||
if(deleted)
|
if(deleted)
|
||||||
msg = "areamarkerdeleted";
|
msg = "areadeleted";
|
||||||
else
|
else
|
||||||
msg = "areamarkerupdated";
|
msg = "areaupdated";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -468,6 +468,51 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
markerSetUpdated(markerset, MarkerUpdate.DELETED); /* Signal delete of set */
|
markerSetUpdated(markerset, MarkerUpdate.DELETED); /* Signal delete of set */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean processAreaArgs(CommandSender sender, AreaMarker marker, Map<String,String> parms) {
|
||||||
|
String val = null;
|
||||||
|
try {
|
||||||
|
double ytop = marker.getTopY();
|
||||||
|
double ybottom = marker.getBottomY();
|
||||||
|
int scolor = marker.getLineColor();
|
||||||
|
int fcolor = marker.getFillColor();
|
||||||
|
double sopacity = marker.getLineOpacity();
|
||||||
|
double fopacity = marker.getFillOpacity();
|
||||||
|
int sweight = marker.getLineWeight();
|
||||||
|
|
||||||
|
val = parms.get(ARG_STROKECOLOR);
|
||||||
|
if(val != null)
|
||||||
|
scolor = Integer.parseInt(val, 16);
|
||||||
|
val = parms.get(ARG_FILLCOLOR);
|
||||||
|
if(val != null)
|
||||||
|
fcolor = Integer.parseInt(val, 16);
|
||||||
|
val = parms.get(ARG_STROKEOPACITY);
|
||||||
|
if(val != null)
|
||||||
|
sopacity = Double.parseDouble(val);
|
||||||
|
val = parms.get(ARG_FILLOPACITY);
|
||||||
|
if(val != null)
|
||||||
|
fopacity = Double.parseDouble(val);
|
||||||
|
val = parms.get(ARG_STROKEWEIGHT);
|
||||||
|
if(val != null)
|
||||||
|
sweight = Integer.parseInt(val);
|
||||||
|
val = parms.get(ARG_YTOP);
|
||||||
|
if(val != null)
|
||||||
|
ytop = Double.parseDouble(val);
|
||||||
|
val = parms.get(ARG_YBOTTOM);
|
||||||
|
if(val != null)
|
||||||
|
ybottom = Double.parseDouble(val);
|
||||||
|
marker.setLineStyle(sweight, sopacity, scolor);
|
||||||
|
marker.setFillStyle(fopacity, fcolor);
|
||||||
|
if(ytop >= ybottom)
|
||||||
|
marker.setRangeY(ytop, ybottom);
|
||||||
|
else
|
||||||
|
marker.setRangeY(ybottom, ytop);
|
||||||
|
} catch (NumberFormatException nfx) {
|
||||||
|
sender.sendMessage("Invalid parameter format: " + val);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private static final Set<String> commands = new HashSet<String>(Arrays.asList(new String[] {
|
private static final Set<String> commands = new HashSet<String>(Arrays.asList(new String[] {
|
||||||
"add", "movehere", "update", "delete", "list", "icons", "addset", "updateset", "deleteset", "listsets", "addicon", "updateicon",
|
"add", "movehere", "update", "delete", "list", "icons", "addset", "updateset", "deleteset", "listsets", "addicon", "updateicon",
|
||||||
|
|
@ -486,6 +531,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
private static final String ARG_STROKEOPACITY = "opacity";
|
private static final String ARG_STROKEOPACITY = "opacity";
|
||||||
private static final String ARG_FILLCOLOR = "fillcolor";
|
private static final String ARG_FILLCOLOR = "fillcolor";
|
||||||
private static final String ARG_FILLOPACITY = "fillopacity";
|
private static final String ARG_FILLOPACITY = "fillopacity";
|
||||||
|
private static final String ARG_YTOP = "ytop";
|
||||||
|
private static final String ARG_YBOTTOM = "ybottom";
|
||||||
|
|
||||||
/* Parse argument strings : handle 'attrib:value' and quoted strings */
|
/* Parse argument strings : handle 'attrib:value' and quoted strings */
|
||||||
private static Map<String,String> parseArgs(String[] args, CommandSender snd) {
|
private static Map<String,String> parseArgs(String[] args, CommandSender snd) {
|
||||||
|
|
@ -1188,6 +1235,9 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
sender.sendMessage("Error creating area");
|
sender.sendMessage("Error creating area");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Process additional attributes, if any */
|
||||||
|
processAreaArgs(sender, m, parms);
|
||||||
|
|
||||||
sender.sendMessage("Added area id:'" + m.getMarkerID() + "' (" + m.getLabel() + ") to set '" + set.getMarkerSetID() + "'");
|
sender.sendMessage("Added area id:'" + m.getMarkerID() + "' (" + m.getLabel() + ") to set '" + set.getMarkerSetID() + "'");
|
||||||
api.pointaccum.remove(pid); /* Clear corner list */
|
api.pointaccum.remove(pid); /* Clear corner list */
|
||||||
}
|
}
|
||||||
|
|
@ -1308,34 +1358,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
if(newlabel != null) { /* Label set? */
|
if(newlabel != null) { /* Label set? */
|
||||||
marker.setLabel(newlabel);
|
marker.setLabel(newlabel);
|
||||||
}
|
}
|
||||||
int scolor = marker.getLineColor();
|
if(!processAreaArgs(sender,marker, parms))
|
||||||
int fcolor = marker.getFillColor();
|
|
||||||
double sopacity = marker.getLineOpacity();
|
|
||||||
double fopacity = marker.getFillOpacity();
|
|
||||||
int sweight = marker.getLineWeight();
|
|
||||||
val = null;
|
|
||||||
try {
|
|
||||||
val = parms.get(ARG_STROKECOLOR);
|
|
||||||
if(val != null)
|
|
||||||
scolor = Integer.parseInt(val, 16);
|
|
||||||
val = parms.get(ARG_FILLCOLOR);
|
|
||||||
if(val != null)
|
|
||||||
fcolor = Integer.parseInt(val, 16);
|
|
||||||
val = parms.get(ARG_STROKEOPACITY);
|
|
||||||
if(val != null)
|
|
||||||
sopacity = Double.parseDouble(val);
|
|
||||||
val = parms.get(ARG_FILLOPACITY);
|
|
||||||
if(val != null)
|
|
||||||
fopacity = Double.parseDouble(val);
|
|
||||||
val = parms.get(ARG_STROKEWEIGHT);
|
|
||||||
if(val != null)
|
|
||||||
sweight = Integer.parseInt(val);
|
|
||||||
marker.setLineStyle(sweight, sopacity, scolor);
|
|
||||||
marker.setFillStyle(fopacity, fcolor);
|
|
||||||
} catch (NumberFormatException nfx) {
|
|
||||||
sender.sendMessage("Invalid parameter format: " + val);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
sender.sendMessage("Updated area id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
|
sender.sendMessage("Updated area id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -1399,8 +1423,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||||
mdata.put("ytop", m.getTopY());
|
mdata.put("ytop", m.getTopY());
|
||||||
mdata.put("ybottom", m.getBottomY());
|
mdata.put("ybottom", m.getBottomY());
|
||||||
mdata.put("z", zz);
|
mdata.put("z", zz);
|
||||||
mdata.put("color", String.format("#%06x", m.getLineColor()));
|
mdata.put("color", String.format("#%06X", m.getLineColor()));
|
||||||
mdata.put("fillcolor", String.format("#%06x", m.getFillColor()));
|
mdata.put("fillcolor", String.format("#%06X", m.getFillColor()));
|
||||||
mdata.put("opacity", m.getLineOpacity());
|
mdata.put("opacity", m.getLineOpacity());
|
||||||
mdata.put("fillopacity", m.getFillOpacity());
|
mdata.put("fillopacity", m.getFillOpacity());
|
||||||
mdata.put("weight", m.getLineWeight());
|
mdata.put("weight", m.getLineWeight());
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
$.each(data.sets, function(name, markerset) {
|
$.each(data.sets, function(name, markerset) {
|
||||||
var ms = dynmapmarkersets[name];
|
var ms = dynmapmarkersets[name];
|
||||||
if(!ms) {
|
if(!ms) {
|
||||||
ms = { id: name, label: markerset.label, hide: markerset.hide, layerprio: markerset.layerprio, markers: {} } ;
|
ms = { id: name, label: markerset.label, hide: markerset.hide, layerprio: markerset.layerprio, markers: {}, areas: {} } ;
|
||||||
createMarkerSet(ms, ts);
|
createMarkerSet(ms, ts);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
@ -31,6 +31,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
dynmap.addToLayerSelector(ms.layergroup, ms.label, ms.layerprio || 0);
|
dynmap.addToLayerSelector(ms.layergroup, ms.label, ms.layerprio || 0);
|
||||||
}
|
}
|
||||||
ms.markers = {};
|
ms.markers = {};
|
||||||
|
ms.areas = {};
|
||||||
ms.hide = markerset.hide;
|
ms.hide = markerset.hide;
|
||||||
ms.timestamp = ts;
|
ms.timestamp = ts;
|
||||||
}
|
}
|
||||||
|
|
@ -40,6 +41,12 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
icon: marker.icon, desc: marker.desc };
|
icon: marker.icon, desc: marker.desc };
|
||||||
createMarker(ms, ms.markers[mname], ts);
|
createMarker(ms, ms.markers[mname], ts);
|
||||||
});
|
});
|
||||||
|
$.each(markerset.areas, function(aname, area) {
|
||||||
|
ms.areas[aname] = { label: area.label, markup: area.markup, desc: area.desc, x: area.x, z: area.z,
|
||||||
|
ytop: area.ytop, ybottom: area.ybottom, color: area.color, weight: area.weight, opacity: area.opacity,
|
||||||
|
fillcolor: area.fillcolor, fillopacity: area.fillopacity };
|
||||||
|
createArea(ms, ms.areas[aname], ts);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -92,6 +99,41 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createArea(set, area, ts) {
|
||||||
|
var style = { color: area.color, opacity: area.opacity, weight: area.weight, fillOpacity: area.fillopacity, fillColor: area.fillcolor };
|
||||||
|
|
||||||
|
if(area.x.length == 2) { /* Only 2 points */
|
||||||
|
if(area.ytop == area.ybottom) {
|
||||||
|
area.our_area = create2DBoxLayer(area.x[0], area.x[1], area.ytop, area.ybottom, area.z[0], area.z[1], style);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
area.our_area = create3DBoxLayer(area.x[0], area.x[1], area.ytop, area.ybottom, area.z[0], area.z[1], style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(area.ytop == area.ybottom) {
|
||||||
|
area.our_area = create2DOutlineLayer(area.x, area.ytop, area.ybottom, area.z, style);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
area.our_area = create3DOutlineLayer(area.x, area.ytop, area.ybottom, area.z, style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
area.timestamp = ts;
|
||||||
|
var popup = document.createElement('div');
|
||||||
|
if(area.desc) {
|
||||||
|
$(popup).addClass('AreaPopup').append(area.desc);
|
||||||
|
}
|
||||||
|
else if(area.markup) {
|
||||||
|
$(popup).addClass('AreaPopup').append(area.label);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$(popup).text(area.label);
|
||||||
|
}
|
||||||
|
area.our_area.bindPopup(popup, {});
|
||||||
|
|
||||||
|
set.layergroup.addLayer(area.our_area);
|
||||||
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
latlng = function(x, y, z) {
|
latlng = function(x, y, z) {
|
||||||
return dynmap.getProjection().fromLocationToLatLng(new Location(undefined, x,y,z));
|
return dynmap.getProjection().fromLocationToLatLng(new Location(undefined, x,y,z));
|
||||||
|
|
@ -182,7 +224,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
}
|
}
|
||||||
marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label, markup: msg.markup, desc: msg.desc };
|
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, msg.timestamp);
|
||||||
}
|
}
|
||||||
else if(msg.msg == 'markerdeleted') {
|
else if(msg.msg == 'markerdeleted') {
|
||||||
var marker = dynmapmarkersets[msg.set].markers[msg.id];
|
var marker = dynmapmarkersets[msg.set].markers[msg.id];
|
||||||
|
|
@ -215,6 +257,24 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
delete dynmapmarkersets[msg.id];
|
delete dynmapmarkersets[msg.id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(msg.msg == 'areaupdated') {
|
||||||
|
var area = dynmapmarkersets[msg.set].areas[msg.id];
|
||||||
|
if(area && area.our_area) {
|
||||||
|
dynmapmarkersets[msg.set].layergroup.removeLayer(area.our_area);
|
||||||
|
delete area.our_area;
|
||||||
|
}
|
||||||
|
area = { x: msg.x, ytop: msg.ytop, ybottom: msg.ybottom, z: msg.z, label: msg.label, markup: msg.markup, desc: msg.desc,
|
||||||
|
color: msg.color, weight: msg.weight, opacity: msg.opacity, fillcolor: msg.fillcolor, fillopacity: msg.fillopacity };
|
||||||
|
dynmapmarkersets[msg.set].areas[msg.id] = area;
|
||||||
|
createArea(dynmapmarkersets[msg.set], area, msg.timestamp);
|
||||||
|
}
|
||||||
|
else if(msg.msg == 'areadeleted') {
|
||||||
|
var area = dynmapmarkersets[msg.set].areas[msg.id];
|
||||||
|
if(area && area.our_area) {
|
||||||
|
dynmapmarkersets[msg.set].layergroup.removeLayer(area.our_area);
|
||||||
|
}
|
||||||
|
delete dynmapmarkersets[msg.set].areas[msg.id];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove marker on start of map change
|
// Remove marker on start of map change
|
||||||
|
|
@ -223,6 +283,9 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
$.each(set.markers, function(mname, marker) {
|
$.each(set.markers, function(mname, marker) {
|
||||||
set.layergroup.removeLayer(marker.our_marker);
|
set.layergroup.removeLayer(marker.our_marker);
|
||||||
});
|
});
|
||||||
|
$.each(set.areas, function(aname, area) {
|
||||||
|
set.layergroup.removeLayer(area.our_area);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Remove marker on map change - let update place it again
|
// Remove marker on map change - let update place it again
|
||||||
|
|
@ -235,6 +298,9 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||||
if(dynmap.map.hasLayer(marker.our_marker) == false)
|
if(dynmap.map.hasLayer(marker.our_marker) == false)
|
||||||
set.layergroup.addLayer(marker.our_marker);
|
set.layergroup.addLayer(marker.our_marker);
|
||||||
});
|
});
|
||||||
|
$.each(set.areas, function(aname, area) {
|
||||||
|
createArea(set, area, area.timestamp);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// Load markers for new world
|
// Load markers for new world
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue