mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-28 13:15:30 +01:00
Add sorting and ordering controls for layer control (layerprio attribute)
This commit is contained in:
parent
36ea3c20ca
commit
afc6f429f0
@ -101,4 +101,12 @@ public interface MarkerSet {
|
||||
* @return true if layer for set will be hidden by default
|
||||
*/
|
||||
public boolean getHideByDefault();
|
||||
/**
|
||||
* Set layer ordering priority (0=default, low before high in layer order)
|
||||
*/
|
||||
public void setLayerPriority(int prio);
|
||||
/**
|
||||
* Get layer ordering priority (0=default, low before high in layer order)
|
||||
*/
|
||||
public int getLayerPriority();
|
||||
}
|
||||
|
@ -424,6 +424,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
private static final String ARG_HIDE = "hide";
|
||||
private static final String ARG_ICON = "icon";
|
||||
private static final String ARG_SET = "set";
|
||||
private static final String ARG_PRIO = "prio";
|
||||
|
||||
/* Parse argument strings : handle 'attrib:value' and quoted strings */
|
||||
private static Map<String,String> parseArgs(String[] args, CommandSender snd) {
|
||||
@ -487,7 +488,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
|
||||
|
||||
public static boolean onCommand(DynmapPlugin plugin, CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
||||
String id, setid, file, label, newlabel, iconid;
|
||||
String id, setid, file, label, newlabel, iconid, prio;
|
||||
|
||||
if(api == null) {
|
||||
sender.sendMessage("Markers component is not enabled.");
|
||||
@ -734,6 +735,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
if(parms == null) return true;
|
||||
id = parms.get(ARG_ID);
|
||||
label = parms.get(ARG_LABEL);
|
||||
prio = parms.get(ARG_PRIO);
|
||||
if((id == null) && (label == null)) {
|
||||
sender.sendMessage("<label> or id:<marker-id> required");
|
||||
return true;
|
||||
@ -757,6 +759,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
String h = parms.get(ARG_HIDE);
|
||||
if((h != null) && (h.equals("true")))
|
||||
set.setHideByDefault(true);
|
||||
if(prio != null) {
|
||||
try {
|
||||
set.setLayerPriority(Integer.valueOf(prio));
|
||||
} catch (NumberFormatException nfx) {
|
||||
sender.sendMessage("Invalid priority: " + prio);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("Added marker set id:'" + set.getMarkerSetID() + "' (" + set.getMarkerSetLabel() + ")");
|
||||
}
|
||||
}
|
||||
@ -771,6 +780,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
if(parms == null) return true;
|
||||
id = parms.get(ARG_ID);
|
||||
label = parms.get(ARG_LABEL);
|
||||
prio = parms.get(ARG_PRIO);
|
||||
if((id == null) && (label == null)) {
|
||||
sender.sendMessage("<label> or id:<marker-id> required");
|
||||
return true;
|
||||
@ -804,6 +814,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
if(hide != null) {
|
||||
set.setHideByDefault(hide.equals("true"));
|
||||
}
|
||||
if(prio != null) {
|
||||
try {
|
||||
set.setLayerPriority(Integer.valueOf(prio));
|
||||
} catch (NumberFormatException nfx) {
|
||||
sender.sendMessage("Invalid priority: " + prio);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("Marker set '" + set.getMarkerSetID() + "' updated");
|
||||
}
|
||||
else {
|
||||
@ -855,7 +872,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
Set<String> setids = new TreeSet<String>(api.markersets.keySet());
|
||||
for(String s : setids) {
|
||||
MarkerSet set = api.markersets.get(s);
|
||||
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide=" + set.getHideByDefault());
|
||||
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide:" + set.getHideByDefault() + ", prio:" + set.getLayerPriority());
|
||||
}
|
||||
}
|
||||
/* Add new icon */
|
||||
@ -1025,6 +1042,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
HashMap<String, Object> msdata = new HashMap<String, Object>();
|
||||
msdata.put("label", ms.getMarkerSetLabel());
|
||||
msdata.put("hide", ms.getHideByDefault());
|
||||
msdata.put("layerprio", ms.getLayerPriority());
|
||||
HashMap<String, Object> markers = new HashMap<String, Object>();
|
||||
for(Marker m : ms.getMarkers()) {
|
||||
if(m.getWorld().equals(wname) == false) continue;
|
||||
|
@ -22,6 +22,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
private HashMap<String, MarkerIconImpl> allowedicons = null;
|
||||
private boolean hide_by_def;
|
||||
private boolean ispersistent;
|
||||
private int prio = 0;
|
||||
|
||||
MarkerSetImpl(String id) {
|
||||
setid = id;
|
||||
@ -215,6 +216,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
}
|
||||
setnode.put("markers", node);
|
||||
setnode.put("hide", hide_by_def);
|
||||
setnode.put("layerprio", prio);
|
||||
return setnode;
|
||||
}
|
||||
|
||||
@ -248,6 +250,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
}
|
||||
}
|
||||
hide_by_def = node.getBoolean("hide", false);
|
||||
prio = node.getInt("layerprio", 0);
|
||||
ispersistent = true;
|
||||
|
||||
return true;
|
||||
@ -265,4 +268,18 @@ class MarkerSetImpl implements MarkerSet {
|
||||
public boolean getHideByDefault() {
|
||||
return hide_by_def;
|
||||
}
|
||||
@Override
|
||||
public void setLayerPriority(int prio) {
|
||||
if(this.prio != prio) {
|
||||
this.prio = prio;
|
||||
MarkerAPIImpl.markerSetUpdated(this, MarkerUpdate.UPDATED);
|
||||
if(ispersistent)
|
||||
MarkerAPIImpl.saveMarkers();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getLayerPriority() {
|
||||
return this.prio;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -71,6 +71,8 @@ components:
|
||||
smallplayerfaces: false
|
||||
# # Optional - make player faces layer hidden by default
|
||||
# hidebydefault: true
|
||||
# # Optional - ordering priority in layer menu (low goes before high - default is 0)
|
||||
# layerprio: 1
|
||||
#- class: org.dynmap.ClientComponent
|
||||
# type: digitalclock
|
||||
- class: org.dynmap.ClientComponent
|
||||
@ -114,6 +116,8 @@ components:
|
||||
# strokeColor: "#00FF00"
|
||||
# # Optional - make layer hidden by default
|
||||
# hidebydefault: true
|
||||
# # Optional - ordering priority in layer menu (low goes before high - default is 0)
|
||||
# layerprio: 1
|
||||
|
||||
#- class: org.dynmap.regions.RegionsComponent
|
||||
# type: regions
|
||||
@ -147,6 +151,8 @@ components:
|
||||
# strokeColor: "#007F00"
|
||||
# # Optional - make layer hidden by default
|
||||
# hidebydefault: true
|
||||
# # Optional - ordering priority in layer menu (low goes before high - default is 0)
|
||||
# layerprio: 1
|
||||
|
||||
#- class: org.dynmap.regions.RegionsComponent
|
||||
# type: regions
|
||||
@ -202,6 +208,8 @@ components:
|
||||
# strokeColor: "#00FF00"
|
||||
# # Optional - make layer hidden by default
|
||||
# hidebydefault: true
|
||||
# # Optional - ordering priority in layer menu (low goes before high - default is 0)
|
||||
# layerprio: 1
|
||||
|
||||
#- class: org.dynmap.TestComponent
|
||||
# stuff: "This is some configuration-value"
|
||||
|
@ -698,6 +698,46 @@ DynMap.prototype = {
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
layersetlist: [],
|
||||
|
||||
addToLayerSelector: function(layer, name, priority) {
|
||||
var me = this;
|
||||
var i;
|
||||
for(i = 0; i < me.layersetlist.length; i++) {
|
||||
if(me.layersetlist[i].layer === layer) {
|
||||
me.layersetlist[i].priority = priority;
|
||||
me.layersetlist[i].name = name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(i >= me.layersetlist.length) {
|
||||
me.layersetlist[i] = { layer: layer, priority: priority, name: name };
|
||||
}
|
||||
me.layersetlist.sort(function(a, b) {
|
||||
if(a.priority != b.priority)
|
||||
return a.priority - b.priority;
|
||||
else
|
||||
return ((a.name < b.name) ? -1 : ((a.name > b.name) ? 1 : 0));
|
||||
});
|
||||
for(i = 0; i < me.layersetlist.length; i++) {
|
||||
me.layercontrol.removeLayer(me.layersetlist[i].layer);
|
||||
}
|
||||
for(i = 0; i < me.layersetlist.length; i++) {
|
||||
me.layercontrol.addOverlay(me.layersetlist[i].layer, me.layersetlist[i].name);
|
||||
}
|
||||
},
|
||||
removeFromLayerSelector: function(layer) {
|
||||
var me = this;
|
||||
var i;
|
||||
for(i = 0; i < me.layersetlist.length; i++) {
|
||||
if(me.layersetlist[i].layer === layer) {
|
||||
me.layersetlist.splice(i, 1);
|
||||
me.layercontrol.removeLayer(layer);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Enable hash-links.
|
||||
/* updateLink: function() {
|
||||
|
@ -20,14 +20,15 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
$.each(data.sets, function(name, markerset) {
|
||||
var ms = dynmapmarkersets[name];
|
||||
if(!ms) {
|
||||
ms = { label: markerset.label, hide: markerset.hide, markers: {} } ;
|
||||
ms = { label: markerset.label, hide: markerset.hide, layerprio: markerset.layerprio, markers: {} } ;
|
||||
createMarkerSet(ms, ts);
|
||||
}
|
||||
else {
|
||||
if(ms.label != markerset.label) {
|
||||
ms.label = markerset.label;
|
||||
dynmap.layercontrol.removeLayer(ms.layergroup);
|
||||
dynmap.layercontrol.addOverlay(ms.layergroup, ms.label);
|
||||
//dynmap.layercontrol.removeLayer(ms.layergroup);
|
||||
//dynmap.layercontrol.addOverlay(ms.layergroup, ms.label);
|
||||
dynmap.addToLayerSelector(ms.layergroup, ms.label, ms.layerprio || 0);
|
||||
}
|
||||
ms.markers = {};
|
||||
ms.hide = markerset.hide;
|
||||
@ -73,7 +74,9 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
set.timestamp = ts;
|
||||
if(!set.hide)
|
||||
dynmap.map.addLayer(set.layergroup);
|
||||
dynmap.layercontrol.addOverlay(set.layergroup, set.label);
|
||||
// dynmap.layercontrol.addOverlay(set.layergroup, set.label);
|
||||
dynmap.addToLayerSelector(set.layergroup, set.label, set.layerprio || 0);
|
||||
|
||||
}
|
||||
|
||||
$(dynmap).bind('component.markers', function(event, msg) {
|
||||
@ -96,20 +99,24 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
}
|
||||
else if(msg.msg == 'setupdated') {
|
||||
if(!dynmapmarkersets[msg.id]) {
|
||||
dynmapmarkersets[msg.id] = { label: msg.label, markers:{} };
|
||||
dynmapmarkersets[msg.id] = { label: msg.label, layerprio: msg.layerprio, markers:{} };
|
||||
createMarkerSet(dynmapmarkersets[msg.id]);
|
||||
}
|
||||
else {
|
||||
if(dynmapmarkersets[msg.id].label != msg.label) {
|
||||
dynmapmarkersets[msg.id].label = msg.label;
|
||||
dynmap.layercontrol.removeLayer(dynmapmarkersets[msg.id].layergroup);
|
||||
dynmap.layercontrol.addOverlay(dynmapmarkersets[msg.id].layergroup, dynmapmarkersets[msg.id].label);
|
||||
//dynmap.layercontrol.removeLayer(dynmapmarkersets[msg.id].layergroup);
|
||||
//dynmap.layercontrol.addOverlay(dynmapmarkersets[msg.id].layergroup, dynmapmarkersets[msg.id].label);
|
||||
dynmap.addToLayerSelector(dynmapmarkersets[msg.id].layergroup, dynmapmarkersets[msg.id].label,
|
||||
dynmapmarkersets[msg.id].layerprio || 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(msg.msg == 'setdeleted') {
|
||||
if(dynmapmarkersets[msg.id]) {
|
||||
dynmap.layercontrol.removeLayer(dynmapmarkersets[msg.id].layergroup);
|
||||
//dynmap.layercontrol.removeLayer(dynmapmarkersets[msg.id].layergroup);
|
||||
dynmap.removeFromLayerSelector(dynmapmarkersets[msg.id].layergroup);
|
||||
delete dynmapmarkersets[msg.id].layergroup;
|
||||
delete dynmapmarkersets[msg.id];
|
||||
}
|
||||
|
@ -130,5 +130,6 @@ componentconstructors['playermarkers'] = function(dynmap, configuration) {
|
||||
dynmap.playermarkergroup = new L.LayerGroup();
|
||||
if(!configuration.hidebydefault)
|
||||
dynmap.map.addLayer(dynmap.playermarkergroup);
|
||||
dynmap.layercontrol.addOverlay(dynmap.playermarkergroup, 'Players');
|
||||
//dynmap.layercontrol.addOverlay(dynmap.playermarkergroup, 'Players');
|
||||
dynmap.addToLayerSelector(dynmap.playermarkergroup, configuration.label || 'Players', configuration.layerprio || 0);
|
||||
};
|
||||
|
@ -190,7 +190,8 @@ componentconstructors['regions'] = function(dynmap, configuration) {
|
||||
configuration.activeLayer = regionsLayer;
|
||||
if(!configuration.hidebydefault)
|
||||
dynmap.map.addLayer(configuration.activeLayer);
|
||||
dynmap.layercontrol.addOverlay(configuration.activeLayer, regionType);
|
||||
//dynmap.layercontrol.addOverlay(configuration.activeLayer, regionType);
|
||||
dynmap.addToLayerSelector(configuration.activeLayer, regionType, configuration.layerprio || 0);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
Loading…
Reference in New Issue
Block a user