diff options
author | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
---|---|---|
committer | Chris Schlaeger <chris@linux.com> | 2014-08-12 21:56:44 +0200 |
commit | ea346a785dc1b3f7c156f6fc33da634e1f1a627b (patch) | |
tree | af67530553d20b6e82ad60fd79593e9c4abf5565 /misc/openlayers/tests/Events/featureclick.html | |
parent | 59741cd535c47f25971bf8c32b25da25ceadc6d5 (diff) | |
download | postrunner-0.0.4.zip |
Adding jquery, flot and openlayers to be included with the GEM.v0.0.4
Diffstat (limited to 'misc/openlayers/tests/Events/featureclick.html')
-rw-r--r-- | misc/openlayers/tests/Events/featureclick.html | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/misc/openlayers/tests/Events/featureclick.html b/misc/openlayers/tests/Events/featureclick.html new file mode 100644 index 0000000..ae111b7 --- /dev/null +++ b/misc/openlayers/tests/Events/featureclick.html @@ -0,0 +1,91 @@ +<html> +<head> +<script src="../OLLoader.js"></script> +<script type="text/javascript"> + +var layer1, style, logevt, lognoevt, map, lonlat, pixel, element; + +function init() { + + element = document.getElementById("map"); + + style = new OpenLayers.StyleMap({ + 'default': OpenLayers.Util.applyDefaults( + {label: "${l}", pointRadius: 30}, + OpenLayers.Feature.Vector.style["default"] + ), + 'select': OpenLayers.Util.applyDefaults( + {pointRadius: 30}, + OpenLayers.Feature.Vector.style.select + ) + }); + + layer1 = new OpenLayers.Layer.Vector("Layer 1", { + styleMap: style + }); + + layer1.addFeatures([ + new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(0 0)"), {l:1}), + new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(0 0)"), {l:1}), + new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(0 0)"), {l:1}), + new OpenLayers.Feature.Vector(OpenLayers.Geometry.fromWKT("POINT(0 0)"), {l:1}) + ]); + + map = new OpenLayers.Map({ + div: "map", + allOverlays: true, + layers: [layer1], + zoom: 6, + center: [0, 0], + eventListeners: { + featureclick: logEvent, + nofeatureclick: logNoEvent + } + }); +} + +function logNoEvent(e) { + lognoevt.push(e); +} + +function logEvent(e) { + logevt.push(e); +} + +function trigger(type, pxl) { + var map_position = OpenLayers.Util.pagePosition(element); + map.events.triggerEvent(type, { + xy: pxl, + clientX: pxl.x + map_position[0], + clientY: pxl.y + map_position[1], + which: 1 // which == 1 means left-click + }); +} + +// TESTS + +function test_onClick(t) { + t.plan(2); + logevt = []; + lognoevt = []; + lonlat = new OpenLayers.LonLat(0,0); + pixel = map.getPixelFromLonLat(lonlat); + + trigger('mousedown', pixel); + trigger('mouseup', pixel); + + t.eq(logevt.length, 4, "4 features hit"); + + trigger('mousedown', {x: 40, y: 40}); + trigger('mouseup', {x: 40, y: 40}); + t.eq(lognoevt.length, 1, "nofeatureclick fired for click outside features."); +} + +// END TESTS + +</script> +</head> +<body onload="init()"> +<div id="map" style="width: 300px; height: 150px; border: 1px solid black"></div> +</body> +</html> |