mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-11-13 05:54:40 +01:00
Add support for minzoom attribute on marker sets - hide markers below configurable zoom for each marker set
This commit is contained in:
parent
7373de85a2
commit
eafbe62c46
@ -84,6 +84,7 @@ public class MarkersComponent extends ClientComponent {
|
||||
offlineset = api.createMarkerSet(OFFLINE_PLAYERS_SETID, configuration.getString("offlinelabel", "Offline"), null, true);
|
||||
}
|
||||
offlineset.setHideByDefault(configuration.getBoolean("offlinehidebydefault", true));
|
||||
offlineset.setMinZoom(configuration.getInteger("offlineminzoom", 0));
|
||||
|
||||
offlineicon = api.getMarkerIcon(configuration.getString("offlineicon", "offlineuser"));
|
||||
|
||||
|
@ -178,9 +178,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
public String msg;
|
||||
public String id;
|
||||
public String label;
|
||||
public int layerprio;
|
||||
public int minzoom;
|
||||
public MarkerSetUpdated(MarkerSet markerset, boolean deleted) {
|
||||
this.id = markerset.getMarkerSetID();
|
||||
this.label = markerset.getMarkerSetLabel();
|
||||
this.layerprio = markerset.getLayerPriority();
|
||||
this.minzoom = markerset.getMinZoom();
|
||||
if(deleted)
|
||||
msg = "setdeleted";
|
||||
else
|
||||
@ -642,6 +646,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
private static final String ARG_ICON = "icon";
|
||||
private static final String ARG_SET = "set";
|
||||
private static final String ARG_PRIO = "prio";
|
||||
private static final String ARG_MINZOOM = "minzoom";
|
||||
private static final String ARG_STROKEWEIGHT = "weight";
|
||||
private static final String ARG_STROKECOLOR = "color";
|
||||
private static final String ARG_STROKEOPACITY = "opacity";
|
||||
@ -712,7 +717,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, prio;
|
||||
String id, setid, file, label, newlabel, iconid, prio, minzoom;
|
||||
String val;
|
||||
|
||||
if(api == null) {
|
||||
@ -961,6 +966,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
id = parms.get(ARG_ID);
|
||||
label = parms.get(ARG_LABEL);
|
||||
prio = parms.get(ARG_PRIO);
|
||||
minzoom = parms.get(ARG_MINZOOM);
|
||||
if((id == null) && (label == null)) {
|
||||
sender.sendMessage("<label> or id:<marker-id> required");
|
||||
return true;
|
||||
@ -991,6 +997,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
sender.sendMessage("Invalid priority: " + prio);
|
||||
}
|
||||
}
|
||||
if(minzoom != null) {
|
||||
try {
|
||||
set.setMinZoom(Integer.valueOf(minzoom));
|
||||
} catch (NumberFormatException nfx) {
|
||||
sender.sendMessage("Invalid max zoom out: " + minzoom);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("Added set id:'" + set.getMarkerSetID() + "' (" + set.getMarkerSetLabel() + ")");
|
||||
}
|
||||
}
|
||||
@ -1006,6 +1019,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
id = parms.get(ARG_ID);
|
||||
label = parms.get(ARG_LABEL);
|
||||
prio = parms.get(ARG_PRIO);
|
||||
minzoom = parms.get(ARG_MINZOOM);
|
||||
if((id == null) && (label == null)) {
|
||||
sender.sendMessage("<label> or id:<set-id> required");
|
||||
return true;
|
||||
@ -1046,6 +1060,13 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
sender.sendMessage("Invalid priority: " + prio);
|
||||
}
|
||||
}
|
||||
if(minzoom != null) {
|
||||
try {
|
||||
set.setMinZoom(Integer.valueOf(minzoom));
|
||||
} catch (NumberFormatException nfx) {
|
||||
sender.sendMessage("Invalid min zoom: " + minzoom);
|
||||
}
|
||||
}
|
||||
sender.sendMessage("Set '" + set.getMarkerSetID() + "' updated");
|
||||
}
|
||||
else {
|
||||
@ -1097,7 +1118,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() + ", prio:" + set.getLayerPriority());
|
||||
sender.sendMessage(set.getMarkerSetID() + ": label:\"" + set.getMarkerSetLabel() + "\", hide:" + set.getHideByDefault() + ", prio:" + set.getLayerPriority() + ", minzoom:" + set.getMinZoom());
|
||||
}
|
||||
}
|
||||
/* Add new icon */
|
||||
@ -1505,6 +1526,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener<DynmapWorld> {
|
||||
msdata.put("label", ms.getMarkerSetLabel());
|
||||
msdata.put("hide", ms.getHideByDefault());
|
||||
msdata.put("layerprio", ms.getLayerPriority());
|
||||
msdata.put("minzoom", ms.getMinZoom());
|
||||
HashMap<String, Object> markers = new HashMap<String, Object>();
|
||||
for(Marker m : ms.getMarkers()) {
|
||||
if(m.getWorld().equals(wname) == false) continue;
|
||||
|
@ -25,6 +25,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
private boolean hide_by_def;
|
||||
private boolean ispersistent;
|
||||
private int prio = 0;
|
||||
private int minzoom = 0;
|
||||
|
||||
MarkerSetImpl(String id) {
|
||||
setid = id;
|
||||
@ -250,6 +251,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
setnode.put("areas", anode);
|
||||
setnode.put("hide", hide_by_def);
|
||||
setnode.put("layerprio", prio);
|
||||
setnode.put("minzoom", minzoom);
|
||||
return setnode;
|
||||
}
|
||||
|
||||
@ -297,6 +299,7 @@ class MarkerSetImpl implements MarkerSet {
|
||||
}
|
||||
hide_by_def = node.getBoolean("hide", false);
|
||||
prio = node.getInt("layerprio", 0);
|
||||
minzoom = node.getInt("minzoom", 0);
|
||||
ispersistent = true;
|
||||
|
||||
return true;
|
||||
@ -370,4 +373,18 @@ class MarkerSetImpl implements MarkerSet {
|
||||
return match;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMinZoom(int minzoom) {
|
||||
if(this.minzoom != minzoom) {
|
||||
this.minzoom = minzoom;
|
||||
MarkerAPIImpl.markerSetUpdated(this, MarkerUpdate.UPDATED);
|
||||
if(ispersistent)
|
||||
MarkerAPIImpl.saveMarkers();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getMinZoom() {
|
||||
return this.minzoom;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ components:
|
||||
#offlinelabel: "Offline"
|
||||
#offlineicon: offlineuser
|
||||
#offlinehidebydefault: true
|
||||
#offlineminzoom: 0
|
||||
|
||||
- class: org.dynmap.ClientComponent
|
||||
type: chat
|
||||
|
@ -140,10 +140,10 @@ DynMap.prototype = {
|
||||
});
|
||||
window.map = map; // Placate Leaflet need for top-level 'map'....
|
||||
|
||||
map.zoom_changed = function() {
|
||||
me.maptype.updateTileSize(me.map.zoom);
|
||||
map.on('zoomend', function() {
|
||||
me.maptype.updateTileSize(me.map.getZoom());
|
||||
$(me).trigger('zoomchanged');
|
||||
};
|
||||
});
|
||||
|
||||
/*google.maps.event.addListener(map, 'dragstart', function(mEvent) {
|
||||
me.followPlayer(null);
|
||||
|
@ -24,7 +24,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: {}, areas: {} } ;
|
||||
ms = { id: name, label: markerset.label, hide: markerset.hide, layerprio: markerset.layerprio, minzoom: markerset.minzoom, markers: {}, areas: {} } ;
|
||||
createMarkerSet(ms, ts);
|
||||
}
|
||||
else {
|
||||
@ -92,7 +92,8 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
$(popup).addClass('MarkerPopup').append(marker.desc);
|
||||
marker.our_marker.bindPopup(popup, {});
|
||||
}
|
||||
set.layergroup.addLayer(marker.our_marker);
|
||||
if((set.minzoom < 1) || (dynmap.map.getZoom() >= set.minzoom))
|
||||
set.layergroup.addLayer(marker.our_marker);
|
||||
}
|
||||
|
||||
function createMarkerSet(set, ts) {
|
||||
@ -138,7 +139,8 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
}
|
||||
area.our_area.bindPopup(popup, {});
|
||||
}
|
||||
set.layergroup.addLayer(area.our_area);
|
||||
if((set.minzoom < 1) || (dynmap.map.getZoom() >= set.minzoom))
|
||||
set.layergroup.addLayer(area.our_area);
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
@ -242,18 +244,21 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
}
|
||||
else if(msg.msg == 'setupdated') {
|
||||
if(!dynmapmarkersets[msg.id]) {
|
||||
dynmapmarkersets[msg.id] = { id: msg.id, label: msg.label, layerprio: msg.layerprio, markers:{} };
|
||||
dynmapmarkersets[msg.id] = { id: msg.id, label: msg.label, layerprio: msg.layerprio, minzoom: msg.minzoom, markers:{} };
|
||||
createMarkerSet(dynmapmarkersets[msg.id]);
|
||||
}
|
||||
else {
|
||||
if(dynmapmarkersets[msg.id].label != msg.label) {
|
||||
if((dynmapmarkersets[msg.id].label != msg.label) || (dynmapmarkersets[msg.id].layerprio != msg.layerprio)) {
|
||||
dynmapmarkersets[msg.id].label = msg.label;
|
||||
dynmapmarkersets[msg.id].layerprio = msg.layerprio;
|
||||
//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);
|
||||
|
||||
}
|
||||
if(dynmapmarkersets[msg.id].minzoom != msg.minzoom) {
|
||||
dynmapmarkersets[msg.id].minzoom = msg.minzoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(msg.msg == 'setdeleted') {
|
||||
@ -297,19 +302,50 @@ componentconstructors['markers'] = function(dynmap, configuration) {
|
||||
});
|
||||
// Remove marker on map change - let update place it again
|
||||
$(dynmap).bind('mapchanged', function(event) {
|
||||
var zoom = dynmap.map.getZoom();
|
||||
$.each(dynmapmarkersets, function(setname, set) {
|
||||
$.each(set.markers, function(mname, marker) {
|
||||
var marker = set.markers[mname];
|
||||
var markerPosition = getPosition(marker);
|
||||
marker.our_marker.setLatLng(markerPosition);
|
||||
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);
|
||||
});
|
||||
if((set.minzoomout < 1) || (zoom >= set.minzoom)) {
|
||||
$.each(set.markers, function(mname, marker) {
|
||||
var marker = set.markers[mname];
|
||||
var markerPosition = getPosition(marker);
|
||||
marker.our_marker.setLatLng(markerPosition);
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
$(dynmap).bind('zoomchanged', function(event) {
|
||||
var zoom = dynmap.map.getZoom();
|
||||
$.each(dynmapmarkersets, function(setname, set) {
|
||||
if(set.minzoom > 0) {
|
||||
if(zoom >= set.minzoom) {
|
||||
$.each(set.markers, function(mname, marker) {
|
||||
var marker = set.markers[mname];
|
||||
var markerPosition = getPosition(marker);
|
||||
marker.our_marker.setLatLng(markerPosition);
|
||||
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);
|
||||
});
|
||||
}
|
||||
else {
|
||||
$.each(set.markers, function(mname, marker) {
|
||||
set.layergroup.removeLayer(marker.our_marker);
|
||||
});
|
||||
$.each(set.areas, function(aname, area) {
|
||||
set.layergroup.removeLayer(area.our_area);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Load markers for new world
|
||||
$(dynmap).bind('worldchanged', function(event) {
|
||||
loadmarkers(this.world.name);
|
||||
|
Loading…
Reference in New Issue
Block a user