diff --git a/examples/utfgrid.html b/examples/utfgrid.html index c176c987b3..adedf6058e 100644 --- a/examples/utfgrid.html +++ b/examples/utfgrid.html @@ -6,7 +6,6 @@ OpenLayers UTFGrid Demo - @@ -15,105 +14,38 @@

OpenLayers Multiple UTFGrid Demo

- This page demonstrates the use of the OpenLayers UTFGrid Controls with more than one UTFGrid Layer. + This page demonstrates the use of the OpenLayers UTFGrid Controls with + more than one UTFGrid Layer.
-
+
+
+

+ This example demonstrates the use of two separate UTFGrid layers. + See the utfgrid_twogrids.js source + for detail on how this is done. +

+
+ + diff --git a/examples/utfgrid_twogrids.js b/examples/utfgrid_twogrids.js new file mode 100644 index 0000000000..05f5eb08de --- /dev/null +++ b/examples/utfgrid_twogrids.js @@ -0,0 +1,70 @@ +var osm = new OpenLayers.Layer.OSM(); + +var population = new OpenLayers.Layer.UTFGrid( + "World Population", + "./utfgrid/world_utfgrid/${z}/${x}/${y}.json", + {utfgridResolution: 4} // default is 2 +); +var bioregions = new OpenLayers.Layer.UTFGrid( + "World Bioregions", + "./utfgrid/bio_utfgrid/${z}/${x}/${y}.json", + {utfgridResolution: 4} // default is 2 +); + +var map = new OpenLayers.Map({ + div: "map", + projection: "EPSG:900913", + controls: [], + layers: [osm, population, bioregions], + center: [0, 0], + zoom: 1 +}); + +var callback = function(infoLookup) { + var msg = ""; + if (infoLookup) { + var layer, info; + for (var idx in infoLookup) { + layer = map.layers[idx]; + info = infoLookup[idx]; + if (info && info.data) { + msg += "" + layer.name + "
"; + msg += "feature id: " + info.id + "
"; + for (var key in info.data) { + msg += key + ": " + info.data[key] + "
"; + } + } + } + } + document.getElementById("attrsdiv").innerHTML = msg; +}; + +var controls = { + move_pop: new OpenLayers.Control.UTFGrid({ + callback: callback, + layers: [population], + handlerMode: "move" + }), + move_bio: new OpenLayers.Control.UTFGrid({ + callback: callback, + layers: [bioregions], + handlerMode: "move" + }), + move_both: new OpenLayers.Control.UTFGrid({ + callback: callback, + layers: null, // same as all map.layers + handlerMode: "move" + }) +}; + +for (var key in controls) { + map.addControl(controls[key]); +} + +function toggleControl(el) { + for (var c in controls) { + controls[c].deactivate(); + } + controls[el.value].activate(); +} +toggleControl({value: "move_pop"});