[OpenLayers-Commits] r10865 - in sandbox/camptocamp/geobretagne: .
examples lib/OpenLayers/Control lib/OpenLayers/Strategy
tests/Control tests/Strategy
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Nov 2 13:13:19 EDT 2010
Author: fvanderbiest
Date: 2010-11-02 10:13:19 -0700 (Tue, 02 Nov 2010)
New Revision: 10865
Modified:
sandbox/camptocamp/geobretagne/
sandbox/camptocamp/geobretagne/examples/mm.html
sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Measure.js
sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Panel.js
sandbox/camptocamp/geobretagne/lib/OpenLayers/Strategy/Fixed.js
sandbox/camptocamp/geobretagne/tests/Control/Measure.html
sandbox/camptocamp/geobretagne/tests/Strategy/Fixed.html
Log:
camptocamp/geobretagne sandbox: merge with r10801
Property changes on: sandbox/camptocamp/geobretagne
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk:9457-9468
/trunk/openlayers:9457-9468,9470-9476,9478-9558,9560-9580,9582-9591,9593-9607,9609-9618
+ /trunk:9457-9468
/trunk/openlayers:9457-9468,9470-9476,9478-9558,9560-9580,9582-9591,9593-9607,9609-9618,10794-10801
Modified: sandbox/camptocamp/geobretagne/examples/mm.html
===================================================================
--- sandbox/camptocamp/geobretagne/examples/mm.html 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/examples/mm.html 2010-11-02 17:13:19 UTC (rev 10865)
@@ -12,7 +12,8 @@
</style>
- <script type="text/javascript" src="http://clients.multimap.com/API/maps/1.1/metacarta_04"></script>
+ <!-- multimap api key for http://(www.)openlayers.org -->
+ <script type="text/javascript" src="http://developer.multimap.com/API/maps/1.2/OA10072915821139765"></script>
<script src="../lib/OpenLayers.js"></script>
Modified: sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Measure.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Measure.js 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Measure.js 2010-11-02 17:13:19 UTC (rev 10865)
@@ -92,7 +92,7 @@
* {Number} Timeout id of trigger for measurepartial.
*/
delayedTrigger: null,
-
+
/**
* APIProperty: persist
* {Boolean} Keep the temporary measurement sketch drawn after the
@@ -130,11 +130,20 @@
},
/**
+ * APIMethod: deactivate
+ */
+ deactivate: function() {
+ this.cancelDelay();
+ return OpenLayers.Control.prototype.deactivate.apply(this, arguments);
+ },
+
+ /**
* APIMethod: cancel
* Stop the control from measuring. If <persist> is true, the temporary
* sketch will be erased.
*/
cancel: function() {
+ this.cancelDelay();
this.handler.cancel();
},
@@ -164,9 +173,7 @@
* geometry - {<OpenLayers.Geometry>}
*/
measureComplete: function(geometry) {
- if(this.delayedTrigger) {
- window.clearTimeout(this.delayedTrigger);
- }
+ this.cancelDelay();
this.measure(geometry, "measure");
},
@@ -179,10 +186,17 @@
* geometry - {<OpenLayers.Geometry>} The sketch geometry.
*/
measurePartial: function(point, geometry) {
- if (geometry.getLength() > 0) {
- geometry = geometry.clone();
+ this.cancelDelay();
+ geometry = geometry.clone();
+ // when we're wating for a dblclick, we have to trigger measurepartial
+ // after some delay to deal with reflow issues in IE
+ if (this.handler.freehandMode(this.handler.evt)) {
+ // no dblclick in freehand mode
+ this.measure(geometry, "measurepartial");
+ } else {
this.delayedTrigger = window.setTimeout(
OpenLayers.Function.bind(function() {
+ this.delayedTrigger = null;
this.measure(geometry, "measurepartial");
}, this),
this.partialDelay
@@ -191,6 +205,17 @@
},
/**
+ * Method: cancelDelay
+ * Cancels the delay measurement that measurePartial began.
+ */
+ cancelDelay: function() {
+ if (this.delayedTrigger !== null) {
+ window.clearTimeout(this.delayedTrigger);
+ this.delayedTrigger = null;
+ }
+ },
+
+ /**
* Method: measure
*
* Parameters:
Modified: sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Panel.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Panel.js 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/lib/OpenLayers/Control/Panel.js 2010-11-02 17:13:19 UTC (rev 10865)
@@ -121,6 +121,9 @@
* Method: redraw
*/
redraw: function() {
+ for (var l=this.div.childNodes.length, i=l-1; i>=0; i--) {
+ this.div.removeChild(this.div.childNodes[i]);
+ }
this.div.innerHTML = "";
if (this.active) {
for (var i=0, len=this.controls.length; i<len; i++) {
Modified: sandbox/camptocamp/geobretagne/lib/OpenLayers/Strategy/Fixed.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/OpenLayers/Strategy/Fixed.js 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/lib/OpenLayers/Strategy/Fixed.js 2010-11-02 17:13:19 UTC (rev 10865)
@@ -97,14 +97,13 @@
* options - {Object} options to pass to protocol read.
*/
load: function(options) {
- var layer = this.layer;
- layer.events.triggerEvent("loadstart");
- layer.protocol.read(OpenLayers.Util.applyDefaults({
- callback: OpenLayers.Function.bind(this.merge, this,
- layer.map.getProjectionObject()),
- filter: layer.filter
+ this.layer.events.triggerEvent("loadstart");
+ this.layer.protocol.read(OpenLayers.Util.applyDefaults({
+ callback: this.merge,
+ filter: this.layer.filter,
+ scope: this
}, options));
- layer.events.un({
+ this.layer.events.un({
"visibilitychanged": this.load,
scope: this
});
@@ -113,28 +112,25 @@
/**
* Method: merge
* Add all features to the layer.
- *
- * Parameters:
- * mapProjection - {OpenLayers.Projection} the map projection
- * resp - {Object} options to pass to protocol read.
*/
- merge: function(mapProjection, resp) {
- var layer = this.layer;
- layer.destroyFeatures();
+ merge: function(resp) {
+ this.layer.destroyFeatures();
var features = resp.features;
if (features && features.length > 0) {
- if(!mapProjection.equals(layer.projection)) {
+ var remote = this.layer.projection;
+ var local = this.layer.map.getProjectionObject();
+ if(!local.equals(remote)) {
var geom;
for(var i=0, len=features.length; i<len; ++i) {
geom = features[i].geometry;
if(geom) {
- geom.transform(layer.projection, mapProjection);
+ geom.transform(remote, local);
}
}
}
- layer.addFeatures(features);
+ this.layer.addFeatures(features);
}
- layer.events.triggerEvent("loadend");
+ this.layer.events.triggerEvent("loadend");
},
CLASS_NAME: "OpenLayers.Strategy.Fixed"
Modified: sandbox/camptocamp/geobretagne/tests/Control/Measure.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/Control/Measure.html 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/tests/Control/Measure.html 2010-11-02 17:13:19 UTC (rev 10865)
@@ -68,52 +68,161 @@
}
- function test_partial(t) {
- t.plan(1);
+ function test_partial(t) {
- // set up
-
- var map, layer, control, geometry, log;
-
- map = new OpenLayers.Map("map", {units: "m"});
-
- layer = new OpenLayers.Layer(null, {isBaseLayer: true});
- map.addLayer(layer);
-
- map.zoomToMaxExtent();
-
- control = new OpenLayers.Control.Measure(OpenLayers.Handler.Path, {
- partialDelay: null
+ t.plan(28);
+
+ var map = new OpenLayers.Map({
+ div: "map",
+ units: "m",
+ resolutions: [1],
+ layers: [
+ new OpenLayers.Layer(null, {
+ isBaseLayer: true
+ })
+ ],
+ center: new OpenLayers.LonLat(0, 0)
});
+ var log = [];
+ var control = new OpenLayers.Control.Measure(
+ OpenLayers.Handler.Path, {persist: true,
+ eventListeners: {
+ measurepartial: function(evt) {
+ log.push(evt);
+ },
+ measure: function(evt){
+ log.push(evt);
+ }
+ }
+ }
+ );
map.addControl(control);
control.activate();
+
+
+ // convenience function to trigger mouse events
+ function trigger(type, x, y) {
+ map.events.triggerEvent(type, {
+ xy: new OpenLayers.Pixel(x, y)
+ })
+ };
+
+ // delay in seconds
+ var delay = control.partialDelay / 1000;
+
+ // establish first point
+ trigger("mousedown", 0, 0);
+ trigger("mouseup", 0, 0);
- control.events.on({
- "measurepartial": function(e) {
- log.measure = e.measure;
- }
- });
+
+ // a) move 10 pixels and click
+ trigger("mousemove", 0, 10);
+ trigger("mousedown", 0, 10);
+ trigger("mouseup", 0, 10);
+
+ // confirm measurepartial is not fired before delay
+ t.eq(log.length, 0, "a) no event fired yet")
- // test
+ t.delay_call(
+ // wait for delay then confirm event was logged
+ delay, function() {
+ t.eq(log.length, 1, "a) event logged")
+ t.eq(log[0].type, "measurepartial", "a) event logged");
+ t.eq(log[0].measure, 10, "a) correct measure");
+
+ // b) move 10 pixels and click
+ trigger("mousemove", 0, 20);
+ trigger("mousedown", 0, 20);
+ trigger("mouseup", 0, 20);
+
+ // confirm measurepartial is not fired before delay
+ t.eq(log.length, 1, "b) no event fired yet")
+
+ },
+ delay, function() {
+ t.eq(log.length, 2, "b) event logged");
+ t.eq(log[1].type, "measurepartial", "b) correct type");
+ t.eq(log[1].measure, 20, "b) correct measure");
- geometry = new OpenLayers.Geometry.LineString([
- new OpenLayers.Geometry.Point(1, 1),
- new OpenLayers.Geometry.Point(2, 1)
- ]);
+ // c) move 10 pixels and click
+ trigger("mousemove", 0, 30);
+ trigger("mousedown", 0, 30);
+ trigger("mouseup", 0, 30);
+ },
+ // wait for half delay and confirm event not logged
+ delay / 2, function() {
+ // confirm measurepartial is not fired before delay
+ t.eq(log.length, 2, "c) no event fired yet")
+ },
+ // wait for rest of delay and confirm event logged
+ delay / 2, function() {
+ t.eq(log.length, 3, "c) event logged");
+ t.eq(log[2].type, "measurepartial", "c) correct type");
+ t.eq(log[2].measure, 30, "c) correct measure");
+
+ // d) move 10 pixels and click
+ trigger("mousemove", 0, 40);
+ trigger("mousedown", 0, 40);
+ trigger("mouseup", 0, 40);
- log = {};
- control.measurePartial(null, geometry);
- geometry.components[1].x = 3;
- t.delay_call(0.2, function() {
+ // confirm measurepartial is not fired before delay
+ t.eq(log.length, 3, "d) no event fired yet")
+
+ // e) double click to finish
+ trigger("dblclick", 0, 40);
- t.eq(log.measure, 1, "partial measure is correct");
+ t.eq(log.length, 4, "e) event logged");
+ t.eq(log[3].type, "measure", "e) correct type");
+ t.eq(log[3].measure, 40, "e) correct measure");
+ },
+ // wait for rest of delay and confirm no measurepartial logged
+ delay, function() {
+ // confirm measurepartial is not fired after dblclick
+ t.eq(log.length, 4, "e) no additional event fired");
+
+ // change to freehand mode and confirm synchronous event dispatch
+ control.handler.freehand = true;
+ // clear log
+ log = [];
+
+ // f) establish first freehand point
+ trigger("mousedown", 0, 0);
+ t.eq(log.length, 0, "f) no event fired yet")
+
+ // g) move 10 pixels
+ trigger("mousemove", 10, 0);
- // tear down
- map.destroy
- });
- };
+ t.eq(log.length, 1, "g) event logged");
+ t.eq(log[0].type, "measurepartial", "g) correct type");
+ t.eq(log[0].measure, 10, "g) correct measure");
+
+ // h) move 10 pixels
+ trigger("mousemove", 20, 0);
+ t.eq(log.length, 2, "h) event logged");
+ t.eq(log[1].type, "measurepartial", "h) correct type");
+ t.eq(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.eq(log[2].type, "measure", "i) correct type");
+ t.eq(log[2].measure, 20, "i) correct measure");
+
+ // j) clean up
+ log = [];
+ map.destroy();
+ },
+ // wait for delay and confirm event not logged
+ delay, function() {
+ t.eq(log.length, 0, "j) no event fired after destroy");
+ }
+ );
+
+ }
+
</script>
</head>
<body>
Modified: sandbox/camptocamp/geobretagne/tests/Strategy/Fixed.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/Strategy/Fixed.html 2010-10-28 06:50:31 UTC (rev 10864)
+++ sandbox/camptocamp/geobretagne/tests/Strategy/Fixed.html 2010-11-02 17:13:19 UTC (rev 10865)
@@ -153,7 +153,7 @@
];
// call merge with a mocked up response
- strategy.merge(new OpenLayers.Projection("EPSG:900913"), {features: features});
+ strategy.merge({features: features});
// confirm that the original features were destroyed
t.eq(layer.features.length, 2, "old features destroyed");
@@ -177,7 +177,7 @@
];
// call merge again with mocked up response
- strategy.merge(new OpenLayers.Projection("EPSG:900913"), {features: features});
+ strategy.merge({features: features});
// test that feature geometries have not been transformed
t.geom_eq(layer.features[0].geometry, features[0].geometry, "[same proj] feature 0 geometry not transformed");
@@ -185,56 +185,6 @@
}
- function test_load(t) {
- t.plan(4);
-
- // set up
-
- var log;
-
- var map = new OpenLayers.Map({
- div: "map",
- projection: new OpenLayers.Projection("EPSG:900913"),
- layers: [new OpenLayers.Layer("", {isBaseLayer: true})]
- });
-
- var response = new OpenLayers.Protocol.Response();
-
- var strategy = new OpenLayers.Strategy.Fixed({
- merge: function(p, r) {
- log = {scope: this, projection: p, response: r};
- }
- });
-
- var layer = new OpenLayers.Layer.Vector("vector", {
- strategies: [strategy],
- protocol: {
- read: function(o) {
- o.callback.call(o.scope, response);
- }
- }
- });
-
- map.addLayer(layer);
-
- // test
-
- strategy.load();
-
- // verify that the callback is correctly bound
- t.ok(log !== undefined,
- "merge was called");
- t.ok(log.scope == strategy,
- "merge called with expected scope");
- t.eq(log.projection.getCode(), map.getProjectionObject().getCode(),
- "merge called the map projection as the first arg");
- t.ok(log.response == response,
- "merge called with response as the first arg");
-
- // tear down
-
- map.destroy();
- }
</script>
</head>
<body>
More information about the Commits
mailing list