Complete area marker API, command line and UI support

This commit is contained in:
Mike Primm 2011-10-22 16:02:41 -05:00
parent 4ff0819230
commit 804fa769a2
2 changed files with 133 additions and 43 deletions

View File

@ -99,11 +99,11 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
public double ytop, ybottom;
public double[] x;
public double[] z;
public int strokeWeight;
public double strokeOpacity;
public int strokeColor;
public double fillOpacity;
public int fillColor;
public int weight;
public double opacity;
public String color;
public double fillopacity;
public String fillcolor;
public String id;
public String label;
public String set;
@ -120,17 +120,17 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
x[i] = m.getCornerX(i);
z[i] = m.getCornerZ(i);
}
strokeColor = m.getLineColor();
strokeWeight = m.getLineWeight();
strokeOpacity = m.getFillOpacity();
fillColor = m.getFillColor();
fillOpacity = m.getFillOpacity();
color = String.format("#%06X", m.getLineColor());
weight = m.getLineWeight();
opacity = m.getLineOpacity();
fillcolor = String.format("#%06X", m.getFillColor());
fillopacity = m.getFillOpacity();
this.set = m.getMarkerSet().getMarkerSetID();
if(deleted)
msg = "areamarkerdeleted";
msg = "areadeleted";
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 */
}
}
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[] {
"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_FILLCOLOR = "fillcolor";
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 */
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");
}
else {
/* Process additional attributes, if any */
processAreaArgs(sender, m, parms);
sender.sendMessage("Added area id:'" + m.getMarkerID() + "' (" + m.getLabel() + ") to set '" + set.getMarkerSetID() + "'");
api.pointaccum.remove(pid); /* Clear corner list */
}
@ -1308,34 +1358,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
if(newlabel != null) { /* Label set? */
marker.setLabel(newlabel);
}
int scolor = marker.getLineColor();
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);
if(!processAreaArgs(sender,marker, parms))
return true;
}
sender.sendMessage("Updated area id:" + marker.getMarkerID() + " (" + marker.getLabel() + ")");
}
else {
@ -1399,8 +1423,8 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
mdata.put("ytop", m.getTopY());
mdata.put("ybottom", m.getBottomY());
mdata.put("z", zz);
mdata.put("color", String.format("#%06x", m.getLineColor()));
mdata.put("fillcolor", String.format("#%06x", m.getFillColor()));
mdata.put("color", String.format("#%06X", m.getLineColor()));
mdata.put("fillcolor", String.format("#%06X", m.getFillColor()));
mdata.put("opacity", m.getLineOpacity());
mdata.put("fillopacity", m.getFillOpacity());
mdata.put("weight", m.getLineWeight());

View File

@ -20,7 +20,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
$.each(data.sets, function(name, markerset) {
var ms = dynmapmarkersets[name];
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);
}
else {
@ -31,6 +31,7 @@ componentconstructors['markers'] = function(dynmap, configuration) {
dynmap.addToLayerSelector(ms.layergroup, ms.label, ms.layerprio || 0);
}
ms.markers = {};
ms.areas = {};
ms.hide = markerset.hide;
ms.timestamp = ts;
}
@ -40,6 +41,12 @@ componentconstructors['markers'] = function(dynmap, configuration) {
icon: marker.icon, desc: marker.desc };
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
latlng = function(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 };
dynmapmarkersets[msg.set].markers[msg.id] = marker;
createMarker(dynmapmarkersets[msg.set], marker);
createMarker(dynmapmarkersets[msg.set], marker, msg.timestamp);
}
else if(msg.msg == 'markerdeleted') {
var marker = dynmapmarkersets[msg.set].markers[msg.id];
@ -215,6 +257,24 @@ componentconstructors['markers'] = function(dynmap, configuration) {
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
@ -223,6 +283,9 @@ componentconstructors['markers'] = function(dynmap, configuration) {
$.each(set.markers, function(mname, 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
@ -235,6 +298,9 @@ componentconstructors['markers'] = function(dynmap, configuration) {
if(dynmap.map.hasLayer(marker.our_marker) == false)
set.layergroup.addLayer(marker.our_marker);
});
$.each(set.areas, function(aname, area) {
createArea(set, area, area.timestamp);
});
});
});
// Load markers for new world