[OpenLayers-Commits] r11413 - in sandbox/cmoullet/openlayers: .
build examples lib lib/OpenLayers lib/OpenLayers/Control
lib/OpenLayers/Handler tests tests/BaseTypes tests/Control
tests/Handler tests/Layer tools
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Feb 24 08:37:57 EST 2011
Author: cmoullet
Date: 2011-02-24 05:37:57 -0800 (Thu, 24 Feb 2011)
New Revision: 11413
Added:
sandbox/cmoullet/openlayers/examples/geolocation.html
sandbox/cmoullet/openlayers/examples/geolocation.js
sandbox/cmoullet/openlayers/examples/kinetic.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Geolocate.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Pinch.js
sandbox/cmoullet/openlayers/tests/Control/Geolocate.html
sandbox/cmoullet/openlayers/tests/Handler/Pinch.html
Modified:
sandbox/cmoullet/openlayers/
sandbox/cmoullet/openlayers/build/build.py
sandbox/cmoullet/openlayers/examples/controls.html
sandbox/cmoullet/openlayers/examples/draw-feature.html
sandbox/cmoullet/openlayers/examples/kinetic.html
sandbox/cmoullet/openlayers/examples/mobile-jq.html
sandbox/cmoullet/openlayers/examples/mobile-navigation.html
sandbox/cmoullet/openlayers/examples/mobile-sencha.html
sandbox/cmoullet/openlayers/examples/mobile.html
sandbox/cmoullet/openlayers/examples/style.css
sandbox/cmoullet/openlayers/lib/OpenLayers.js
sandbox/cmoullet/openlayers/lib/OpenLayers/BaseTypes.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Measure.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Events.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Drag.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Polygon.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Kinetic.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Map.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js
sandbox/cmoullet/openlayers/tests/BaseTypes/Bounds.html
sandbox/cmoullet/openlayers/tests/BaseTypes/LonLat.html
sandbox/cmoullet/openlayers/tests/BaseTypes/Pixel.html
sandbox/cmoullet/openlayers/tests/Control/DrawFeature.html
sandbox/cmoullet/openlayers/tests/Control/Measure.html
sandbox/cmoullet/openlayers/tests/Control/PanZoom.html
sandbox/cmoullet/openlayers/tests/Control/Scale.html
sandbox/cmoullet/openlayers/tests/Control/Split.html
sandbox/cmoullet/openlayers/tests/Handler/Click.html
sandbox/cmoullet/openlayers/tests/Handler/Drag.html
sandbox/cmoullet/openlayers/tests/Handler/Path.html
sandbox/cmoullet/openlayers/tests/Handler/Point.html
sandbox/cmoullet/openlayers/tests/Handler/Polygon.html
sandbox/cmoullet/openlayers/tests/Layer/EventPane.html
sandbox/cmoullet/openlayers/tests/Map.html
sandbox/cmoullet/openlayers/tests/Util.html
sandbox/cmoullet/openlayers/tests/list-tests.html
sandbox/cmoullet/openlayers/tests/run-tests.html
sandbox/cmoullet/openlayers/tools/exampleparser.py
Log:
Merge with trunk
Property changes on: sandbox/cmoullet/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
- /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11253
+ /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11410
Modified: sandbox/cmoullet/openlayers/build/build.py
===================================================================
--- sandbox/cmoullet/openlayers/build/build.py 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/build/build.py 2011-02-24 13:37:57 UTC (rev 11413)
@@ -3,40 +3,46 @@
import sys
sys.path.append("../tools")
import mergejs
+import optparse
-def build():
- have_compressor = None
+def build(config_file = None, output_file = None, options = None):
+ have_compressor = []
try:
import jsmin
- have_compressor = "jsmin"
+ have_compressor.append("jsmin")
except ImportError:
- try:
- import minimize
- have_compressor = "minimize"
- except Exception, E:
- print E
- pass
+ print "No jsmin"
+
+ try:
+ import minimize
+ have_compressor.append("minimize")
+ except ImportError:
+ print "No minimize"
+ use_compressor = None
+ if options.compressor and options.compressor in have_compressor:
+ use_compressor = options.compressor
+
sourceDirectory = "../lib"
configFilename = "full.cfg"
outputFilename = "OpenLayers.js"
- if len(sys.argv) > 1:
- configFilename = sys.argv[1]
+ if config_file:
+ configFilename = config_file
extension = configFilename[-4:]
if extension != ".cfg":
- configFilename = sys.argv[1] + ".cfg"
+ configFilename = config_file + ".cfg"
- if len(sys.argv) > 2:
- outputFilename = sys.argv[2]
+ if output_file:
+ outputFilename = output_file
print "Merging libraries."
merged = mergejs.run(sourceDirectory, None, configFilename)
- if have_compressor == "jsmin":
+ if use_compressor == "jsmin":
print "Compressing using jsmin."
minimized = jsmin.jsmin(merged)
- elif have_compressor == "minimize":
+ elif use_compressor == "minimize":
print "Compressing using minimize."
minimized = minimize.minimize(merged)
else: # fallback
@@ -51,4 +57,7 @@
print "Done."
if __name__ == '__main__':
- build()
\ No newline at end of file
+ opt = optparse.OptionParser(usage="%s [options] [config_file] [output_file]\n Default config_file is 'full.cfg', Default output_file is 'OpenLayers.js'")
+ opt.add_option("-c", "--compressor", dest="compressor", help="compression method: one of 'jsmin', 'minimize', or 'none'", default="jsmin")
+ (options, args) = opt.parse_args()
+ build(*args, options=options)
Modified: sandbox/cmoullet/openlayers/examples/controls.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/controls.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/controls.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -64,8 +64,8 @@
Attach zooming, panning, layer switcher, overview map, and permalink map controls to an OpenLayers window.
</p>
- <a style="float:right" href="" id="permalink">Permalink</a>
<div id="map" class="smallmap"></div>
+ <a href="#" id="permalink">Permalink</a>
<div id="docs"></div>
</body>
Modified: sandbox/cmoullet/openlayers/examples/draw-feature.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/draw-feature.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/draw-feature.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -64,6 +64,14 @@
}
}
}
+
+ function allowPan(element) {
+ var stop = !element.checked;
+ for(var key in drawControls) {
+ drawControls[key].handler.stopDown = stop;
+ drawControls[key].handler.stopUp = stop;
+ }
+ }
</script>
</head>
<body onload="init()">
@@ -97,15 +105,20 @@
<input type="radio" name="type" value="polygon" id="polygonToggle" onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label>
</li>
+ <li>
+ <input type="checkbox" name="allow-pan" value="allow-pan" id="allowPanCheckbox" checked=true onclick="allowPan(this);" />
+ <label for="allowPanCheckbox">allow pan while drawing</label>
+ </li>
</ul>
<div id="docs">
- <p>With the point drawing control active, click on the map to add a point. You can drag the point
- before letting the mouse up if you want to adjust the position.</p>
+ <p>With the point drawing control active, click on the map to add a point.</p>
<p>With the line drawing control active, click on the map to add the points that make up your line.
Double-click to finish drawing.</p>
<p>With the polygon drawing control active, click on the map to add the points that make up your
polygon. Double-click to finish drawing.</p>
+ <p>With any drawing control active, paning the map can still be achieved. Drag the map as
+ usual for that.</p>
<p>Hold down the shift key while drawing to activate freehand mode. While drawing lines or polygons
in freehand mode, hold the mouse down and a point will be added with every mouse movement.<p>
</div>
Copied: sandbox/cmoullet/openlayers/examples/geolocation.html (from rev 11410, trunk/openlayers/examples/geolocation.html)
===================================================================
--- sandbox/cmoullet/openlayers/examples/geolocation.html (rev 0)
+++ sandbox/cmoullet/openlayers/examples/geolocation.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
+ <meta name="apple-mobile-web-app-capable" content="yes">
+ <title>OpenLayers Geolocation</title>
+
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
+ <link rel="stylesheet" href="style.css" type="text/css">
+ <style>
+ .olControlAttribution {
+ bottom: 3px;
+ }
+ </style>
+ </head>
+ <body>
+ <h1 id="title">Geolocation Example</h1>
+
+ <div id="tags">
+ geolocation, geolocate, mobile
+ </div>
+
+ <p id="shortdesc">
+ Track current position and display it with its accuracy.
+ </p>
+
+ <div id="map" class="smallmap"></div>
+ <button id="locate">Locate me!</button>
+ <input type="checkbox" name="track" id="track">
+ <label for="track">Track my position</label>
+ <div id="docs">
+ <p>
+ View the <a href="geolocation.js" target="_blank">geolocation.js source</a>
+ to see how this is done.
+ </p>
+ </div>
+ <script src="../lib/OpenLayers.js"></script>
+ <script src="geolocation.js"></script>
+ </body>
+</html>
Copied: sandbox/cmoullet/openlayers/examples/geolocation.js (from rev 11410, trunk/openlayers/examples/geolocation.js)
===================================================================
--- sandbox/cmoullet/openlayers/examples/geolocation.js (rev 0)
+++ sandbox/cmoullet/openlayers/examples/geolocation.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,103 @@
+var style = {
+ fillColor: '#000',
+ fillOpacity: 0.1,
+ strokeWidth: 0
+}
+
+var map = new OpenLayers.Map('map');
+var layer = new OpenLayers.Layer.OSM( "Simple OSM Map");
+var vector = new OpenLayers.Layer.Vector('vector');
+map.addLayers([layer, vector]);
+
+map.setCenter(
+ new OpenLayers.LonLat(-71.147, 42.472).transform(
+ new OpenLayers.Projection("EPSG:4326"),
+ map.getProjectionObject()
+ ), 12
+);
+
+var pulsate = function(feature) {
+ var point = feature.geometry.getCentroid(),
+ bounds = feature.geometry.getBounds(),
+ radius = Math.abs((bounds.right - bounds.left)/2),
+ count = 0,
+ grow = 'up';
+
+ var resize = function(){
+ if (count>16) clearInterval(window.resizeInterval);
+ var interval = radius * 0.03;
+ var ratio = interval/radius;
+ switch(count) {
+ case 4:
+ case 12:
+ grow = 'down'; break;
+ case 8:
+ grow = 'up'; break;
+ }
+ if (grow!=='up') {
+ ratio = - Math.abs(ratio);
+ }
+ feature.geometry.resize(1+ratio, point);
+ vector.drawFeature(feature);
+ count++;
+ }
+ window.resizeInterval = window.setInterval(resize, 50, point, radius);
+};
+
+var geolocate = new OpenLayers.Control.Geolocate({
+ geolocationOptions: {
+ enableHighAccuracy: false,
+ maximumAge: 0,
+ timeout: 7000
+ }
+});
+map.addControl(geolocate);
+geolocate.events.register("locationupdated",this,function(e) {
+ vector.removeAllFeatures();
+ var circle = new OpenLayers.Feature.Vector(
+ OpenLayers.Geometry.Polygon.createRegularPolygon(
+ new OpenLayers.Geometry.Point(e.point.x, e.point.y),
+ e.position.coords.accuracy/2,
+ 40,
+ 0
+ ),
+ {},
+ style
+ );
+ vector.addFeatures([
+ new OpenLayers.Feature.Vector(
+ e.point,
+ {},
+ {
+ graphicName: 'cross',
+ strokeColor: '#f00',
+ strokeWidth: 2,
+ fillOpacity: 0,
+ pointRadius: 10
+ }
+ ),
+ circle
+ ]);
+ map.zoomToExtent(vector.getDataExtent());
+ pulsate(circle);
+});
+geolocate.events.register("locationfailed",this,function() {
+ OpenLayers.Console.log('Location detection failed');
+});
+
+$('locate').onclick = function() {
+ vector.removeAllFeatures();
+ geolocate.deactivate();
+ $('track').checked = false;
+ geolocate.watch = false;
+ geolocate.activate();
+};
+$('track').onclick = function() {
+ vector.removeAllFeatures();
+ geolocate.deactivate();
+ if (this.checked) {
+ geolocate.watch = true;
+ geolocate.activate();
+ }
+};
+$('track').checked = false;
Modified: sandbox/cmoullet/openlayers/examples/kinetic.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/kinetic.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/kinetic.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -1,50 +1,13 @@
-<html xmlns="http://www.w3.org/1999/xhtml">
+<!DOCTYPE html>
+<html>
<head>
<title>OpenLayers Kinetic Dragging Example</title>
- <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
- <link rel="stylesheet" href="style.css" type="text/css" />
- <style type="text/css">
- #map {
- width: 100%;
- height: 100%;
- }
- </style>
- <script src="../lib/OpenLayers.js"></script>
- <script type="text/javascript">
- var map, layer;
- function init(){
- map = new OpenLayers.Map({
- div: "map",
- resolutions: [0.087890625, 0.0439453125, 0.02197265625, 0.010986328125],
- panDuration: 100,
- controls: [
- new OpenLayers.Control.Navigation(
- {dragPanOptions: {enableKinetic: true}}
- )
- ]
- });
- layer = new OpenLayers.Layer.TileCache("TileCache Layer",
- ["http://c0.tilecache.osgeo.org/wms-c/cache/",
- "http://c1.tilecache.osgeo.org/wms-c/cache/",
- "http://c2.tilecache.osgeo.org/wms-c/cache/",
- "http://c3.tilecache.osgeo.org/wms-c/cache/",
- "http://c4.tilecache.osgeo.org/wms-c/cache/"],
- "basic",
- {
- serverResolutions: [0.703125, 0.3515625, 0.17578125, 0.087890625,
- 0.0439453125, 0.02197265625, 0.010986328125,
- 0.0054931640625, 0.00274658203125, 0.001373291015625,
- 0.0006866455078125, 0.00034332275390625, 0.000171661376953125,
- 0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625],
- buffer: 4
- }
- );
- map.addLayer(layer);
- map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- }
- </script>
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
+ <meta name="apple-mobile-web-app-capable" content="yes" />
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css">
+ <link rel="stylesheet" href="style.css" type="text/css">
</head>
- <body onload="init()">
+ <body>
<h1 id="title">Kinetic Dragging Example</h1>
<div id="tags">
@@ -58,24 +21,23 @@
<div id="map" class="smallmap"></div>
<div id="docs">
-
<p>
- OpenLayers Kinetic Dragging inspired from <a href="http://www.tile5.org">Tile5</a>, and
- <a href="http://code.google.com/p/kineticscrolling/">kineticscrolling</a> for Google Maps API V3.
+ OpenLayers Kinetic Dragging inspired from <a href="http://www.tile5.org">Tile5</a>, and
+ <a href="http://code.google.com/p/kineticscrolling/">kineticscrolling</a> for Google Maps API V3.
+ </p><p>
+ As shown in this example Kinetic Dragging is enabled by setting
+ <code>enableKinetic</code> to true in the config object provided to the
+ <code>Control.DragPan</code> constructor. When using
+ <code>Control.Navigation</code> or <code>Control.TouchNavigation</code>
+ providing options to the underlying <code>Control.DragPan</code>
+ instance is done through the <code>dragPanOptions</code> config
+ property.
+ </p><p>
+ View the <a href="kinetic.js" target="_blank">kinetic.js source</a>
+ to see how this is done.
</p>
-
- <p>
-
- As shown in this example Kinetic Dragging is enabled by setting
- <code>enableKinetic</code> to true in the config object provided to the
- <code>Control.DragPan</code> constructor. When using
- <code>Control.Navigation</code> or <code>Control.TouchNavigation</code>
- providing options to the underlying <code>Control.DragPan</code>
- instance is done through the <code>dragPanOptions</code> config
- property.
-
- </p>
-
</div>
+ <script src="../lib/OpenLayers.js"></script>
+ <script src="kinetic.js"></script>
</body>
</html>
Copied: sandbox/cmoullet/openlayers/examples/kinetic.js (from rev 11410, trunk/openlayers/examples/kinetic.js)
===================================================================
--- sandbox/cmoullet/openlayers/examples/kinetic.js (rev 0)
+++ sandbox/cmoullet/openlayers/examples/kinetic.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,28 @@
+var map = new OpenLayers.Map({
+ div: "map",
+ resolutions: [0.087890625, 0.0439453125, 0.02197265625, 0.010986328125],
+ panDuration: 100,
+ controls: [
+ new OpenLayers.Control.Navigation(
+ {dragPanOptions: {enableKinetic: true}}
+ )
+ ]
+});
+var layer = new OpenLayers.Layer.TileCache("TileCache Layer",
+ ["http://c0.tilecache.osgeo.org/wms-c/cache/",
+ "http://c1.tilecache.osgeo.org/wms-c/cache/",
+ "http://c2.tilecache.osgeo.org/wms-c/cache/",
+ "http://c3.tilecache.osgeo.org/wms-c/cache/",
+ "http://c4.tilecache.osgeo.org/wms-c/cache/"],
+ "basic",
+ {
+ serverResolutions: [0.703125, 0.3515625, 0.17578125, 0.087890625,
+ 0.0439453125, 0.02197265625, 0.010986328125,
+ 0.0054931640625, 0.00274658203125, 0.001373291015625,
+ 0.0006866455078125, 0.00034332275390625, 0.000171661376953125,
+ 0.0000858306884765625, 0.00004291534423828125, 0.000021457672119140625],
+ buffer: 4
+ }
+);
+map.addLayer(layer);
+map.setCenter(new OpenLayers.LonLat(0, 0), 0);
\ No newline at end of file
Modified: sandbox/cmoullet/openlayers/examples/mobile-jq.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-jq.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/mobile-jq.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -37,7 +37,7 @@
bottom: 5px;
right: 5px;
}
- #tags {
+ #title, #tags, #shortdesc {
display: none;
}
</style>
@@ -104,9 +104,13 @@
</script>
</head>
<body>
+ <h1 id="title">OpenLayers with jQuery Mobile</h1>
<div id="tags">
mobile, jquery
</div>
+ <p id="shortdesc">
+ Using jQuery Mobile to display an OpenLayers map.
+ </p>
<div data-role="page">
<div data-role="header">
<input id="west" type="button" data-icon="arrow-l" value="west">
Modified: sandbox/cmoullet/openlayers/examples/mobile-navigation.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-navigation.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/mobile-navigation.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -3,7 +3,7 @@
<head>
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
<meta name="apple-mobile-web-app-capable" content="yes" />
- <title>OpenLayers TouchNavigation Control</title>
+ <title>Mobile Navigation Example</title>
<link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="style.mobile.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
@@ -11,20 +11,36 @@
<script type="text/javascript" src="mobile-navigation.js"></script>
</head>
<body onload="init()">
- <h1 id="title">TouchNavigation Control</h1>
+ <h1 id="title">Mobile Navigation</h1>
<div id="tags">
mobile, touch, drag, move, zoom, navigate
</div>
- <div id="shortdesc">Demonstrate TouchNavigation Control features</div>
+ <div id="shortdesc">Demonstrate map navigation on mobile</div>
<div id="map" class="smallmap"></div>
<div id="docs">
+
<p>
- This example demonstrates a couple features of the TouchNavigation
- control. The TouchNavigation control controls most map dragging,
- movement, zooming, etc, optimized for mobile devices.
+ This example demonstates what OpenLayers provides for map
+ navigation on mobile.
+ </p>
+
+ <p>
+ The TouchNavigation control allows to pan the map with touch
+ gestures on the screen – "touchstart", "touchmove",
+ "touchend" sequences. It also allows to zoom in with double taps,
+ and to zoom out with two-finger single taps. The latter is only
+ available on devices supporting multi-touch. Note that in most
+ devices Android doesn't support multi-touch in the browser.
+ </p>
+
+ <p>
+ The ZoomPanel control provides + and - buttons for zooming in and
+ out. These buttons should work on any device, and the zoom out
+ button is especially needed for devices that don't support
+ multi-touch.
</p>
<p>
See the <a href="mobile-navigation.js" target="_blank">mobile-navigation.js
Modified: sandbox/cmoullet/openlayers/examples/mobile-sencha.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-sencha.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/mobile-sencha.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -20,7 +20,7 @@
bottom: 5px;
right: 5px;
}
- #tags {
+ #title, #tags, #shortdesc {
display: none;
}
</style>
@@ -125,8 +125,12 @@
</script>
</head>
<body>
+ <h1 id="title">OpenLayers with Sencha Touch</h1>
<div id="tags">
- mobile, sencha
+ mobile, sencha touch
</div>
+ <p id="shortdesc">
+ Using Sencha Touch to display an OpenLayers map.
+ </p>
</body>
</html>
Modified: sandbox/cmoullet/openlayers/examples/mobile.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/mobile.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -23,15 +23,19 @@
bottom: 5px;
right: 5px;
}
- #tags {
+ #title, #tags, #shortdesc {
display: none;
}
</style>
</head>
<body>
+ <h1 id="title">Basic Mobile Example</h1>
<div id="tags">
mobile
</div>
+ <p id="shortdesc">
+ A basic full-screen map for mobile devices.
+ </p>
<div id="map"></div>
<script>
init();
Modified: sandbox/cmoullet/openlayers/examples/style.css
===================================================================
--- sandbox/cmoullet/openlayers/examples/style.css 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/examples/style.css 2011-02-24 13:37:57 UTC (rev 11413)
@@ -121,3 +121,19 @@
display : none;
}
}
+ at media only screen and (orientation: landscape) and (max-width: 600px) {
+ #shortdesc {
+ float: right;
+ width: 25%;
+ }
+ #map {
+ width: 70%;
+ }
+ #docs {
+ font-size: 12px;
+ }
+}
+body {
+ -webkit-text-size-adjust: none;
+}
+
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/BaseTypes.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/BaseTypes.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/BaseTypes.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -632,9 +632,11 @@
* APIMethod: parse
* Generate a date object from a string. The format for the string follows
* the profile of ISO 8601 for date and time on the Internet (see
- * http://tools.ietf.org/html/rfc3339). If the parse method on
- * the Date constructor returns a valid date for the given string,
- * that method is used.
+ * http://tools.ietf.org/html/rfc3339). We don't call the native
+ * Date.parse because of inconsistency between implmentations. In
+ * Chrome, calling Date.parse with a string that doesn't contain any
+ * indication of the timezone (e.g. "2011"), the date is interpreted
+ * in local time. On Firefox, the assumption is UTC.
*
* Parameters:
* str - {String} A string representing the date (e.g.
@@ -647,37 +649,31 @@
*/
parse: function(str) {
var date;
- // first check if the native parse method can parse it
- var elapsed = Date.parse(str);
- if (!isNaN(elapsed)) {
- date = new Date(elapsed);
- } else {
- var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))?$/);
- if (match && (match[1] || match[7])) { // must have at least year or time
- var year = parseInt(match[1], 10) || 0;
- var month = (parseInt(match[2], 10) - 1) || 0;
- var day = parseInt(match[3], 10) || 1;
- date = new Date(Date.UTC(year, month, day));
- // optional time
- var type = match[7];
- if (type) {
- var hours = parseInt(match[4], 10);
- var minutes = parseInt(match[5], 10);
- var secFrac = parseFloat(match[6]);
- var seconds = secFrac | 0;
- var milliseconds = Math.round(1000 * (secFrac - seconds));
- date.setUTCHours(hours, minutes, seconds, milliseconds);
- // check offset
- if (type !== "Z") {
- var hoursOffset = parseInt(type, 10);
- var minutesOffset = parseInt(match[8], 10) || 0;
- var offset = -1000 * (60 * (hoursOffset * 60) + minutesOffset * 60);
- date = new Date(date.getTime() + offset);
- }
+ var match = str.match(/^(?:(\d{4})(?:-(\d{2})(?:-(\d{2}))?)?)?(?:T(\d{1,2}):(\d{2}):(\d{2}(?:\.\d+)?)(Z|(?:[+-]\d{1,2}(?::(\d{2}))?)))?$/);
+ if (match && (match[1] || match[7])) { // must have at least year or time
+ var year = parseInt(match[1], 10) || 0;
+ var month = (parseInt(match[2], 10) - 1) || 0;
+ var day = parseInt(match[3], 10) || 1;
+ date = new Date(Date.UTC(year, month, day));
+ // optional time
+ var type = match[7];
+ if (type) {
+ var hours = parseInt(match[4], 10);
+ var minutes = parseInt(match[5], 10);
+ var secFrac = parseFloat(match[6]);
+ var seconds = secFrac | 0;
+ var milliseconds = Math.round(1000 * (secFrac - seconds));
+ date.setUTCHours(hours, minutes, seconds, milliseconds);
+ // check offset
+ if (type !== "Z") {
+ var hoursOffset = parseInt(type, 10);
+ var minutesOffset = parseInt(match[8], 10) || 0;
+ var offset = -1000 * (60 * (hoursOffset * 60) + minutesOffset * 60);
+ date = new Date(date.getTime() + offset);
}
- } else {
- date = new Date("invalid");
}
+ } else {
+ date = new Date("invalid");
}
return date;
}
Copied: sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Geolocate.js (from rev 11410, trunk/openlayers/lib/OpenLayers/Control/Geolocate.js)
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Geolocate.js (rev 0)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Geolocate.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,172 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the Clear BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Control.js
+ * @requires OpenLayers/Geometry/Point.js
+ * @requires OpenLayers/Projection.js
+ */
+
+/**
+ * Class: OpenLayers.Control.Geolocate
+ * The Geolocate control wraps w3c geolocation API into control that can be
+ * bound to a map, and generate events on location update
+ *
+ * To use this control requires to load the proj4js library if the projection
+ * of the map is not EPSG:4326 or EPSG:900913.
+ *
+ * Inherits from:
+ * - <OpenLayers.Control>
+ */
+OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
+
+ /**
+ * Constant: EVENT_TYPES
+ * Supported event types:
+ * - *locationupdated* Triggered when browser return a new position
+ * - *locationfailed* Triggered when geolocation has failed
+ * - *locationuncapable* Triggered when control is activated on a browser
+ * which doesn't support geolocation
+ */
+ EVENT_TYPES: ["locationupdated", "locationfailed", "locationuncapable"],
+
+ /**
+ * Property: geolocation
+ * {Object} The geolocation engine, as a property to be possibly mocked.
+ */
+ geolocation: navigator.geolocation,
+
+ /**
+ * APIProperty: bind
+ * {Boolean} If true, map center will be set on location update.
+ */
+ bind: true,
+
+ /**
+ * APIProperty: watch
+ * {Boolean} If true, position will be update regularly.
+ */
+ watch: false,
+
+ /**
+ * APIProperty: geolocationOptions
+ * {Object} Options to pass to the navigator's geolocation API. See
+ * <http://dev.w3.org/geo/api/spec-source.html>. No specific
+ * option is passed to the geolocation API by default.
+ */
+ geolocationOptions: null,
+
+ /**
+ * Constructor: OpenLayers.Control.Geolocate
+ * Create a new control to deal with browser geolocation API
+ *
+ */
+ initialize: function(options) {
+ // concatenate events specific to this control with those from the base
+ this.EVENT_TYPES =
+ OpenLayers.Control.Geolocate.prototype.EVENT_TYPES.concat(
+ OpenLayers.Control.prototype.EVENT_TYPES
+ );
+ this.geolocationOptions = {};
+ OpenLayers.Control.prototype.initialize.apply(this, [options]);
+ },
+
+ /**
+ * Method: activate
+ * Activates the control.
+ *
+ * Returns:
+ * {Boolean} The control was effectively activated.
+ */
+ activate: function () {
+ if (!this.geolocation) {
+ this.events.triggerEvent("locationuncapable");
+ return false;
+ }
+ if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
+ if (this.watch) {
+ this.watchId = this.geolocation.watchPosition(
+ OpenLayers.Function.bind(this.geolocate, this),
+ OpenLayers.Function.bind(this.failure, this),
+ this.geolocationOptions
+ );
+ } else {
+ this.getCurrentLocation();
+ }
+ return true;
+ }
+ return false;
+ },
+
+ /**
+ * Method: deactivate
+ * Deactivates the control.
+ *
+ * Returns:
+ * {Boolean} The control was effectively deactivated.
+ */
+ deactivate: function () {
+ if (this.active && this.watchId !== null) {
+ this.geolocation.clearWatch(this.watchId);
+ }
+ return OpenLayers.Control.prototype.deactivate.apply(
+ this, arguments
+ );
+ },
+
+ /**
+ * Method: geolocate
+ * Activates the control.
+ *
+ */
+ geolocate: function (position) {
+ var center = new OpenLayers.LonLat(
+ position.coords.longitude,
+ position.coords.latitude
+ ).transform(
+ new OpenLayers.Projection("EPSG:4326"),
+ this.map.getProjectionObject()
+ );
+ if (this.bind) {
+ this.map.setCenter(center);
+ }
+ this.events.triggerEvent("locationupdated", {
+ position: position,
+ point: new OpenLayers.Geometry.Point(
+ center.lon, center.lat
+ )
+ });
+ },
+
+ /**
+ * APIMethod: getCurrentLocation
+ *
+ * Returns:
+ * {Boolean} Returns true if a event will be fired (successfull
+ * registration)
+ */
+ getCurrentLocation: function() {
+ if (!this.active || this.watch) {
+ return false;
+ }
+ this.geolocation.getCurrentPosition(
+ OpenLayers.Function.bind(this.geolocate, this),
+ OpenLayers.Function.bind(this.failure, this),
+ this.geolocationOptions
+ );
+ return true;
+ },
+
+ /**
+ * Method: failure
+ * method called on browser's geolocation failure
+ *
+ */
+ failure: function (error) {
+ this.events.triggerEvent("locationfailed", {error: error});
+ },
+
+ CLASS_NAME: "OpenLayers.Control.Geolocate"
+});
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Measure.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Measure.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Control/Measure.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -237,8 +237,8 @@
* Parameters: point - {<OpenLayers.Geometry.Point>} The point at the
* mouseposition. feature - {<OpenLayers.Feature.Vector>} The sketch feature.
*/
- measureImmediate : function(point, feature) {
- if (this.delayedTrigger === null &&
+ measureImmediate : function(point, feature, drawing) {
+ if (drawing && this.delayedTrigger === null &&
!this.handler.freehandMode(this.handler.evt)) {
this.measure(feature.geometry, "measurepartial");
}
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Events.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Events.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Events.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -105,6 +105,20 @@
},
/**
+ * Method: isMultiTouch
+ * Determine whether event was caused by a multi touch
+ *
+ * Parameters:
+ * event - {Event}
+ *
+ * Returns:
+ * {Boolean}
+ */
+ isMultiTouch: function(event) {
+ return event.touches && event.touches.length > 1;
+ },
+
+ /**
* Method: isLeftClick
* Determine whether event was caused by a left click.
*
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Drag.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Drag.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Drag.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -156,9 +156,7 @@
this.down(evt);
this.callback("down", [evt.xy]);
- if (evt.type === "mousedown") {
- OpenLayers.Event.stop(evt);
- }
+ OpenLayers.Event.stop(evt);
if(!this.oldOnselectstart) {
this.oldOnselectstart = document.onselectstart ?
@@ -204,9 +202,7 @@
this.interval);
}
this.dragging = true;
- if (evt.type === "touchmove") {
- OpenLayers.Event.stop(evt);
- }
+
this.move(evt);
this.callback("move", [evt.xy]);
if(!this.oldOnselectstart) {
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -79,6 +79,9 @@
* feature.
*/
createFeature: function(pixel) {
+ if(!pixel) {
+ pixel = new OpenLayers.Pixel(-50, -50);
+ }
var lonlat = this.control.map.getLonLatFromPixel(pixel);
this.point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
@@ -101,6 +104,17 @@
},
/**
+ * Method: destroyPersistedFeature
+ * Destroy the persisted feature.
+ */
+ destroyPersistedFeature: function() {
+ var layer = this.layer;
+ if(layer && layer.features.length > 2) {
+ this.layer.features[0].destroy();
+ }
+ },
+
+ /**
* Method: removePoint
* Destroy the temporary point.
*/
@@ -151,12 +165,13 @@
* Parameters:
* pixel - {<OpenLayers.Pixel>} The updated pixel location for the latest
* point.
+ * drawing - {Boolean} Indicate if we're currently drawing.
*/
- modifyFeature: function(pixel) {
+ modifyFeature: function(pixel, drawing) {
var lonlat = this.control.map.getLonLatFromPixel(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
- this.callback("modify", [this.point.geometry, this.getSketch()]);
+ this.callback("modify", [this.point.geometry, this.getSketch(), drawing]);
this.point.geometry.clearBounds();
this.drawFeature();
},
@@ -209,22 +224,17 @@
* {Boolean} Allow event propagation
*/
mousedown: function(evt) {
- // ignore double-clicks
- if (this.lastDown && this.lastDown.equals(evt.xy)) {
- return false;
+ var stopDown = this.stopDown;
+ if(this.freehandMode(evt)) {
+ stopDown = true;
}
- if(this.lastDown == null) {
- if(this.persist) {
- this.destroyFeature();
- }
- this.createFeature(evt.xy);
- } else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) {
- this.addPoint(evt.xy);
+ if(!this.lastDown || !this.lastDown.equals(evt.xy)) {
+ this.modifyFeature(evt.xy, !!this.lastUp);
}
this.mouseDown = true;
this.lastDown = evt.xy;
- this.drawing = true;
- return false;
+ this.stoppedDown = stopDown;
+ return !stopDown;
},
/**
@@ -239,13 +249,16 @@
* {Boolean} Allow event propagation
*/
mousemove: function (evt) {
- if(this.drawing) {
- if(this.mouseDown && this.freehandMode(evt)) {
- this.addPoint(evt.xy);
- } else {
- this.modifyFeature(evt.xy);
+ if(this.stoppedDown && this.freehandMode(evt)) {
+ if(this.persist) {
+ this.destroyPersistedFeature();
}
+ this.addPoint(evt.xy);
+ return false;
}
+ if(!this.mouseDown || this.stoppedDown) {
+ this.modifyFeature(evt.xy, !!this.lastUp);
+ }
return true;
},
@@ -261,20 +274,23 @@
* {Boolean} Allow event propagation
*/
mouseup: function (evt) {
- this.mouseDown = false;
- if(this.drawing) {
- if(this.freehandMode(evt)) {
+ if(this.mouseDown && (!this.lastUp || !this.lastUp.equals(evt.xy))) {
+ if(this.stoppedDown && this.freehandMode(evt)) {
this.removePoint();
this.finalize();
} else {
- if(this.lastUp == null) {
- this.addPoint(evt.xy);
+ if(this.lastDown.equals(evt.xy)) {
+ if(this.lastUp == null && this.persist) {
+ this.destroyPersistedFeature();
+ }
+ this.addPoint(evt.xy);
+ this.lastUp = evt.xy;
}
- this.lastUp = evt.xy;
}
- return false;
}
- return true;
+ this.stoppedDown = this.stopDown;
+ this.mouseDown = false;
+ return !this.stopUp;
},
/**
Copied: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Pinch.js (from rev 11410, trunk/openlayers/lib/OpenLayers/Handler/Pinch.js)
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Pinch.js (rev 0)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Pinch.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,227 @@
+/* Copyright (c) 2006-2011 by OpenLayers Contributors (see authors.txt for
+ * full list of contributors). Published under the Clear BSD license.
+ * See http://svn.openlayers.org/trunk/openlayers/license.txt for the
+ * full text of the license. */
+
+/**
+ * @requires OpenLayers/Handler.js
+ */
+
+/**
+ * Class: OpenLayers.Handler.Pinch
+ * The pinch handler is used to deal with sequences of browser events related
+ * to pinch gestures. The handler is used by controls that want to know
+ * when a pinch sequence begins, when a pinch is happening, and when it has
+ * finished.
+ *
+ * Controls that use the pinch handler typically construct it with callbacks
+ * for 'start', 'move', and 'done'. Callbacks for these keys are
+ * called when the pinch begins, with each change, and when the pinch is
+ * done.
+ *
+ * Create a new pinch handler with the <OpenLayers.Handler.Pinch> constructor.
+ *
+ * Inherits from:
+ * - <OpenLayers.Handler>
+ */
+OpenLayers.Handler.Pinch = OpenLayers.Class(OpenLayers.Handler, {
+
+ /**
+ * Property: started
+ * {Boolean} When a touchstart event is received, we want to record it,
+ * but not set 'pinching' until the touchmove get started after
+ * starting.
+ */
+ started: false,
+
+ /**
+ * Property: stopDown
+ * {Boolean} Stop propagation of touchstart events from getting to
+ * listeners on the same element. Default is true.
+ */
+ stopDown: true,
+
+ /**
+ * Property: pinching
+ * {Boolean}
+ */
+ pinching: false,
+
+ /**
+ * Property: last
+ * {Object} Object that store informations related to pinch last touch.
+ */
+ last: null,
+
+ /**
+ * Property: start
+ * {Object} Object that store informations related to pinch touchstart.
+ */
+ start: null,
+
+ /**
+ * Constructor: OpenLayers.Handler.Pinch
+ * Returns OpenLayers.Handler.Pinch
+ *
+ * Parameters:
+ * control - {<OpenLayers.Control>} The control that is making use of
+ * this handler. If a handler is being used without a control, the
+ * handlers setMap method must be overridden to deal properly with
+ * the map.
+ * callbacks - {Object} An object containing functions to be called when
+ * the pinch operation start, change, or is finished. The callbacks
+ * should expect to receive an object argument, which contains
+ * information about scale, distance, and position of touch points.
+ * options - {Object}
+ */
+ initialize: function(control, callbacks, options) {
+ OpenLayers.Handler.prototype.initialize.apply(this, arguments);
+ },
+
+ /**
+ * Method: touchstart
+ * Handle touchstart events
+ *
+ * Parameters:
+ * evt - {Event}
+ *
+ * Returns:
+ * {Boolean} Let the event propagate.
+ */
+ touchstart: function(evt) {
+ var propagate = true;
+ this.pinching = false;
+ if (OpenLayers.Event.isMultiTouch(evt)) {
+ this.started = true;
+ this.last = this.start = {
+ distance: this.getDistance(evt.touches),
+ delta: 0,
+ scale: 1
+ };
+ this.callback("start", [evt, this.start]);
+ propagate = !this.stopDown;
+ } else {
+ this.started = false;
+ this.start = null;
+ this.last = null;
+ }
+ OpenLayers.Event.stop(evt);
+ return propagate;
+ },
+
+ /**
+ * Method: touchmove
+ * Handle touchmove events
+ *
+ * Parameters:
+ * evt - {Event}
+ *
+ * Returns:
+ * {Boolean} Let the event propagate.
+ */
+ touchmove: function(evt) {
+ if (this.started && OpenLayers.Event.isMultiTouch(evt)) {
+ this.pinching = true;
+ var current = this.getPinchData(evt);
+ this.callback("move", [evt, current]);
+ this.last = current;
+ }
+ return true;
+ },
+
+ /**
+ * Method: touchend
+ * Handle touchend events
+ *
+ * Parameters:
+ * evt - {Event}
+ *
+ * Returns:
+ * {Boolean} Let the event propagate.
+ */
+ touchend: function(evt) {
+ if (this.started) {
+ this.started = false;
+ this.pinching = false;
+ this.callback("done", [evt, this.start, this.last]);
+ this.start = null;
+ this.last = null;
+ }
+ return true;
+ },
+
+ /**
+ * Method: activate
+ * Activate the handler.
+ *
+ * Returns:
+ * {Boolean} The handler was successfully activated.
+ */
+ activate: function() {
+ var activated = false;
+ if (OpenLayers.Handler.prototype.activate.apply(this, arguments)) {
+ this.pinching = false;
+ activated = true;
+ }
+ return activated;
+ },
+
+ /**
+ * Method: deactivate
+ * Deactivate the handler.
+ *
+ * Returns:
+ * {Boolean} The handler was successfully deactivated.
+ */
+ deactivate: function() {
+ var deactivated = false;
+ if (OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
+ this.started = false;
+ this.pinching = false;
+ this.start = null;
+ this.last = null;
+ deactivated = true;
+ }
+ return deactivated;
+ },
+
+ /**
+ * Method: getDistance
+ * Get the distance in pixels between two touches.
+ *
+ * Parameters:
+ * touches - {Array(Object)}
+ */
+ getDistance: function(touches) {
+ var t0 = touches[0];
+ var t1 = touches[1];
+ return Math.sqrt(
+ Math.pow(t0.clientX - t1.clientX, 2) +
+ Math.pow(t0.clientY - t1.clientY, 2)
+ );
+ },
+
+
+ /**
+ * Method: getPinchData
+ * Get informations about the pinch event.
+ *
+ * Parameters:
+ * evt - {Event}
+ *
+ * Returns:
+ * {Object} Object that contains data about the current pinch.
+ */
+ getPinchData: function(evt) {
+ var distance = this.getDistance(evt.touches);
+ var scale = distance / this.start.distance;
+ return {
+ distance: distance,
+ delta: this.last.distance - distance,
+ scale: scale
+ };
+ },
+
+ CLASS_NAME: "OpenLayers.Handler.Pinch"
+});
+
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -11,9 +11,9 @@
/**
* Class: OpenLayers.Handler.Point
- * Handler to draw a point on the map. Point is displayed on mouse down,
- * moves on mouse move, and is finished on mouse up. The handler triggers
- * callbacks for 'done', 'cancel', and 'modify'. The modify callback is
+ * Handler to draw a point on the map. Point is displayed on activation,
+ * moves on mouse move, and is finished on mouse up. The handler triggers
+ * callbacks for 'done', 'cancel', and 'modify'. The modify callback is
* called with each change in the sketch and will receive the latest point
* drawn. Create a new instance with the <OpenLayers.Handler.Point>
* constructor.
@@ -43,18 +43,19 @@
multi: false,
/**
- * Property: drawing
- * {Boolean} A point is being drawn
- */
- drawing: false,
-
- /**
* Property: mouseDown
* {Boolean} The mouse is down
*/
mouseDown: false,
/**
+ * Property: stoppedDown
+ * {Boolean} Indicate whether the last mousedown stopped the event
+ * propagation.
+ */
+ stoppedDown: null,
+
+ /**
* Property: lastDown
* {<OpenLayers.Pixel>} Location of the last mouse down
*/
@@ -76,6 +77,20 @@
persist: false,
/**
+ * APIProperty: stopDown
+ * {Boolean} Stop event propagation on mousedown. Must be false to
+ * allow "pan while drawing". Defaults to false.
+ */
+ stopDown: false,
+
+ /**
+ * APIPropery: stopUp
+ * {Boolean} Stop event propagation on mouse. Must be false to
+ * allow "pan while dragging". Defaults to fase.
+ */
+ stopUp: false,
+
+ /**
* Property: layerOptions
* {Object} Any optional properties to be set on the sketch layer.
*/
@@ -130,6 +145,7 @@
}, this.layerOptions);
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
+ this.createFeature();
return true;
},
@@ -141,6 +157,9 @@
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
*/
createFeature: function(pixel) {
+ if(!pixel) {
+ pixel = new OpenLayers.Pixel(-50, -50);
+ }
var lonlat = this.map.getLonLatFromPixel(pixel);
this.point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
@@ -158,17 +177,14 @@
if(!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
return false;
}
- // call the cancel callback if mid-drawing
- if(this.drawing) {
- this.cancel();
- }
- this.destroyFeature();
+ this.cancel(true);
// If a layer's map property is set to null, it means that that layer
// isn't added to the map. Since we ourself added the layer to the map
// in activate(), we can assume that if this.layer.map is null it means
// that the layer has been destroyed (as a result of map.destroy() for
// example.
if (this.layer.map != null) {
+ this.destroyFeature();
this.layer.destroy(false);
}
this.layer = null;
@@ -187,14 +203,27 @@
},
/**
+ * Method: destroyPersistedFeature
+ * Destroy the persisted feature.
+ */
+ destroyPersistedFeature: function() {
+ var layer = this.layer;
+ if(layer && layer.features.length > 1) {
+ this.layer.features[0].destroy();
+ }
+ },
+
+ /**
* Method: finalize
* Finish the geometry and call the "done" callback.
*
* Parameters:
* cancel - {Boolean} Call cancel instead of done callback. Default is
* false.
+ * noNew - {Boolean} Do not create a new feature after
+ * finalization. Default is false.
*/
- finalize: function(cancel) {
+ finalize: function(cancel, noNew) {
var key = cancel ? "cancel" : "done";
this.drawing = false;
this.mouseDown = false;
@@ -204,14 +233,21 @@
if(cancel || !this.persist) {
this.destroyFeature();
}
+ if(!noNew) {
+ this.createFeature();
+ }
},
/**
* APIMethod: cancel
* Finish the geometry and call the "cancel" callback.
+ *
+ * Parameters:
+ * noNew - {Boolean} Do not create a new feature after
+ * cancelation. Default is false.
*/
- cancel: function() {
- this.finalize(true);
+ cancel: function(noNew) {
+ this.finalize(true, noNew);
},
/**
@@ -257,7 +293,7 @@
var lonlat = this.map.getLonLatFromPixel(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
- this.callback("modify", [this.point.geometry, this.point]);
+ this.callback("modify", [this.point.geometry, this.point, false]);
this.point.geometry.clearBounds();
this.drawFeature();
},
@@ -310,25 +346,11 @@
* {Boolean} Allow event propagation
*/
mousedown: function(evt) {
- // check keyboard modifiers
- if(!this.checkModifiers(evt)) {
- return true;
- }
- // ignore double-clicks
- if(this.lastDown && this.lastDown.equals(evt.xy)) {
- return true;
- }
- this.drawing = true;
- if(this.lastDown == null) {
- if(this.persist) {
- this.destroyFeature();
- }
- this.createFeature(evt.xy);
- } else {
- this.modifyFeature(evt.xy);
- }
+ this.mouseDown = true;
this.lastDown = evt.xy;
- return false;
+ this.modifyFeature(evt.xy);
+ this.stoppedDown = this.stopDown;
+ return !this.stopDown;
},
/**
@@ -343,7 +365,7 @@
* {Boolean} Allow event propagation
*/
mousemove: function (evt) {
- if(this.drawing) {
+ if(!this.mouseDown || this.stoppedDown) {
this.modifyFeature(evt.xy);
}
return true;
@@ -361,13 +383,42 @@
* {Boolean} Allow event propagation
*/
mouseup: function (evt) {
- if(this.drawing) {
+ this.mouseDown = false;
+ this.stoppedDown = this.stopDown;
+ // check keyboard modifiers
+ if(!this.checkModifiers(evt)) {
+ return true;
+ }
+ // ignore double-clicks
+ if(this.lastUp && this.lastUp.equals(evt.xy)) {
+ return true;
+ }
+ if(this.lastDown && this.lastDown.equals(evt.xy)) {
+ if(this.persist) {
+ this.destroyPersistedFeature();
+ }
+ this.lastUp = evt.xy;
this.finalize();
- return false;
+ return !this.stopUp;
} else {
return true;
}
},
+ /**
+ * Method: mouseout
+ * Handle mouse out. For better user experience reset mouseDown
+ * and stoppedDown when the mouse leaves the map viewport.
+ *
+ * Parameters:
+ * evt - {Event} The browser event
+ */
+ mouseout: function(evt) {
+ if(OpenLayers.Util.mouseLeft(evt, this.map.viewPortDiv)) {
+ this.stoppedDown = this.stopDown;
+ this.mouseDown = false;
+ }
+ },
+
CLASS_NAME: "OpenLayers.Handler.Point"
});
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Polygon.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -75,6 +75,9 @@
* feature.
*/
createFeature: function(pixel) {
+ if(!pixel) {
+ pixel = new OpenLayers.Pixel(-50, -50);
+ }
var lonlat = this.control.map.getLonLatFromPixel(pixel);
this.point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat)
@@ -82,13 +85,27 @@
this.line = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LinearRing([this.point.geometry])
);
-
- // check for hole digitizing
- var polygon;
- if (this.holeModifier && (this.evt[this.holeModifier])) {
+ this.polygon = new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Polygon([this.line.geometry])
+ );
+ this.callback("create", [this.point.geometry, this.getSketch()]);
+ this.point.geometry.clearBounds();
+ this.layer.addFeatures([this.polygon, this.point], {silent: true});
+ },
+
+ /**
+ * Method: addPoint
+ * Add point to geometry.
+ *
+ * Parameters:
+ * pixel - {<OpenLayers.Pixel>} The pixel location for the new point.
+ */
+ addPoint: function(pixel) {
+ if(!this.drawingHole && this.holeModifier &&
+ this.evt && this.evt[this.holeModifier]) {
var geometry = this.point.geometry;
var features = this.control.layer.features;
- var candidate;
+ var candidate, polygon;
// look for intersections, last drawn gets priority
for (var i=features.length-1; i>=0; --i) {
candidate = features[i].geometry;
@@ -110,15 +127,7 @@
}
}
}
- if (!polygon) {
- this.polygon = new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Polygon([this.line.geometry])
- );
- }
-
- this.callback("create", [this.point.geometry, this.getSketch()]);
- this.point.geometry.clearBounds();
- this.layer.addFeatures([this.polygon, this.point], {silent: true});
+ OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments);
},
/**
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Kinetic.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Kinetic.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Kinetic.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -63,7 +63,6 @@
/**
* Method: begin
- *
* Begins the dragging.
*/
begin: function() {
@@ -74,8 +73,10 @@
/**
* Method: update
+ * Updates during the dragging.
*
- * Updates during the dragging.
+ * Parameters:
+ * xy - {<OpenLayers.Pixel>} The new position.
*/
update: function(xy) {
this.points.unshift({xy: xy, tick: new Date().getTime()});
@@ -86,8 +87,15 @@
/**
* Method: end
+ * Ends the dragging, start the kinetic.
*
- * Ends the dragging, start the kinetic.
+ * Parameters:
+ * xy - {<OpenLayers.Pixel>} The last position.
+ *
+ * Returns:
+ * {Object} An object with two properties: "speed", and "theta". The
+ * "speed" and "theta" values are to be passed to the move
+ * function when starting the animation.
*/
end: function(xy) {
var last, now = new Date().getTime();
@@ -117,12 +125,13 @@
/**
* Method: move
- *
* Launch the kinetic move pan.
*
* Parameters:
- * info - {Object}
- * callback - arguments x, y (values to pan), end (is the last point)
+ * info - {Object} An object with two properties, "speed", and "theta".
+ * These values are those returned from the "end" call.
+ * callback - {Function} Function called on every step of the animation,
+ * receives x, y (values to pan), end (is the last point).
*/
move: function(info, callback) {
var v0 = info.speed;
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Map.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Map.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Map.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -507,18 +507,27 @@
this.viewPortDiv.className = "olMapViewport";
this.div.appendChild(this.viewPortDiv);
+ // the eventsDiv is where we listen for all map events
+ var eventsDiv = document.createElement("div");
+ eventsDiv.id = this.id + "_events";
+ eventsDiv.style.position = "absolute";
+ eventsDiv.style.width = "100%";
+ eventsDiv.style.height = "100%";
+ eventsDiv.style.zIndex = this.Z_INDEX_BASE.Control - 1;
+ this.viewPortDiv.appendChild(eventsDiv);
+ this.eventsDiv = eventsDiv;
+ this.events = new OpenLayers.Events(
+ this, this.eventsDiv, this.EVENT_TYPES, this.fallThrough,
+ {includeXY: true}
+ );
+
// the layerContainerDiv is the one that holds all the layers
id = this.id + "_OpenLayers_Container";
this.layerContainerDiv = OpenLayers.Util.createDiv(id);
this.layerContainerDiv.style.zIndex=this.Z_INDEX_BASE['Popup']-1;
- this.viewPortDiv.appendChild(this.layerContainerDiv);
+ this.eventsDiv.appendChild(this.layerContainerDiv);
- this.events = new OpenLayers.Events(this,
- this.viewPortDiv,
- this.EVENT_TYPES,
- this.fallThrough,
- {includeXY: true});
this.updateSize();
if(this.eventListeners instanceof Object) {
this.events.on(this.eventListeners);
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -1849,6 +1849,15 @@
coordinateseconds = Math.round(coordinateseconds*10);
coordinateseconds /= 10;
+ if( coordinateseconds >= 60) {
+ coordinateseconds -= 60;
+ coordinateminutes += 1;
+ if( coordinateminutes >= 60) {
+ coordinateminutes -= 60;
+ coordinatedegrees += 1;
+ }
+ }
+
if( coordinatedegrees < 10 ) {
coordinatedegrees = "0" + coordinatedegrees;
}
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers.js 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers.js 2011-02-24 13:37:57 UTC (rev 11413)
@@ -170,6 +170,7 @@
"OpenLayers/Handler/Polygon.js",
"OpenLayers/Handler/Feature.js",
"OpenLayers/Handler/Drag.js",
+ "OpenLayers/Handler/Pinch.js",
"OpenLayers/Handler/RegularPolygon.js",
"OpenLayers/Handler/Box.js",
"OpenLayers/Handler/MouseWheel.js",
@@ -331,6 +332,7 @@
"OpenLayers/Control/ZoomOut.js",
"OpenLayers/Control/ZoomPanel.js",
"OpenLayers/Control/EditingToolbar.js",
+ "OpenLayers/Control/Geolocate.js",
"OpenLayers/Symbolizer.js",
"OpenLayers/Symbolizer/Point.js",
"OpenLayers/Symbolizer/Line.js",
Modified: sandbox/cmoullet/openlayers/tests/BaseTypes/Bounds.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/BaseTypes/Bounds.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/BaseTypes/Bounds.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -606,6 +606,7 @@
t.ok( bounds.equals(b), "bounds is set correctly");
//null values
+ OpenLayers.Lang.setCode('en');
var desiredMsg = "You must pass both x and y values to the add function.";
OpenLayers.Console.error = function(msg) {
t.eq(msg, desiredMsg, "error correctly reported");
Modified: sandbox/cmoullet/openlayers/tests/BaseTypes/LonLat.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/BaseTypes/LonLat.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/BaseTypes/LonLat.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -64,6 +64,7 @@
t.ok( addpx.equals(ll), "addpx is set correctly");
//null values
+ OpenLayers.Lang.setCode('en');
var desiredMsg = "You must pass both lon and lat values to the add function.";
OpenLayers.Console.error = function(msg) {
t.eq(msg, desiredMsg, "error correctly reported");
Modified: sandbox/cmoullet/openlayers/tests/BaseTypes/Pixel.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/BaseTypes/Pixel.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/BaseTypes/Pixel.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -74,6 +74,7 @@
t.ok( pixel.equals(px), "returned pixel is correct");
//null values
+ OpenLayers.Lang.setCode('en');
var desiredMsg = "You must pass both x and y values to the add function.";
OpenLayers.Console.error = function(msg) {
t.eq(msg, desiredMsg, "error correctly reported");
Modified: sandbox/cmoullet/openlayers/tests/Control/DrawFeature.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/DrawFeature.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Control/DrawFeature.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -60,7 +60,7 @@
}
function test_sketch_events(t) {
- t.plan(6);
+ t.plan(12);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -69,37 +69,62 @@
isBaseLayer: true
});
var control = new OpenLayers.Control.DrawFeature(
- layer, OpenLayers.Handler.Point
+ layer, OpenLayers.Handler.Path, {
+ handlerOptions: {persist: true}
+ }
);
map.addLayer(layer);
map.addControl(control);
map.zoomToMaxExtent();
- control.activate();
- var log = {};
+ var log;
layer.events.on({
sketchstarted: function(event) {
- log.event = event;
+ log['sketchstarted'] = event;
},
sketchmodified: function(event) {
- log.event = event;
+ log['sketchmodified'] = event;
},
sketchcomplete: function(event) {
- log.event = event;
+ log['sketchcomplete'] = event;
}
});
// mock up draw/modify of a point
+ log = {};
+ control.activate();
+ t.eq(log.sketchstarted.type, "sketchstarted", "[activate] sketchstarted triggered");
+ t.geom_eq(log.sketchstarted.vertex, new OpenLayers.Geometry.Point(-250, 175), "[activate] correct vertex");
+
+ log = {};
+ map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(log.sketchmodified.type, "sketchmodified", "[mousemove] sketchmodified triggered");
+ t.geom_eq(log.sketchmodified.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousemove] correct vertex");
+
map.events.triggerEvent("mousedown", {xy: new OpenLayers.Pixel(0, 0)});
- t.eq(log.event.type, "sketchstarted", "[mousedown] sketchstarted triggered");
- t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousedown] correct vertex");
+
+ log = {};
+ map.events.triggerEvent("mouseup", {xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(log.sketchmodified.type, "sketchmodified", "[mouseup] sketchmodified triggered");
+ t.geom_eq(log.sketchmodified.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mouseup] correct vertex");
+
+ log = {};
map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(10, 10)});
- t.eq(log.event.type, "sketchmodified", "[mousemove] sketchmodified triggered");
- t.geom_eq(log.event.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
- map.events.triggerEvent("mouseup", {xy: new OpenLayers.Pixel(10, 10)});
- t.eq(log.event.type, "sketchcomplete", "[mouseup] sketchcomplete triggered");
- t.geom_eq(log.event.feature.geometry, new OpenLayers.Geometry.Point(-190, 115), "[mouseup] correct geometry");
-
+ t.eq(log.sketchmodified.type, "sketchmodified", "[mousemove] sketchmodified triggered");
+ t.geom_eq(log.sketchmodified.vertex, new OpenLayers.Geometry.Point(-190, 115), "[mousemove] correct vertex");
+
+ log = {};
+ map.events.triggerEvent("dblclick", {xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(log.sketchcomplete.type, "sketchcomplete", "[dblclick] sketchcomplete triggered");
+ t.geom_eq(log.sketchcomplete.feature.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-200, 125),
+ new OpenLayers.Geometry.Point(-190, 115)
+ ]),
+ "[dblclick] correct geometry");
+ t.eq(log.sketchstarted.type, "sketchstarted", "[dblclick] sketchstarted triggered");
+ t.geom_eq(log.sketchstarted.vertex, new OpenLayers.Geometry.Point(-250, 175), "[dblclick] correct vertex");
+
map.destroy();
}
Copied: sandbox/cmoullet/openlayers/tests/Control/Geolocate.html (from rev 11410, trunk/openlayers/tests/Control/Geolocate.html)
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Geolocate.html (rev 0)
+++ sandbox/cmoullet/openlayers/tests/Control/Geolocate.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,130 @@
+<html>
+<head>
+ <script src="../../lib/OpenLayers.js"></script>
+ <script type="text/javascript">
+ var map, control, centerLL
+ watch = null,
+ geolocation= {
+ getCurrentPosition: function(f) {
+ f({
+ coords: { latitude: 10, longitude: 10 }
+ });
+ },
+ watchPosition: function(f) {
+ watch = true;
+ },
+ clearWatch: function() {
+ watch = null;
+ }
+ };
+
+ function test_initialize(t) {
+ t.plan(3);
+ control = new OpenLayers.Control.Geolocate({geolocationOptions: {foo: 'bar'}});
+ t.ok(control instanceof OpenLayers.Control.Geolocate,
+ "new OpenLayers.Control returns object" );
+ t.eq(control.displayClass, "olControlGeolocate", "displayClass is correct" );
+ t.eq(control.geolocationOptions.foo, 'bar',
+ 'provided geolocation options are set in the geolocationOptions prop');
+ }
+ function test_bind(t) {
+ t.plan(3);
+ var control = new OpenLayers.Control.Geolocate({
+ geolocation: geolocation
+ });
+ control.events.register('locationupdated', null, function() {
+ t.ok(true, 'locationupdated event is fired when bound');
+ });
+ map.addControl(control);
+ control.activate();
+ var center = map.getCenter();
+ t.eq(center.lon, 10, 'bound control sets the map lon');
+ t.eq(center.lat, 10, 'bound control sets the map lat');
+ control.deactivate();
+ map.removeControl(control);
+ map.setCenter(centerLL);
+ }
+ function test_unbind(t) {
+ t.plan(3);
+ var control = new OpenLayers.Control.Geolocate({
+ geolocation: geolocation,
+ bind: false
+ });
+ control.events.register('locationupdated', null, function() {
+ t.ok(true, 'locationupdated event is fired when unbound');
+ });
+ map.addControl(control);
+ control.activate();
+ var center = map.getCenter();
+ t.eq(center.lon, 0, 'unbound control doesnt sets the map lon');
+ t.eq(center.lat, 0, 'unbound control doesnt sets the map lat');
+ control.deactivate();
+ map.removeControl(control);
+ map.setCenter(centerLL);
+ }
+ function test_getCurrentLocation(t) {
+ t.plan(5);
+ var control = new OpenLayers.Control.Geolocate({
+ geolocation: geolocation
+ });
+ map.addControl(control);
+ t.eq(control.getCurrentLocation(), false, 'getCurrentLocation return false if control hasnt been activated');
+ control.activate();
+ map.setCenter(centerLL);
+ t.eq(control.getCurrentLocation(), true, 'getCurrentLocation return true if control has been activated');
+ var center = map.getCenter();
+ t.eq(center.lon, 10, 'bound control sets the map lon when calling getCurrentLocation');
+ t.eq(center.lat, 10, 'bound control sets the map lat when calling getCurrentLocation');
+ control.deactivate();
+ map.removeControl(control);
+ map.setCenter(centerLL);
+ var control2 = new OpenLayers.Control.Geolocate({
+ geolocation: geolocation
+ });
+ map.addControl(control2);
+ t.eq(control2.getCurrentLocation(), false, 'getCurrentLocation return false if control is in watch mode');
+ control2.deactivate();
+ map.removeControl(control2);
+ map.setCenter(centerLL);
+ }
+ function test_watch(t) {
+ t.plan(2);
+ var control = new OpenLayers.Control.Geolocate({
+ geolocation: geolocation,
+ watch: true
+ });
+ map.addControl(control);
+ control.activate();
+ t.eq(watch, true, 'watch option makes calls to watchPosition');
+ control.deactivate();
+ t.eq(watch, null, 'deactivate control calls the clearwatch');
+ map.removeControl(control);
+ map.setCenter(centerLL);
+ }
+ function test_uncapable(t) {
+ t.plan(1);
+ var control = new OpenLayers.Control.Geolocate({
+ geolocation: null,
+ bind: false
+ });
+ control.events.register('locationuncapable', null, function() {
+ t.ok(true,'uncapable browser fired locationuncapable event');
+ });
+ map.addControl(control);
+ control.activate();
+ }
+ function loader() {
+ map = new OpenLayers.Map('map');
+ var layer = new OpenLayers.Layer.WMS("Test Layer",
+ "http://labs.metacarta.com/wms-c/Basic.py?",
+ {layers: "basic"});
+ map.addLayer(layer);
+ centerLL = new OpenLayers.LonLat(0,0);
+ map.setCenter(centerLL, 5);
+ }
+ </script>
+</head>
+<body onload="loader()">
+ <div id="map" style="width: 256px; height: 256px;"/>
+</body>
+</html>
Modified: sandbox/cmoullet/openlayers/tests/Control/Measure.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Measure.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Control/Measure.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -52,6 +52,7 @@
xy: new OpenLayers.Pixel(x, y)
})
};
+ trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
trigger("mouseup", 0, 0);
trigger("mousemove", 10, 10);
@@ -60,9 +61,10 @@
// confirm that the sketch persists
t.eq(control.handler.layer.features.length, 1, "feature persists");
- // cancel and see that sketch is gone
+ // cancel and see that sketch is gone (do not forget that
+ // cancel will create the new feature)
control.cancel();
- t.eq(control.handler.layer.features.length, 0, "feature is gone after cancel");
+ t.eq(control.handler.layer.features.length, 2, "feature is gone after cancel");
map.destroy();
@@ -112,6 +114,7 @@
var delay = control.partialDelay / 1000;
// establish first point
+ trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
trigger("mouseup", 0, 0);
@@ -187,6 +190,7 @@
log = [];
// f) establish first freehand point
+ trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
t.eq(log.length, 0, "f) no event fired yet")
@@ -203,14 +207,14 @@
t.eq(log.length, 2, "h) event logged");
t.ok(log[1] && log[1].type == "measurepartial", "h) correct type");
t.ok(log[1] && log[1].measure == 20, "h) correct measure");
-
+
// i) mouse up to finish
trigger("mouseup", 20, 0);
t.eq(log.length, 3, "i) event logged");
t.ok(log[2] && log[2].type == "measure", "i) correct type");
t.ok(log[2] && log[2].measure == 20, "i) correct measure");
-
+
// j) clean up
log = [];
map.destroy();
@@ -224,7 +228,7 @@
}
function test_immediate(t) {
- t.plan(29);
+ t.plan(32);
var map = new OpenLayers.Map({
div: "map",
@@ -237,7 +241,7 @@
],
center: new OpenLayers.LonLat(0, 0)
});
-
+
var log = [];
var control = new OpenLayers.Control.Measure(
OpenLayers.Handler.Path, {
@@ -255,7 +259,7 @@
);
map.addControl(control);
control.activate();
-
+
// convenience function to trigger mouse events
function trigger(type, x, y) {
map.events.triggerEvent(type, {
@@ -267,6 +271,7 @@
var delay = control.partialDelay / 1000;
// a) establish first point
+ trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
trigger("mouseup", 0, 0);
@@ -274,7 +279,7 @@
trigger("mousemove", 0, 10);
t.eq(log.length, 0, "a) no event fired yet");
-
+
t.delay_call(
delay, function() {
// confirm measurepartial is fired
@@ -334,18 +339,21 @@
// i) double click to finish
trigger("mousedown", 0, 60);
+ t.eq(log.length, 7, "i) event logged");
+ t.eq(log[6] && log[6].type, "measurepartial", "i) correct type");
+ t.eq(log[6] && log[6].measure, 60, "i) correct measure");
trigger("mouseup", 0, 60);
- t.eq(log.length, 6, "i) no event fired yet");
+ t.eq(log.length, 7, "i) no event fired yet");
},
delay, function() {
- t.eq(log.length, 7, "i) event logged");
- t.ok(log[6] && log[6].type == "measurepartial", "i) correct type");
- t.ok(log[6] && log[6].measure == 60, "i) correct measure");
-
+ t.eq(log.length, 8, "i) event logged");
+ t.eq(log[7] && log[7].type, "measurepartial", "i) correct type");
+ t.eq(log[7] && log[7].measure, 60, "i) correct measure");
+
trigger("dblclick", 0, 60);
- t.eq(log.length, 8, "i) event logged");
- t.ok(log[7] && log[7].type == "measure", "i) correct type");
- t.ok(log[7] && log[7].measure == 60, "i) correct measure");
+ t.eq(log.length, 9, "i) event logged");
+ t.eq(log[8] && log[8].type, "measure", "i) correct type");
+ t.eq(log[8] && log[8].measure, 60, "i) correct measure");
// clear log
log = [];
Modified: sandbox/cmoullet/openlayers/tests/Control/PanZoom.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/PanZoom.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Control/PanZoom.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -72,65 +72,65 @@
simulateClick(wnd, wnd.control.buttons[0]);
t.delay_call(2, function() {
- t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "Pan up works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.ok( wnd.mapper.getCenter().lat > wnd.centerLL.lat, "1) Pan up works correctly" );
+ t.ok(!flag.mousedown, "1) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "1) mouseup does not get to the map");
+ t.ok(!flag.click, "1) click does not get to the map");
+ t.ok(!flag.dblclick, "1) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[1]);
}, 2, function() {
- t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "Pan left works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.ok( wnd.mapper.getCenter().lon < wnd.centerLL.lon, "2) Pan left works correctly" );
+ t.ok(!flag.mousedown, "2) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "2) mouseup does not get to the map");
+ t.ok(!flag.click, "2) click does not get to the map");
+ t.ok(!flag.dblclick, "2) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[2]);
}, 2, function() {
- t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "Pan right works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.ok( wnd.mapper.getCenter().lon == wnd.centerLL.lon, "3) Pan right works correctly" );
+ t.ok(!flag.mousedown, "3) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "3) mouseup does not get to the map");
+ t.ok(!flag.click, "3) click does not get to the map");
+ t.ok(!flag.dblclick, "3) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[3]);
}, 2, function() {
- t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "Pan down works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.ok( wnd.mapper.getCenter().lat == wnd.centerLL.lat, "4) Pan down works correctly" );
+ t.ok(!flag.mousedown, "4) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "4) mouseup does not get to the map");
+ t.ok(!flag.click, "4) click does not get to the map");
+ t.ok(!flag.dblclick, "4) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[4]);
}, 2, function() {
- t.eq( wnd.mapper.getZoom(), 6, "zoomin works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.eq( wnd.mapper.getZoom(), 6, "5) zoomin works correctly" );
+ t.ok(!flag.mousedown, "5) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "5) mouseup does not get to the map");
+ t.ok(!flag.click, "5) click does not get to the map");
+ t.ok(!flag.dblclick, "5) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[6]);
}, 2, function() {
- t.eq( wnd.mapper.getZoom(), 5, "zoomout works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.eq( wnd.mapper.getZoom(), 5, "6) zoomout works correctly" );
+ t.ok(!flag.mousedown, "6) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "6) mouseup does not get to the map");
+ t.ok(!flag.click, "6) click does not get to the map");
+ t.ok(!flag.dblclick, "6) dblclick does not get to the map");
resetFlags();
simulateClick(wnd, wnd.control.buttons[5]);
}, 2, function() {
- t.eq( wnd.mapper.getZoom(), 2, "zoomworld works correctly" );
- t.ok(!flag.mousedown, "mousedown does not get to the map");
- t.ok(flag.mouseup, "mouseup does get to the map");
- t.ok(!flag.click, "click does not get to the map");
- t.ok(!flag.dblclick, "dblclick does not get to the map");
+ t.eq( wnd.mapper.getZoom(), 2, "7) zoomworld works correctly" );
+ t.ok(!flag.mousedown, "7) mousedown does not get to the map");
+ t.ok(!flag.mouseup, "7) mouseup does not get to the map");
+ t.ok(!flag.click, "7) click does not get to the map");
+ t.ok(!flag.dblclick, "7) dblclick does not get to the map");
resetFlags();
});
});
Modified: sandbox/cmoullet/openlayers/tests/Control/Scale.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Scale.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Control/Scale.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -2,6 +2,7 @@
<head>
<script src="../OLLoader.js"></script>
<script type="text/javascript">
+ OpenLayers.Lang.setCode('en');
var map;
function test_Control_Scale_constructor (t) {
t.plan( 2 );
Modified: sandbox/cmoullet/openlayers/tests/Control/Split.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Split.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Control/Split.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -35,13 +35,20 @@
function test_setSource(t) {
t.plan(5);
- var layer1 = new OpenLayers.Layer.Vector();
- var layer2 = new OpenLayers.Layer.Vector();
+ var layer1 = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ var layer2 = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
var control = new OpenLayers.Control.Split({layer: layer1});
var map = new OpenLayers.Map("map");
map.addLayers([layer1, layer2]);
+ map.zoomToMaxExtent();
map.addControl(control);
control.activate();
@@ -64,12 +71,16 @@
function test_activate(t) {
t.plan(8);
- var layer = new OpenLayers.Layer.Vector();
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
var control = new OpenLayers.Control.Split({layer: layer});
var map = new OpenLayers.Map("map");
map.addLayer(layer);
+ map.zoomToMaxExtent();
map.addControl(control);
-
+
// test activation with no source layer
control.activate();
t.eq(control.active, true, "control is active");
@@ -93,12 +104,16 @@
t.plan(7);
- var layer = new OpenLayers.Layer.Vector();
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
var control = new OpenLayers.Control.Split({layer: layer});
var map = new OpenLayers.Map("map");
map.addLayer(layer);
+ map.zoomToMaxExtent();
map.addControl(control);
-
+
// activate and check sketch handler
control.activate();
t.ok(control.handler, "sketch handler present");
Modified: sandbox/cmoullet/openlayers/tests/Handler/Click.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Click.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Handler/Click.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -50,7 +50,8 @@
map: map
};
map.events.registerPriority = function(type, obj, func) {
- var r = func();
+ var f = OpenLayers.Function.bind(func, obj)
+ var r = f({xy:null});
if(typeof r == "string") {
// this is one of the mock handler methods
t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
Modified: sandbox/cmoullet/openlayers/tests/Handler/Drag.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Drag.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Handler/Drag.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -294,7 +294,7 @@
// "touchend" events set expected states in the drag handler.
// We also verify that we stop event bubbling as appropriate.
- t.plan(12);
+ t.plan(14);
// set up
@@ -302,37 +302,44 @@
var c = new OpenLayers.Control();
m.addControl(c);
var h = new OpenLayers.Handler.Drag(c, {
- done: function(px) { log = px; }});
+ done: function(px) {
+ log.push(px);
+ }
+ });
h.activate();
var _stop = OpenLayers.Event.stop;
- OpenLayers.Event.stop = function(e) { log = e; };
+ OpenLayers.Event.stop = function(e) {
+ log.push(e);
+ };
- var Px = OpenLayers.Pixel, e, log;
+ var Px = OpenLayers.Pixel, e;
+ var log = [];
// test
-
e = {touches: [{}], xy: new Px(0, 0)};
m.events.triggerEvent('touchstart', e);
t.eq(h.started, true, '[touchstart] started is set');
t.eq(h.start.x, 0, '[touchstart] start.x is correct');
t.eq(h.start.y, 0, '[touchstart] start.y is correct');
- t.eq(log, undefined, '[touchstart] event is not stopped');
+ t.eq(log.length, 1, '[touchstart] one item in log');
+ t.ok(log[0] === e, "touchstart", '[touchstart] event is stopped');
e = {xy: new Px(1, 1)};
m.events.triggerEvent('touchmove', e);
t.eq(h.dragging, true, '[touchmove] dragging is set');
- t.eq(h.last.x, 1, '[touchstart] last.x is correct');
- t.eq(h.last.y, 1, '[touchstart] last.y is correct');
- t.ok(log == e, '[touchmove] event is stopped');
+ t.eq(h.last.x, 1, '[touchmove] last.x is correct');
+ t.eq(h.last.y, 1, '[touchmove] last.y is correct');
+ t.eq(log.length, 1, '[touchmove] one item in log (event is not stopped)');
e = {xy: new Px(2, 2)};
m.events.triggerEvent('touchend', e);
t.eq(h.started, false, '[touchend] started is reset');
t.eq(h.started, false, '[touchend] started is reset');
// the "done" callback gets the position of the last touchmove
- t.eq(log.x, 1, '[touchend] done callback got correct x position');
- t.eq(log.y, 1, '[touchend] done callback got correct y position');
+ t.eq(log.length, 2, '[touchend] two items in log');
+ t.ok(log[1] instanceof Px, '[touchend] got');
+ t.ok(log[1].equals(e.xy), '[touchend] done callback got correct position');
// tear down
Modified: sandbox/cmoullet/openlayers/tests/Handler/Path.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Path.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Handler/Path.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -25,12 +25,27 @@
}
function test_Handler_Path_activation(t) {
- t.plan(3);
- var map = new OpenLayers.Map('map');
+ t.plan(12);
+ var log = [];
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
var control = new OpenLayers.Control();
+ var handler = new OpenLayers.Handler.Path(control, {
+ "create": function(g, f) {
+ log.push({geometry: g, feature: f});
+ }
+ });
+ control.handler = handler;
map.addControl(control);
- var handler = new OpenLayers.Handler.Path(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.active = true;
+
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
@@ -38,39 +53,72 @@
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
+ t.ok(handler.layer instanceof OpenLayers.Layer.Vector,
+ "activate creates a vector layer");
+ t.ok(handler.layer.map == map,
+ "activate adds the vector layer to the map");
+ t.ok(handler.point instanceof OpenLayers.Feature.Vector,
+ "activate creates a point feature");
+ t.ok(handler.point.layer == handler.layer,
+ "activate adds the point feature to the layer");
+ t.ok(handler.line instanceof OpenLayers.Feature.Vector,
+ "acttivates creates a line feature");
+ t.ok(handler.line.layer == handler.layer,
+ "activate adds the line feature to the layer");
+ t.eq(log.length, 1,
+ "activate calls \"create\" once");
+ t.geom_eq(log[0].geometry, handler.point.geometry,
+ "\"create\" called with expected geometry");
+ t.ok(log[0].feature == handler.line,
+ "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
- map.destroy();
+
+ map.destroy();
}
- function test_Handler_Path_bounds(t) {
+ function test_bounds(t) {
t.plan(2);
+ var geometry;
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
- var handler = new OpenLayers.Handler.Path(control, {});
+ var handler = new OpenLayers.Handler.Path(control, {},
+ {stopDown: true, stopUp: true});
var activated = handler.activate();
+ // click on (150, 75)
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
+ handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
- var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
+ // click on (175, 100)
+ evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
- t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
- var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
+ t.ok(handler.line.geometry.getBounds().equals(
+ new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
+ "Correct bounds");
+ // mousedown on (175, 100)
+ evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
- var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
+ // mousemove to (125, 100)
+ evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
- t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
+ // test that the bounds have changed
+ t.ok(!handler.line.geometry.getBounds().equals(
+ new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
+ "Correct bounds after dragging without letting go. " +
+ "(Came out as " + handler.line.geometry.getBounds().toBBOX() +
+ ".)");
map.destroy();
}
function test_callbacks(t) {
- t.plan(15);
+ t.plan(45);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -79,74 +127,347 @@
isBaseLayer: true
});
map.addLayer(layer);
- var control = new OpenLayers.Control({
- });
- var log = {};
+ var control = new OpenLayers.Control({});
+ var logs = [], log;
var handler = new OpenLayers.Handler.Path(control, {
create: function() {
- log.type = "create",
- log.args = arguments
+ logs.push({type: "create", args: arguments});
},
+ point: function() {
+ logs.push({type: "point", args: arguments});
+ },
modify: function() {
- log.type = "modify",
- log.args = arguments
+ logs.push({type: "modify", args: arguments});
},
done: function() {
- log.type = "done",
- log.args = arguments
+ logs.push({type: "done", args: arguments});
},
cancel: function() {
- log.type = "cancel",
- log.args = arguments
+ logs.push({type: "cancel", args: arguments});
}
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // mock up feature drawing
+ // create line
handler.activate();
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(log.type, "create", "[mousedown] create called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
- t.ok(log.args[1] === handler.line, "[mousedown] correct sketch feature");
+ t.eq(logs.length, 1, "[activate] called back");
+ log = logs.shift();
+ t.eq(log.type, "create", "[activate] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[activate] correct point");
+ t.ok(log.args[1] == handler.line,
+ "[activate] correct feature");
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousemove] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousedown] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousedown] correct feature");
+ // mouse up
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 2, "[mouseup] called back twice");
+ log = logs.shift();
+ t.eq(log.type, "point", "[mouseup] point called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ t.geom_eq(log.args[1],
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-150, 75),
+ new OpenLayers.Geometry.Point(-150, 75)
+ ]), "[mouseup] correct line");
+ log = logs.shift();
t.eq(log.type, "modify", "[mouseup] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
- t.ok(log.args[1] === handler.line, "[mouseup] correct sketch feature");
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ t.ok(log.args[1] == handler.line,
+ "[mouseup] correct feature");
+ // mouse move
+ handler.mousemove({type: "mousemove",
+ xy: new OpenLayers.Pixel(1, 1)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 74), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.line, "[mousemove] correct sketch feature");
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 74),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousemove] correct feature");
+ // mouse move
+ handler.mousemove({type: "mousemove",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.line, "[mousemove] correct sketch feature");
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
- handler.dblclick({type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown({type: "mousedown",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65),
+ "[mousedown] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousedown] correct feature");
+ // mouse up ("point", "modify")
+ handler.mouseup({type: "mouseup",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 2, "[mouseup] called back twice");
+ log = logs.shift();
+ log = logs.shift();
+ // mouse down
+ handler.mousedown({type: "mousedown",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 0, "[mousedown] called back");
+ // mouse up
+ handler.mouseup({type: "mouseup",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 0, "[mouseup] not called back");
+ // double click
+ handler.dblclick({type: "dblclick",
+ xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 2, "[dblclick] called back twice");
+ log = logs.shift();
t.eq(log.type, "done", "[dblclick] done called");
- t.geom_eq(
- log.args[0],
+ t.geom_eq(log.args[0],
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-150, 75),
new OpenLayers.Geometry.Point(-140, 65)
]),
"[dblclick] correct linestring"
);
-
- // mock up sketch cancel
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
- handler.deactivate();
- t.eq(log.type, "cancel", "[deactivate while drawing] cancel called");
-
+ log = logs.shift();
+ t.eq(log.type, "create", "[dblclick] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[dblclick] correct point");
+ t.ok(log.args[1] == handler.line,
+ "[dblclick] correct feature");
+ // cancel
+ handler.cancel();
+ t.eq(logs.length, 2, "[cancel] called back");
+ log = logs.shift();
+ t.eq(log.type, "cancel", "[cancel] canced called");
+ t.geom_eq(log.args[0],
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-200, 125)
+ ]),
+ "[cancel] correct linestring"
+ );
+ log = logs.shift();
+ t.eq(log.type, "create", "[cancel] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
+
map.destroy();
- }
+ }
+ function test_toggle_freehand(t) {
+ t.plan(2);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control, {
+ done: function(g) {
+ log++;
+ }
+ }, {persist: true});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ log = 0;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.eq(log, 1, "feature drawn when shift pressed on mousedown");
+
+ log = 0;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.eq(log, 0, "feature not drawn when shift not pressed on mousedown");
+ }
+
+ function test_persist(t) {
+ t.plan(4);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ handler.persist = false;
+ var feature1 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+ t.ok(feature1.layer == null, "a) feature1 destroyed");
+
+ handler.persist = true;
+ var feature2 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+ t.ok(feature2.layer != null, "b) feature2 not destroyed");
+
+ var feature3 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+ t.ok(feature3.layer != null, "c) feature3 not destroyed");
+ t.ok(feature2.layer == null, "c) feature2 destroyed");
+
+ map.destroy();
+ }
+
+ function test_persist_freehand(t) {
+ t.plan(6);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ handler.persist = false;
+ var feature1 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.ok(feature1.layer == null, "a) feature1 destroyed");
+
+ handler.persist = true;
+ feature2 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.ok(feature2.layer != null, "b) feature2 not destroyed");
+
+ feature3 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.ok(feature3.layer != null, "c) feature3 not destroyed");
+ t.ok(feature2.layer == null, "c) feature2 destroyed");
+
+ feature4 = handler.line;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.ok(feature4.layer != null, "d) feature4 not destroyed");
+ t.ok(feature3.layer == null, "c) feature3 destroyed");
+
+ map.destroy();
+ }
+
function test_Handler_Path_destroy(t) {
t.plan(6);
var map = new OpenLayers.Map('map');
@@ -175,9 +496,251 @@
"handler.line is null after destroy");
map.destroy();
}
-
+ //
+ // Sequence tests
+ //
+ // Sequence tests basically involve executing a sequence of events
+ // and testing the resulting geometry.
+ //
+ // Below are tests for various drawing sequences. Tests can be
+ // added here each a non-working sequence is found.
+ //
+ // stopDown:true, stopUp:true
+ // a) click on (0, 0)
+ // b) mousedown on (0.5, 0.5)
+ // c) mouseup on (1, 1)
+ // d) dblclick on (10, 10)
+ function test_sequence1(t) {
+ t.plan(1);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control,
+ {done: function(g) { log.geometry = g; }},
+ {stopDown: true, stopUp: true}
+ );
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+ log = {};
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) mousedown on (0.5, 0.5)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ // c) mouseup on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // d) dblclick on (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "geometry is correct");
+ }
+
+ // stopDown:false, stopUp:false
+ // a) click on (0, 0)
+ // b) mousedown on (0.5, 0.5)
+ // c) mouseup on (1, 1)
+ // d) dblclick on (10, 10)
+ function test_sequence2(t) {
+ t.plan(1);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control,
+ {done: function(g) { log.geometry = g; }},
+ {stopDown: false, stopUp: false}
+ );
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+ log = {};
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) mousedown on (0.5, 0.5)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ // c) mouseup on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // d) dblclick on (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "geometry is correct");
+ }
+
+ // a) click
+ // b) dblclick
+ // c) mousedown holding shift key
+ // d) mousemove holding shift key
+ function test_sequence3(t) {
+ t.plan(1);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) click on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // c) click on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // d) mousemove to (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10), shiftKey: true});
+ t.geom_eq(handler.line.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-149, 74), // (1, 1)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "geometry is correct after mousemove");
+ }
+
+ // a) click
+ // b) dblclick
+ // c) mousedown holding shift key
+ // d) mousemove holding shift key
+ function test_sequence4(t) {
+ t.plan(2);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Path(control,
+ {done: function(g) { log.geometry = g; }},
+ {stopDown: false, stopUp: false}
+ );
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+ log = {};
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) dblclick on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-149, 74) // (1, 1)
+ ]), "geometry is correct after dblclick");
+ // c) mousedown holding shift key on (1, 1)
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ // d) mousemove holding shift key to (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10), shiftKey: true});
+ t.geom_eq(handler.line.geometry,
+ new OpenLayers.Geometry.LineString([
+ new OpenLayers.Geometry.Point(-149, 74), // (1, 1)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ]), "geometry is correct after mousemove");
+ }
+
</script>
</head>
<body>
Copied: sandbox/cmoullet/openlayers/tests/Handler/Pinch.html (from rev 11410, trunk/openlayers/tests/Handler/Pinch.html)
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Pinch.html (rev 0)
+++ sandbox/cmoullet/openlayers/tests/Handler/Pinch.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -0,0 +1,264 @@
+<html>
+<head>
+ <script src="../OLLoader.js"></script>
+ <script type="text/javascript">
+ function test_constructor(t) {
+ t.plan(3);
+ var control = new OpenLayers.Control();
+ control.id = Math.random();
+ var callbacks = {foo: "bar"};
+ var options = {bar: "foo"};
+
+ var oldInit = OpenLayers.Handler.prototype.initialize;
+
+ OpenLayers.Handler.prototype.initialize = function(con, call, opt) {
+ t.eq(con.id, control.id,
+ "constructor calls parent with the correct control");
+ t.eq(call, callbacks,
+ "constructor calls parent with the correct callbacks");
+ t.eq(opt, options,
+ "constructor calls parent with the correct options");
+ };
+ var handler = new OpenLayers.Handler.Pinch(control, callbacks, options);
+
+ OpenLayers.Handler.prototype.initialize = oldInit;
+ }
+
+ function test_activate(t) {
+ t.plan(3);
+ var map = new OpenLayers.Map('map');
+ var control = new OpenLayers.Control();
+ map.addControl(control);
+ var handler = new OpenLayers.Handler.Pinch(control);
+ handler.active = true;
+ var activated = handler.activate();
+ t.ok(!activated,
+ "activate returns false if the handler was already active");
+ handler.active = false;
+ handler.pinching = true;
+ activated = handler.activate();
+ t.ok(activated,
+ "activate returns true if the handler was not already active");
+ t.ok(!handler.pinching,
+ "activate sets pinching to false");
+
+ }
+
+ function test_events(t) {
+ // each handled event should be activated twice when handler is
+ // activated, so:
+ // 27 = 4tests * 2*3events + 1tests * 3events
+ t.plan(27);
+
+ var map = new OpenLayers.Map('map');
+ var control = new OpenLayers.Control();
+ map.addControl(control);
+ var handler = new OpenLayers.Handler.Pinch(control);
+
+ // list below events that should be handled (events) and those
+ // that should not be handled (nonevents) by the handler
+ var events = ["touchend", "touchmove", "touchstart"];
+ var nonevents = ["mousedown", "mouseup", "mousemove", "mouseout",
+ "click", "dblclick", "resize", "focus", "blur"];
+ map.events.registerPriority = function(type, obj, func) {
+ // this is one of the mock handler methods
+ t.eq(OpenLayers.Util.indexOf(nonevents, type), -1,
+ "registered method is not one of the events " +
+ "that should not be handled: " + type);
+ t.ok(OpenLayers.Util.indexOf(events, type) > -1,
+ "activate calls registerPriority with browser event: " + type);
+ t.eq(typeof func, "function",
+ "activate calls registerPriority with a function");
+ t.eq(obj["CLASS_NAME"], "OpenLayers.Handler.Pinch",
+ "activate calls registerPriority with the handler");
+ };
+ handler.activate();
+ handler.deactivate();
+
+ // set browser event like properties on the handler
+ for(var i=0; i<events.length; ++i) {
+ setMethod(events[i]);
+ }
+ function setMethod(key) {
+ handler[key] = function() {return key;};
+ }
+
+ map.events.registerPriority = function(type, obj, func) {
+ var r = func();
+ if(typeof r == "string") {
+ t.eq(r, type,
+ "activate calls registerPriority with the correct method");
+ }
+ }
+ handler.activate();
+
+ }
+
+ function test_callbacks(t) {
+ t.plan(23);
+
+ var map = new OpenLayers.Map('map', {controls: []});
+
+ var control = new OpenLayers.Control();
+ map.addControl(control);
+
+ // set fake values for touches
+ var testEvents = {
+ start: {
+ type: 'start',
+ touches: [{
+ clientX: 100,
+ clientY: 0
+ }, {
+ clientX: 0,
+ clientY: 0
+ }]
+ },
+ move: {
+ type: 'move',
+ touches: [{
+ clientX: 100,
+ clientY: 0
+ }, {
+ clientX: 20,
+ clientY: 0
+ }]
+ },
+ done: {
+ type: 'done',
+ touches: []
+ }
+ };
+
+ // set callback methods
+ var customCb = OpenLayers.Function.False;
+ var cb = function(evt) {
+ var tch = testEvents[evt.type].touches;
+ t.ok(evt.touches[0].clientX == tch[0].clientX &&
+ evt.touches[0].clientY == tch[0].clientY,
+ "touchstart sets first touch position correctly in evt");
+ t.ok(evt.touches[1].clientX == tch[1].clientX &&
+ evt.touches[1].clientY == tch[1].clientY,
+ "touchstart sets second touch position correctly in evt");
+ t.eq(handler.start.distance, 100, "start distance is " +
+ "always the same");
+ customCb.apply(this, arguments);
+ }
+ var callbacks = {
+ start: cb,
+ move: cb,
+ done: customCb
+ };
+
+ var handler = new OpenLayers.Handler.Pinch(control, callbacks);
+ handler.activate();
+
+ var old_isMultiTouch = OpenLayers.Event.isMultiTouch;
+ var old_stop = OpenLayers.Event.stop;
+
+ // test single touch
+ OpenLayers.Event.isMultiTouch = function() {
+ return false;
+ }
+ handler.started = true;
+ handler.start = {
+ distance: 100,
+ delta: 0,
+ scale: 1
+ };
+ handler.last = {
+ distance: 150,
+ delta: 10,
+ scale: 1.5
+ };
+ map.events.triggerEvent("touchstart", testEvents.start);
+ t.ok(!handler.started, "1) touchstart (singletouch) sets started to false");
+ t.eq(handler.start, null, "1) touchstart (singletouch) sets start to null");
+ t.eq(handler.last, null, "1) touchstart (singletouch) sets last to null");
+
+ OpenLayers.Event.stop = function(evt, allowDefault) {
+ if(allowDefault) {
+ t.fail(
+ "touchstart is prevented from falling to other elements");
+ }
+ }
+ OpenLayers.Event.isMultiTouch = function(evt) {
+ var res = old_isMultiTouch(evt);
+ t.ok(res, "fake event is a mutitouch touch event");
+ return res;
+ }
+ customCb = function(evt, pinchdata) {
+ t.eq(pinchdata.distance, 100, "2) calculated distance is correct");
+ t.eq(pinchdata.delta, 0, "2) calculated delta is correct");
+ t.eq(pinchdata.scale, 1, "2) calculated scale is correct");
+ }
+ map.events.triggerEvent("touchstart", testEvents.start);
+ t.ok(handler.started, "2) touchstart sets the started flag to true");
+ t.ok(!handler.pinching, "2) touchstart sets the pinching flag to false");
+
+ customCb = function(evt, pinchdata) {
+ t.eq(pinchdata.distance, 80, "3) calculated distance is correct");
+ t.eq(pinchdata.delta, 20, "3) calculated delta is correct");
+ t.eq(pinchdata.scale, 0.8, "3) calculated scale is correct");
+ }
+ map.events.triggerEvent("touchmove", testEvents.move);
+ t.ok(handler.started, "3) started flag still set to true");
+ t.ok(handler.pinching, "3) touchmove sets the pinching flag to true");
+
+
+ customCb = function(evt, first, last) {
+ t.eq(first.distance, 100, "4) calculated distance is correct");
+ t.eq(first.delta, 0, "4) calculated delta is correct");
+ t.eq(first.scale, 1, "4) calculated scale is correct");
+ t.eq(last.distance, 80, "4) calculated distance is correct");
+ t.eq(last.delta, 20, "4) calculated delta is correct");
+ t.eq(last.scale, 0.8, "4) calculated scale is correct");
+ }
+ map.events.triggerEvent("touchend", testEvents.done);
+ t.ok(!handler.started, "4) started flag is set to false");
+ t.ok(!handler.pinching, "4) touchdone sets the pinching flag to false");
+
+ OpenLayers.Event.stop = old_stop;
+ OpenLayers.Event.isMultiTouch = old_isMultiTouch;
+
+ // test move or done before start
+ customCb = function(evt) {
+ t.fail("should not pass here")
+ }
+ map.events.triggerEvent("touchmove", testEvents.move);
+ map.events.triggerEvent("touchend", testEvents.end);
+
+ }
+
+ function test_deactivate(t) {
+ t.plan(6);
+ var map = new OpenLayers.Map('map');
+ var control = new OpenLayers.Control();
+ map.addControl(control);
+ var handler = new OpenLayers.Handler.Pinch(control);
+ handler.active = false;
+ var deactivated = handler.deactivate();
+ t.ok(!deactivated,
+ "deactivate returns false if the handler was not already active");
+ handler.active = true;
+ handler.pinching = true;
+ deactivated = handler.deactivate();
+ t.ok(deactivated,
+ "deactivate returns true if the handler was active already");
+ t.ok(!handler.started,
+ "deactivate sets started to false");
+ t.ok(!handler.pinching,
+ "deactivate sets pinching to false");
+ t.ok(handler.start == null,
+ "deactivate sets start to null");
+ t.ok(handler.last == null,
+ "deactivate sets start to null");
+ }
+
+
+ </script>
+</head>
+<body>
+ <div id="map" style="width: 300px; height: 150px;"/>
+</body>
+</html>
Modified: sandbox/cmoullet/openlayers/tests/Handler/Point.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Point.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Handler/Point.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -25,11 +25,26 @@
}
function test_Handler_Point_activation(t) {
- t.plan(3);
- var map = new OpenLayers.Map('map');
+ t.plan(10);
+ var log = [];
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
var control = new OpenLayers.Control();
+ var handler = new OpenLayers.Handler.Point(control, {
+ "create": function(g, f) {
+ log.push({geometry: g, feature: f});
+ }
+ });
+ control.handler = handler;
map.addControl(control);
- var handler = new OpenLayers.Handler.Point(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
handler.active = true;
var activated = handler.activate();
t.ok(!activated,
@@ -38,24 +53,52 @@
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
+ t.ok(handler.layer instanceof OpenLayers.Layer.Vector,
+ "activate creates a vector layer");
+ t.ok(handler.layer.map == map,
+ "activate adds the vector layer to the map");
+ t.ok(handler.point instanceof OpenLayers.Feature.Vector,
+ "activate creates a feature");
+ t.ok(handler.point.layer == handler.layer,
+ "activate adds the feature to the layer");
+ t.eq(log.length, 1,
+ "activate calls \"create\" once");
+ t.geom_eq(log[0].geometry, handler.point.geometry,
+ "\"create\" called with expected geometry");
+ t.ok(log[0].feature == handler.point,
+ "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
+
+ map.destroy();
}
function test_Handler_Point_events(t) {
- t.plan(29);
-
- var map = new OpenLayers.Map('map');
- var control = {
- map: map
- };
- var handler = new OpenLayers.Handler.Point(control);
+ t.plan(34);
+ var log = [];
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control();
+ var handler = new OpenLayers.Handler.Point(control, {
+ "create": function(g, f) {
+ log.push({geometry: g, feature: f});
+ }
+ });
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
// list below events that should be handled (events) and those
// that should not be handled (nonevents) by the handler
- var events = ["click", "dblclick", "mousedown", "mouseup", "mousemove"];
- var nonevents = ["mouseout", "resize", "focus", "blur"];
+ var events = ["click", "dblclick", "mousedown", "mouseup", "mousemove", "mouseout"];
+ var nonevents = ["resize", "focus", "blur"];
map.events.registerPriority = function(type, obj, func) {
var r = func();
if(typeof r == "string") {
@@ -99,7 +142,7 @@
}
function test_callbacks(t) {
- t.plan(10);
+ t.plan(28);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -108,68 +151,189 @@
isBaseLayer: true
});
map.addLayer(layer);
- var control = new OpenLayers.Control({
- });
- var log = {};
+ var control = new OpenLayers.Control({});
+ var logs = [], log;
var handler = new OpenLayers.Handler.Point(control, {
create: function() {
- log.type = "create",
- log.args = arguments
+ logs.push({type: "create", args: arguments});
},
modify: function() {
- log.type = "modify",
- log.args = arguments
+ logs.push({type: "modify", args: arguments});
},
done: function() {
- log.type = "done",
- log.args = arguments
+ logs.push({type: "done", args: arguments});
},
cancel: function() {
- log.type = "cancel",
- log.args = arguments
+ logs.push({type: "cancel", args: arguments});
}
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // mock up feature drawing
+ // create point
handler.activate();
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(log.type, "create", "[mousedown] create called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct point");
- t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct sketch feature");
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 0)});
+ t.eq(logs.length, 1, "[activate] called back");
+ log = logs.shift();
+ t.eq(log.type, "create", "[activate] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[activate] correct point");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousedown] correct point");
+ t.geom_eq(log.args[1].geometry,
+ new OpenLayers.Geometry.Point(-150, 75),
+ "[mousedown] correct feature");
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 0)});
+ t.eq(logs.length, 0, "[mousemove] not called back");
+ // mouse up (no finalize - we moved)
+ handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(1, 0)});
+ t.eq(logs.length, 0, "[mouseup] not called back");
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 0)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 75), "[mousemove] correct point");
- t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-149, 75), "[mousemove] correct sketch feature");
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(1, 0)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-148, 75),
+ "[mousemove] correct point");
+ t.geom_eq(log.args[1].geometry,
+ new OpenLayers.Geometry.Point(-148, 75),
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(2, 0)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-148, 75),
+ "[mousedown] correct point");
+ t.geom_eq(log.args[1].geometry,
+ new OpenLayers.Geometry.Point(-148, 75),
+ "[mousedown] correct feature");
+ // mouse up
+ handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
+ t.eq(logs.length, 2, "[mouseup] called back twice");
+ log = logs.shift();
t.eq(log.type, "done", "[mouseup] done called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 75), "[mouseup] correct point");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-148, 75),
+ "[mouseup] correct point");
+ log = logs.shift();
+ t.eq(log.type, "create", "[mouseup] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[activate] correct point");
+ // mouse up on same pixel
+ handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
+ t.eq(logs.length, 0, "[mouseup] not called back");
+ // cancel
+ handler.cancel();
+ t.eq(logs.length, 2, "[cancel] called back");
+ log = logs.shift();
+ t.eq(log.type, "cancel", "[cancel] canced called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
+ log = logs.shift();
+ t.eq(log.type, "create", "[cancel] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
- // mock up feature drawing with a cancel
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- handler.deactivate();
- t.eq(log.type, "cancel", "[deactivate while drawing] cancel called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[deactivate while drawing] correct point");
+ map.destroy();
+ }
+
+ function test_persist(t) {
+ t.plan(3);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Point(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+ handler.activate();
+
+ handler.persist = false;
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(handler.layer.features.length, 1,
+ "feature destroyed on mouseup when persist is false");
+
+ handler.persist = true;
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 0)});
+ t.eq(handler.layer.features.length, 2,
+ "feature not destroyed on mouseup when persist is true");
+ var feature = handler.layer.features[0];
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(2, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
+ t.ok(handler.layer.features[0] !== feature,
+ "persisted feature destroyed on next mouseup");
+
map.destroy();
}
function test_Handler_Point_deactivation(t) {
- t.plan(1);
- var map = new OpenLayers.Map('map');
+ t.plan(5);
+ var log = [];
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
var control = new OpenLayers.Control();
+ var handler = new OpenLayers.Handler.Point(control, {
+ "cancel": function(g) {
+ log.push({geometry: g});
+ }
+ });
+ control.handler = handler;
map.addControl(control);
-
- var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
handler.activate();
+ var _layer = handler.layer;
+ var _geometry = handler.point.geometry;
+ handler.deactivate();
+ t.eq(_layer.map, null,
+ "deactivates removes the layer from the map");
+ t.eq(handler.layer, null,
+ "deactivates sets its \"layer\" property to null");
+ t.eq(log.length, 1,
+ "deactivates calls \"cancel\" once");
+ t.ok(log[0].geometry.equals(_geometry),
+ "\"cancel\" called with expected geometry");
+
+ handler.activate();
handler.layer.destroy();
handler.deactivate();
t.eq(handler.layer, null,
"deactivate doesn't throw an error if layer was" +
" previously destroyed");
+
+ map.destroy();
}
function test_Handler_Point_bounds(t) {
@@ -183,7 +347,7 @@
var activated = handler.activate();
var px = new OpenLayers.Pixel(150, 75);
var evt = {xy: px, which: 1};
- handler.mousedown(evt);
+ handler.mousemove(evt);
var lonlat = map.getLonLatFromPixel(px);
t.eq(handler.point.geometry.x, lonlat.lon, "X is correct");
t.eq(handler.point.geometry.y, lonlat.lat, "Y is correct");
@@ -203,8 +367,6 @@
var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
handler.activate();
- var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
- handler.mousedown(evt);
t.ok(handler.layer,
"handler has a layer prior to destroy");
Modified: sandbox/cmoullet/openlayers/tests/Handler/Polygon.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Polygon.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Handler/Polygon.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -25,12 +25,27 @@
}
function test_Handler_Polygon_activation(t) {
- t.plan(3);
- var map = new OpenLayers.Map('map');
+ t.plan(13);
+ var log = [];
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
var control = new OpenLayers.Control();
+ var handler = new OpenLayers.Handler.Polygon(control, {
+ "create": function(g, f) {
+ log.push({geometry: g, feature: f});
+ }
+ });
+ control.handler = handler;
map.addControl(control);
- var handler = new OpenLayers.Handler.Polygon(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.active = true;
+
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
@@ -38,41 +53,68 @@
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
+ t.ok(handler.layer instanceof OpenLayers.Layer.Vector,
+ "activate creates a vector layer");
+ t.ok(handler.layer.map == map,
+ "activate adds the vector layer to the map");
+ t.ok(handler.point instanceof OpenLayers.Feature.Vector,
+ "activate creates a point feature");
+ t.ok(handler.point.layer == handler.layer,
+ "activate adds the point feature to the layer");
+ t.ok(handler.line instanceof OpenLayers.Feature.Vector,
+ "activates creates a line feature");
+ t.ok(handler.polygon instanceof OpenLayers.Feature.Vector,
+ "acttivates creates a polygon feature");
+ t.ok(handler.polygon.layer == handler.layer,
+ "activate adds the polygin feature to the layer");
+ t.eq(log.length, 1,
+ "activate calls \"create\" once");
+ t.geom_eq(log[0].geometry, handler.point.geometry,
+ "\"create\" called with expected geometry");
+ t.ok(log[0].feature == handler.polygon,
+ "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
- map.destroy();
+
+ map.destroy();
}
- function test_Handler_Polygon_bounds(t) {
+ function test_bounds_stopDown_true(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
map.zoomToMaxExtent();
var control = new OpenLayers.Control();
map.addControl(control);
- var handler = new OpenLayers.Handler.Polygon(control, {});
+ var handler = new OpenLayers.Handler.Polygon(control, {},
+ {stopDown: true, stopUp: true});
var activated = handler.activate();
-
+ // click on (150, 75)
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
+ handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
- var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
+ // click on (175, 100)
+ evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
t.ok(handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds");
- var evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
+ // mousedown on (175, 100)
+ evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousedown(evt);
- var evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
+ // mousemove to (125, 100)
+ evt = {xy: new OpenLayers.Pixel(125, 100), which: 1};
handler.mousemove(evt);
+ // test that the bounds have changed
t.ok(!handler.polygon.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
"Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)");
map.destroy();
}
function test_callbacks(t) {
- t.plan(15);
+ t.plan(45);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -83,57 +125,141 @@
map.addLayer(layer);
var control = new OpenLayers.Control({
});
- var log = {};
+ var logs = [], log;
var handler = new OpenLayers.Handler.Polygon(control, {
create: function() {
- log.type = "create",
- log.args = arguments
+ logs.push({type: "create", args: arguments});
},
+ point: function() {
+ logs.push({type: "point", args: arguments});
+ },
modify: function() {
- log.type = "modify",
- log.args = arguments
+ logs.push({type: "modify", args: arguments});
},
done: function() {
- log.type = "done",
- log.args = arguments
+ logs.push({type: "done", args: arguments});
},
cancel: function() {
- log.type = "cancel",
- log.args = arguments
+ logs.push({type: "cancel", args: arguments});
}
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // mock up feature drawing
+ // create polygon
handler.activate();
- // click at 0, 0
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(log.type, "create", "[mousedown] create called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mousedown] correct sketch feature");
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.activate();
+ t.eq(logs.length, 1, "[activate] called back");
+ log = logs.shift();
+ t.eq(log.type, "create", "[activate] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[activate] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[activate] correct feature");
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousemove] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousedown] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousedown] correct feature");
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 2, "[mouseup] called back twice");
+ log = logs.shift();
+ t.eq(log.type, "point", "[mouseup] point called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ var geom = new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75)
+ ])
+ ]);
+ geom.components[0].addComponent(
+ new OpenLayers.Geometry.Point(-150, 75),
+ geom.components[0].components.length
+ );
+ t.geom_eq(log.args[1], geom, "[mouseup] correct polygon");
+ log = logs.shift();
t.eq(log.type, "modify", "[mouseup] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- // move to 10, 10 and click
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[mouseup] correct feature");
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65),
+ "[mousedown] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousedown] correct feature");
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ log = logs.shift();
+ log = logs.shift();
// move to 0, 10 and double click
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 65), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
- handler.dblclick({type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 65),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 1, "[mousedown] not called back");
+ log = logs.shift();
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 2, "[mouseup] called back");
+ log = logs.shift();
+ log = logs.shift();
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 0, "[mousedown] not called back");
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 0, "[mouseup] not called back");
+ // dblclick
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 2, "[dblclick] called back twice");
+ log = logs.shift();
t.eq(log.type, "done", "[dblclick] done called");
t.geom_eq(
log.args[0],
@@ -147,17 +273,232 @@
]),
"[dblclick] correct polygon"
);
-
- // mock up sketch cancel
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
- handler.deactivate();
- t.eq(log.type, "cancel", "[deactivate while drawing] cancel called");
-
+ log = logs.shift();
+ t.eq(log.type, "create", "[dblclick] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[dblclick] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[dblclick] correct feature");
+ // cancel
+ handler.cancel();
+ t.eq(logs.length, 2, "[cancel] called back");
+ log = logs.shift();
+ t.eq(log.type, "cancel", "[cancel] canced called");
+ log = logs.shift();
+ t.eq(log.type, "create", "[cancel] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
+
map.destroy();
}
+ function test_toggle_freehand(t) {
+ t.plan(2);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control, {
+ done: function(g) {
+ log++;
+ }
+ }, {persist: true});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ log = 0;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.eq(log, 1, "feature drawn when shift pressed on mousedown");
+
+ log = 0;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.eq(log, 0, "feature not drawn when shift not pressed on mousedown");
+ }
+
+ function test_persist(t) {
+ t.plan(4);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ handler.persist = false;
+ var feature1 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
+ t.ok(feature1.layer == null, "a) feature1 destroyed");
+
+ handler.persist = true;
+ var feature2 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
+ t.ok(feature2.layer != null, "b) feature2 not destroyed");
+
+ var feature3 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
+ t.ok(feature3.layer != null, "c) feature3 not destroyed");
+ t.ok(feature2.layer == null, "c) feature2 destroyed");
+
+ map.destroy();
+ }
+
+ function test_persist_freehand(t) {
+ t.plan(6);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+
+ handler.persist = false;
+ var feature1 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ t.ok(feature1.layer == null, "a) feature1 destroyed");
+
+ handler.persist = true;
+ var feature2 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ t.ok(feature2.layer != null, "b) feature2 not destroyed");
+
+ var feature3 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ t.ok(feature3.layer != null, "c) feature3 not destroyed");
+ t.ok(feature2.layer == null, "c) feature2 destroyed");
+
+ feature4 = handler.polygon;
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1), shiftKey: true});
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
+ t.ok(feature4.layer != null, "d) feature4 not destroyed");
+ t.ok(feature3.layer == null, "c) feature3 destroyed");
+
+ map.destroy();
+ }
+
function test_rings(t) {
t.plan(12);
@@ -204,6 +545,7 @@
log = [];
// start at -9, 9
event = {xy: new OpenLayers.Pixel(-9, 9)};
+ trigger("mousemove", event);
trigger("mousedown", event);
trigger("mouseup", event);
// draw to -1, 9
@@ -228,7 +570,7 @@
trigger("dblclick", event);
// make assertions
- t.eq(log.length, 9, "a) correct number of events");
+ t.eq(log.length, 14, "a) correct number of events");
t.eq(log[log.length-1].type, "featureadded", "a) featureadded event last");
t.eq(log[log.length-1].feature.geometry.getArea(), 64, "a) correct polygon area");
@@ -236,6 +578,7 @@
log = [];
// start at -6, 6
event = {xy: new OpenLayers.Pixel(-6, 6), altKey: true};
+ trigger("mousemove", event);
trigger("mousedown", event);
trigger("mouseup", event);
// draw to -3, 6
@@ -260,7 +603,7 @@
trigger("dblclick", event);
// make assertions
- t.eq(log.length, 8, "b) correct number of events");
+ t.eq(log.length, 13, "b) correct number of events");
t.eq(log[log.length-1].type, "sketchcomplete", "b) sketchcomplete event last");
t.eq(log[log.length-1].feature.geometry.getArea(), 55, "b) correct polygon area");
@@ -269,6 +612,7 @@
log = [];
// start at -2, 2
event = {xy: new OpenLayers.Pixel(-2, 2)};
+ trigger("mousemove", event);
trigger("mousedown", event);
trigger("mouseup", event);
// draw to 2, 2
@@ -293,7 +637,7 @@
trigger("dblclick", event);
// make assertions
- t.eq(log.length, 9, "c) correct number of events");
+ t.eq(log.length, 14, "c) correct number of events");
t.eq(log[log.length-1].type, "featureadded", "c) featureadded event last");
t.eq(log[log.length-1].feature.geometry.getArea(), 16, "c) correct polygon area");
@@ -301,6 +645,7 @@
log = [];
// start at -1, 1
event = {xy: new OpenLayers.Pixel(-1, 1), altKey: true};
+ trigger("mousemove", event);
trigger("mousedown", event);
trigger("mouseup", event);
// draw to 1, 1
@@ -330,7 +675,7 @@
trigger("dblclick", event);
// make assertions
- t.eq(log.length, 11, "d) correct number of events");
+ t.eq(log.length, 18, "d) correct number of events");
t.eq(log[log.length-1].type, "sketchcomplete", "d) sketchcomplete event last");
t.eq(log[log.length-1].feature.geometry.getArea(), 12, "d) correct polygon area");
@@ -338,7 +683,6 @@
map.destroy();
}
-
function test_Handler_Polygon_destroy(t) {
t.plan(8);
var map = new OpenLayers.Map('map');
@@ -372,8 +716,158 @@
map.destroy();
}
+ //
+ // Sequence tests
+ //
+ // Sequence tests basically involve executing a sequence of events
+ // and testing the resulting geometry.
+ //
+ // Below are tests for various drawing sequences. Tests can be
+ // added here each a non-working sequence is found.
+ //
+ // stopDown:true, stopUp:true
+ // a) click on (0, 0)
+ // b) mousedown on (0.5, 0.5)
+ // c) mouseup on (1, 1)
+ // d) click on (0, 10)
+ // e) dblclick on (10, 10)
+ function test_sequence1(t) {
+ t.plan(1);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control,
+ {done: function(g) { log.geometry = g; }},
+ {stopDown: true, stopUp: true}
+ );
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+ handler.activate();
+ log = {};
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) mousedown on (0.5, 0.5)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ // c) mouseup on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // d) click on (0, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ // e) dblclick on (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ])
+ ]), "geometry is correct");
+ }
+
+ // stopDown:false, stopUp:false
+ // a) click on (0, 0)
+ // b) mousedown on (0.5, 0.5)
+ // c) mouseup on (1, 1)
+ // d) click on (0, 10)
+ // e) dblclick on (10, 10)
+ function test_sequence2(t) {
+ t.plan(1);
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control,
+ {done: function(g) { log.geometry = g; }},
+ {stopDown: false, stopUp: false}
+ );
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+
+ handler.activate();
+ log = {};
+
+ // a) click on (0, 0)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ // b) mousedown on (0.5, 0.5)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0.5, 0.5)});
+ // c) mouseup on (1, 1)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(1, 1)});
+ // d) click on (0, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ // e) dblclick on (10, 10)
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ])
+ ]), "geometry is correct");
+ }
+
</script>
</head>
<body>
Modified: sandbox/cmoullet/openlayers/tests/Layer/EventPane.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Layer/EventPane.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Layer/EventPane.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -58,11 +58,11 @@
// t.plan( 2 );
if (OpenLayers.BROWSER_NAME != "firefox" && OpenLayers.BROWSER_NAME != "mozilla") {
- t.plan(4);
+ t.plan(4);
} else {
- t.plan(0);
- t.debug_print("Firefox gives different results for different browsers on setMap on EventPane, so just don't run it for now.")
- return;
+ t.plan(0);
+ t.debug_print("Firefox gives different results for different browsers on setMap on EventPane, so just don't run it for now.")
+ return;
}
var map = new OpenLayers.Map('map');
@@ -84,19 +84,23 @@
layer2.getWarningHTML = function() { this.warning = true; return ""; }
map.addLayer(layer2);
- t.ok( !layer2.warning, "warning not registered on mapObject load" );
+ t.ok(!layer2.warning, "warning not registered on mapObject load");
- map.events.register("mousemove", map, function () {
- t.ok(true, "got mouse move");
+ var log = [];
+ map.events.register("mousemove", map, function(event) {
+ log.push(event);
});
- if( document.createEvent ) { // Mozilla
- var evObj = document.createEvent('MouseEvents');
- evObj.initEvent( 'mousemove', true, false );
- layer.pane.dispatchEvent(evObj);
- } else if( document.createEventObject ) { // IE
- layer.pane.fireEvent('onmousemove');
+ if (document.createEvent) { // Mozilla
+ var evObj = document.createEvent('MouseEvents');
+ evObj.initEvent('mousemove', true, false);
+ map.eventsDiv.dispatchEvent(evObj);
+ } else if(document.createEventObject) { // IE
+ map.eventsDiv.fireEvent('onmousemove');
}
+
+ t.eq(log.length, 1, "got one event");
+
}
function test_Layer_EventPane_setVisibility (t) {
Modified: sandbox/cmoullet/openlayers/tests/Map.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Map.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Map.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -1667,7 +1667,26 @@
map.destroy();
}
+ function test_pixel_lonlat(t) {
+
+ t.plan(4);
+ var map = new OpenLayers.Map({
+ div: "map",
+ layers: [
+ new OpenLayers.Layer("name", {isBaseLayer:true})
+ ]
+ });
+ map.zoomToMaxExtent();
+ var px = map.getPixelFromLonLat(map.getLonLatFromPixel(new OpenLayers.Pixel(100, 100)));
+ t.eq(px.x, 100, "x is the same in and ot");
+ t.eq(px.y, 100, "y is the same in and out");
+ var ll = map.getLonLatFromPixel(map.getPixelFromLonLat(new OpenLayers.LonLat(100, 100)));
+ t.ok((ll.lon > (100 -map.getResolution()) && (ll.lon < (100 + map.getResolution()))), "lon is the same in and ot");
+ t.ok((ll.lat > (100 -map.getResolution()) && (ll.lat < (100 + map.getResolution()))), "lat is the same in and ot");
+ map.destroy();
+ }
+
</script>
</head>
<body>
Modified: sandbox/cmoullet/openlayers/tests/Util.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Util.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/Util.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -1101,6 +1101,12 @@
t.eq(OpenLayers.Util.toFloat(b1), OpenLayers.Util.toFloat(b2),
"toFloat rounds large floats correctly #2");
}
+ function test_getFormattedLonLat(t) {
+ t.plan(1);
+ var z = 2 + (4/60) - 0.000002 ;
+ t.eq(OpenLayers.Util.getFormattedLonLat(z,"lon"), "02°04'00\"E",
+ "LonLat does not show 60 seconds.");
+ }
</script>
</head>
<body>
Modified: sandbox/cmoullet/openlayers/tests/list-tests.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/list-tests.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/list-tests.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -15,6 +15,7 @@
<li>Control/DragFeature.html</li>
<li>Control/DragPan.html</li>
<li>Control/DrawFeature.html</li>
+ <li>Control/Geolocate.html</li>
<li>Control/GetFeature.html</li>
<li>Control/Graticule.html</li>
<li>Control/KeyboardDefaults.html</li>
@@ -117,6 +118,7 @@
<li>Handler/Box.html</li>
<li>Handler/Click.html</li>
<li>Handler/Drag.html</li>
+ <li>Handler/Pinch.html</li>
<li>Handler/Feature.html</li>
<li>Handler/Hover.html</li>
<li>Handler/Keyboard.html</li>
Modified: sandbox/cmoullet/openlayers/tests/run-tests.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/run-tests.html 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tests/run-tests.html 2011-02-24 13:37:57 UTC (rev 11413)
@@ -686,7 +686,7 @@
timeout_seconds=4;
}
var no_close=document.getElementById( "dont_close_test_windows" );
- var action={ action_kind: "window", wnd_url: url.toString(), wnd_wnd: null, wnd_fn: fn, wnd_timeout_milliseconds: timeout_seconds*1000, wnd_no_close: no_close.checked };
+ var action={ action_kind: "window", wnd_url: url.toString() + (window.location.search || ""), wnd_wnd: null, wnd_fn: fn, wnd_timeout_milliseconds: timeout_seconds*1000, wnd_no_close: no_close.checked };
this.delay_total_milliseconds_left+=Test.AnotherWay._action_estimate_milliseconds( action );
this.delay_actions.push( action );
}
@@ -2410,4 +2410,10 @@
</div>
</span>
+<script>
+ if (/noscroll/.test(location.href)) {
+ document.getElementById('scroller').style.height='auto';
+ document.getElementById('right_frame').style.height='auto';
+ }
+</script>
</body></html>
Modified: sandbox/cmoullet/openlayers/tools/exampleparser.py
===================================================================
--- sandbox/cmoullet/openlayers/tools/exampleparser.py 2011-02-24 13:37:34 UTC (rev 11412)
+++ sandbox/cmoullet/openlayers/tools/exampleparser.py 2011-02-24 13:37:57 UTC (rev 11413)
@@ -20,7 +20,14 @@
missing_deps = False
try:
- import simplejson
+ import json
+except ImportError:
+ try:
+ import simplejson as json
+ except ImportError, E:
+ missing_deps = E
+
+try:
from BeautifulSoup import BeautifulSoup
except ImportError, E:
missing_deps = E
@@ -196,7 +203,7 @@
if __name__ == "__main__":
if missing_deps:
- print "This script requires simplejson and BeautifulSoup. You don't have them. \n(%s)" % E
+ print "This script requires json or simplejson and BeautifulSoup. You don't have them. \n(%s)" % E
sys.exit()
if len(sys.argv) > 1:
@@ -237,7 +244,7 @@
index = wordIndex(exampleList)
- json = simplejson.dumps({"examples": exampleList, "index": index})
+ json = json.dumps({"examples": exampleList, "index": index})
#give the json a global variable we can use in our js. This should be replaced or made optional.
json = 'var info=' + json
outFile.write(json)
More information about the Commits
mailing list