diff --git a/config.js b/config.js
index 45534c6..d9aa1d9 100644
--- a/config.js
+++ b/config.js
@@ -10,14 +10,23 @@
};
-// define a list of pattern-label pairs. Each label will appear
-// in the 'Signposts' control, allowing your users to quickly enable
-// or disable certain labels. See below for some examples:
-var signGroups = {
-// "Directions": /^#Direction/i,
-// "Big Dig": /big\s*dig/i,
-// "Warnings": /warning/i,
-};
+/* signGroups -- A list of signpost groups. A signpost can fall into zero, one, or more than one
+ * group. See below for some examples.
+ *
+ * Required:
+ * label : string. Displayed in the drop down menu control.
+ * match : function. Applied to each marker (from markers.js). It is returns true if the marker
+ * Should be part of the group.
+ *
+ * Optional:
+ * checked : boolean. Set to true to have the group visible by default
+ */
+var signGroups = [
+// {label: "'To'", checked: false, match: function(s) {return s.msg.match(/to/)}},
+// {label: "Storage", match: function(s) {return s.msg.match(/storage/i) || s.msg.match(/dirt/i) || s.msg.match(/sand/)}},
+// {label: "Below Sealevel", match: function(s) { return s.y<64;}},
+ {label: "All", match: function(s) {return true}}
+];
// Please leave the following variables here:
var markerCollection = {}; // holds groups of markers
diff --git a/web_assets/functions.js b/web_assets/functions.js
index da098a6..07025d9 100644
--- a/web_assets/functions.js
+++ b/web_assets/functions.js
@@ -29,7 +29,7 @@ function drawMapControls() {
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(compassDiv);
- if (markerData.length > 0) {
+ if (signGroups.length > 0) {
// signpost display control
//
@@ -62,8 +62,12 @@ function drawMapControls() {
map.controls[google.maps.ControlPosition.TOP_RIGHT].push(signControl);
+
var hasSignGroup = false;
- for (label in signGroups) {
+ for (idx in signGroups) {
+ var item = signGroups[idx];
+ //console.log(item);
+ label = item.label;
hasSignGroup = true;
var d = document.createElement("div");
var n = document.createElement("input");
@@ -75,6 +79,11 @@ function drawMapControls() {
jQuery.each(markerCollection[t.data("label")], function(i,elem) {elem.setVisible(e.target.checked);});
});
+
+ if (item.checked) {
+ n.checked = true;
+ jQuery.each(markerCollection[label], function(i,elem) {elem.setVisible(n.checked);});
+ }
dropdownDiv.appendChild(d);
d.appendChild(n)
var textNode = document.createElement("text");
@@ -83,25 +92,6 @@ function drawMapControls() {
}
- // add "others"
- var n = document.createElement("input");
- n.type="checkbox";
-
- $(n).data("label","__others__");
- jQuery(n).click(function(e) {
- var t = $(e.target);
- jQuery.each(markerCollection[t.data("label")], function(i,elem) {elem.setVisible(e.target.checked);});
- });
-
- dropdownDiv.appendChild(n);
- var textNode = document.createElement("text");
- if (hasSignGroup) {
- textNode.innerHTML = "Others
";
- } else{
- textNode.innerHTML = "All
";
- }
- dropdownDiv.appendChild(textNode);
-
}
}
@@ -172,11 +162,12 @@ function initMarkers() {
}
var matched = false;
- for (label in signGroups) {
- var pattern = signGroups[label];
+ for (idx in signGroups) {
+ var signGroup = signGroups[idx];
+ var testfunc = signGroup.match;
+ var label = signGroup.label;
- var r = item.msg.match(pattern);
- if (r) {
+ if (testfunc(item)) {
matched = true;
if (item.type == 'sign') { iconURL = 'signpost_icon.png';}
@@ -246,14 +237,14 @@ function initialize() {
map.overlayMapTypes.insertAt(0, new CoordMapType(new google.maps.Size(config.tileSize, config.tileSize)));
google.maps.event.addListener(map, 'click', function(event) {
- console.log("latLng; " + event.latLng.lat() + ", " + event.latLng.lng());
+ //console.log("latLng; " + event.latLng.lat() + ", " + event.latLng.lng());
var pnt = map.getProjection().fromLatLngToPoint(event.latLng);
- console.log("point: " + pnt);
+ //console.log("point: " + pnt);
var pxx = pnt.x * config.tileSize * Math.pow(2, config.maxZoom);
var pxy = pnt.y * config.tileSize * Math.pow(2, config.maxZoom);
- console.log("pixel: " + pxx + ", " + pxy);
+ //console.log("pixel: " + pxx + ", " + pxy);
});
}