[OpenLayers-Commits] r10938 - in trunk/openlayers:
lib/OpenLayers/Control tests/Control
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Dec 1 14:40:17 EST 2010
Author: ahocevar
Date: 2010-12-01 11:40:17 -0800 (Wed, 01 Dec 2010)
New Revision: 10938
Modified:
trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
trunk/openlayers/tests/Control/ModifyFeature.html
Log:
give ModifyFeature control a vertexRenderIntent property. r=tschaub (closes #2955)
Modified: trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js 2010-12-01 15:26:18 UTC (rev 10937)
+++ trunk/openlayers/lib/OpenLayers/Control/ModifyFeature.js 2010-12-01 19:40:17 UTC (rev 10938)
@@ -113,6 +113,15 @@
* {Object} A symbolizer to be used for virtual vertices.
*/
virtualStyle: null,
+
+ /**
+ * APIProperty: vertexRenderIntent
+ * {String} The renderIntent to use for vertices. If no <virtualStyle> is
+ * provided, this renderIntent will also be used for virtual vertices, with
+ * a fillOpacity and strokeOpacity of 0.3. Default is null, which means
+ * that the layer's default style will be used for vertices.
+ */
+ vertexRenderIntent: null,
/**
* APIProperty: mode
@@ -193,11 +202,14 @@
* control.
*/
initialize: function(layer, options) {
+ options = options || {};
this.layer = layer;
this.vertices = [];
this.virtualVertices = [];
this.virtualStyle = OpenLayers.Util.extend({},
- this.layer.style || this.layer.styleMap.createSymbolizer());
+ this.layer.style ||
+ this.layer.styleMap.createSymbolizer(null, options.vertexRenderIntent)
+ );
this.virtualStyle.fillOpacity = 0.3;
this.virtualStyle.strokeOpacity = 0.3;
this.deleteCodes = [46, 68];
@@ -622,6 +634,7 @@
if(geometry.CLASS_NAME == "OpenLayers.Geometry.Point") {
vertex = new OpenLayers.Feature.Vector(geometry);
vertex._sketch = true;
+ vertex.renderIntent = control.vertexRenderIntent;
control.vertices.push(vertex);
} else {
var numVert = geometry.components.length;
@@ -633,6 +646,7 @@
if(component.CLASS_NAME == "OpenLayers.Geometry.Point") {
vertex = new OpenLayers.Feature.Vector(component);
vertex._sketch = true;
+ vertex.renderIntent = control.vertexRenderIntent;
control.vertices.push(vertex);
} else {
collectComponentVertices(component);
Modified: trunk/openlayers/tests/Control/ModifyFeature.html
===================================================================
--- trunk/openlayers/tests/Control/ModifyFeature.html 2010-12-01 15:26:18 UTC (rev 10937)
+++ trunk/openlayers/tests/Control/ModifyFeature.html 2010-12-01 19:40:17 UTC (rev 10938)
@@ -473,9 +473,13 @@
}
function test_onModificationStart(t) {
- t.plan(1);
+ t.plan(5);
var map = new OpenLayers.Map("map");
- var layer = new OpenLayers.Layer.Vector();
+ var layer = new OpenLayers.Layer.Vector(null, {
+ styleMap: new OpenLayers.StyleMap({
+ "vertex": new OpenLayers.Style({foo: "bar"})
+ }, {extendDefault: false})
+ });
map.addLayer(layer);
var control = new OpenLayers.Control.ModifyFeature(layer);
map.addControl(control);
@@ -483,14 +487,38 @@
// make sure onModificationStart is called on feature selection
var testFeature = new OpenLayers.Feature.Vector(
- new OpenLayers.Geometry.Point(Math.random(), Math.random())
+ OpenLayers.Geometry.fromWKT("LINESTRING(3 4,10 50,20 25)")
);
+ layer.addFeatures([testFeature]);
control.onModificationStart = function(feature) {
t.eq(feature.id, testFeature.id,
"onModificationStart called with the right feature");
};
control.selectFeature(testFeature);
+ // make sure styles are set correctly from default style
+ t.eq(control.virtualStyle, OpenLayers.Util.applyDefaults({
+ strokeOpacity: 0.3,
+ fillOpacity: 0.3
+ }, OpenLayers.Feature.Vector.style["default"]), "virtual style set correctly");
+ var vertex = layer.features[layer.features.length-1];
+ t.eq(vertex.renderIntent, null, "vertex style set correctly - uses default style");
+ control.unselectFeature(testFeature);
+
+ // make sure styles are set correctly with vertexRenderIntent
+ control = new OpenLayers.Control.ModifyFeature(layer, {vertexRenderIntent: "vertex"});
+ map.addControl(control);
+ control.activate();
+ control.selectFeature(testFeature);
+ t.eq(control.virtualStyle, {
+ strokeOpacity: 0.3,
+ fillOpacity: 0.3,
+ foo: "bar"
+ }, "virtual style set correctly");
+ var vertex = layer.features[layer.features.length-1];
+ t.eq(vertex.renderIntent, "vertex", "vertex style set correctly - uses 'vertex' renderIntent");
+ control.unselectFeature(testFeature);
+
map.destroy();
}
More information about the Commits
mailing list