[OpenLayers-Commits] r11840 - in sandbox/cmoullet/openlayers: .
build examples lib/OpenLayers/Feature lib/OpenLayers/Handler
lib/OpenLayers/Renderer tests/Control tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Mar 31 08:31:16 EDT 2011
Author: cmoullet
Date: 2011-03-31 05:31:16 -0700 (Thu, 31 Mar 2011)
New Revision: 11840
Modified:
sandbox/cmoullet/openlayers/
sandbox/cmoullet/openlayers/build/mobile.cfg
sandbox/cmoullet/openlayers/examples/mobile-drawing.html
sandbox/cmoullet/openlayers/examples/mobile-drawing.js
sandbox/cmoullet/openlayers/examples/vector-features-with-text.html
sandbox/cmoullet/openlayers/lib/OpenLayers/Feature/Vector.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/Canvas.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG.js
sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG2.js
sandbox/cmoullet/openlayers/tests/Control/Measure.html
sandbox/cmoullet/openlayers/tests/Handler/Path.html
Log:
Merge with trunk
Property changes on: sandbox/cmoullet/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
- /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11831
+ /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11839
Modified: sandbox/cmoullet/openlayers/build/mobile.cfg
===================================================================
--- sandbox/cmoullet/openlayers/build/mobile.cfg 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/build/mobile.cfg 2011-03-31 12:31:16 UTC (rev 11840)
@@ -15,6 +15,7 @@
OpenLayers/Control/Attribution.js
OpenLayers/Control/SelectFeature.js
OpenLayers/Control/DrawFeature.js
+OpenLayers/Control/ModifyFeature.js
OpenLayers/Control/Panel.js
OpenLayers/Handler/Point.js
OpenLayers/Handler/Path.js
Modified: sandbox/cmoullet/openlayers/examples/mobile-drawing.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-drawing.html 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/examples/mobile-drawing.html 2011-03-31 12:31:16 UTC (rev 11840)
@@ -55,6 +55,12 @@
div.olControlZoomPanel .olControlZoomToMaxExtentItemInactive {
display: none;
}
+ .olControlEditingToolbar .olControlModifyFeatureItemInactive {
+ background-position: -1px -1px;
+ }
+ .olControlEditingToolbar .olControlModifyFeatureItemActive {
+ background-position: -1px -24px;
+ }
#title, #tags, #shortdesc {
display: none;
}
Modified: sandbox/cmoullet/openlayers/examples/mobile-drawing.js
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-drawing.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/examples/mobile-drawing.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -20,6 +20,10 @@
new OpenLayers.Control({
displayClass: 'olControlNavigation'
}),
+ new OpenLayers.Control.ModifyFeature(vector, {
+ vertexRenderIntent: 'temporary',
+ displayClass: 'olControlModifyFeature'
+ }),
new OpenLayers.Control.DrawFeature(vector, OpenLayers.Handler.Point, {
displayClass: 'olControlDrawFeaturePoint'
}),
Modified: sandbox/cmoullet/openlayers/examples/vector-features-with-text.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/vector-features-with-text.html 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/examples/vector-features-with-text.html 2011-03-31 12:31:16 UTC (rev 11840)
@@ -29,7 +29,8 @@
fillOpacity: 0.5,
pointRadius: 6,
pointerEvents: "visiblePainted",
- label : "name: ${name}, age: ${age}",
+ // label with \n linebreaks
+ label : "name: ${name}\n\nage: ${age}",
fontColor: "${favColor}",
fontSize: "12px",
@@ -113,7 +114,7 @@
map.addLayer(vectorLayer);
vectorLayer.drawFeature(multiFeature);
- map.setCenter(new OpenLayers.LonLat(point.x, point.y), 3);
+ map.setCenter(new OpenLayers.LonLat(-109.370078125, 43.39484375), 4);
vectorLayer.addFeatures([pointFeature, polygonFeature, multiFeature, labelOffsetFeature, nullFeature ]);
}
</script>
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Feature/Vector.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Feature/Vector.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Feature/Vector.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -365,7 +365,7 @@
* graphicZIndex - {Number} The integer z-index value to use in rendering.
* graphicName - {String} Named graphic to use when rendering points. Supported values include "circle" (default),
* "square", "star", "x", "cross", "triangle".
- * graphicTitle - {String} Tooltip for an external graphic. Only supported in Firefox and Internet Explorer.
+ * graphicTitle - {String} Tooltip for an external graphic.
* backgroundGraphic - {String} Url to a graphic to be used as the background under an externalGraphic.
* backgroundGraphicZIndex - {Number} The integer z-index value to use in rendering the background graphic.
* backgroundXOffset - {Number} The x offset (in pixels) for the background graphic.
@@ -377,10 +377,9 @@
* labelAlign - {String} Label alignment. This specifies the insertion point relative to the text. It is a string
* composed of two characters. The first character is for the horizontal alignment, the second for the vertical
* alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for vertical
- * alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb". The canvas renderer does not
- * support vertical alignment, it will always use "b".
- * labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label.
- * labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label.
+ * alignment: "t"=top, "m"=middle, "b"=bottom. Example values: "lt", "cm", "rb".
+ * labelXOffset - {Number} Pixel offset along the positive x axis for displacing the label. Not supported by the canvas renderer.
+ * labelYOffset - {Number} Pixel offset along the positive y axis for displacing the label. Not supported by the canvas renderer.
* labelSelect - {Boolean} If set to true, labels will be selectable using SelectFeature or similar controls.
* Default is false.
* fontColor - {String} The font color for the label, to be provided like CSS.
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Path.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -157,6 +157,7 @@
this.line.geometry.addComponent(
this.point.geometry, this.line.geometry.components.length
);
+ this.layer.addFeatures([this.point]);
this.callback("point", [this.point.geometry, this.getGeometry()]);
this.callback("modify", [this.point.geometry, this.getSketch()]);
this.drawFeature();
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/Canvas.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/Canvas.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/Canvas.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -9,7 +9,7 @@
/**
* Class: OpenLayers.Renderer.Canvas
- * A renderer based on the 2D 'canvas' drawing element.element
+ * A renderer based on the 2D 'canvas' drawing element.
*
* Inherits:
* - <OpenLayers.Renderer>
@@ -329,42 +329,61 @@
labelAlign: "cm"
}, style);
var pt = this.getLocalXY(location);
-
+
this.setCanvasStyle("reset");
this.canvas.fillStyle = style.fontColor;
this.canvas.globalAlpha = style.fontOpacity || 1.0;
var fontStyle = [style.fontStyle ? style.fontStyle : "normal",
"normal", // "font-variant" not supported
style.fontWeight ? style.fontWeight : "normal",
- style.fontSize ? style.fontSize : "10px",
+ style.fontSize ? style.fontSize : "1em",
style.fontFamily ? style.fontFamily : "sans-serif"].join(" ");
+ var labelRows = style.label.split('\n');
+ var numRows = labelRows.length;
if (this.canvas.fillText) {
// HTML5
- var labelAlign =
+ this.canvas.font = fontStyle;
+ this.canvas.textAlign =
OpenLayers.Renderer.Canvas.LABEL_ALIGN[style.labelAlign[0]] ||
"center";
- this.canvas.font = fontStyle;
- this.canvas.textAlign = labelAlign;
- this.canvas.fillText(style.label, pt[0], pt[1]);
+ this.canvas.textBaseline =
+ OpenLayers.Renderer.Canvas.LABEL_ALIGN[style.labelAlign[1]] ||
+ "middle";
+ var vfactor =
+ OpenLayers.Renderer.Canvas.LABEL_FACTOR[style.labelAlign[1]];
+ if (vfactor == null) {
+ vfactor = -.5;
+ }
+ var lineHeight =
+ this.canvas.measureText('Mg').height ||
+ this.canvas.measureText('xx').width;
+ pt[1] += lineHeight*vfactor*(numRows-1);
+ for (var i = 0; i < numRows; i++) {
+ this.canvas.fillText(labelRows[i], pt[0], pt[1] + (lineHeight*i));
+ }
} else if (this.canvas.mozDrawText) {
// Mozilla pre-Gecko1.9.1 (<FF3.1)
this.canvas.mozTextStyle = fontStyle;
// No built-in text alignment, so we measure and adjust the position
- var len = this.canvas.mozMeasureText(style.label);
- switch(style.labelAlign[0]) {
- case "l":
- break;
- case "r":
- pt[0] -= len;
- break;
- case "c":
- default:
- pt[0] -= len / 2;
+ var hfactor =
+ OpenLayers.Renderer.Canvas.LABEL_FACTOR[style.labelAlign[0]];
+ if (hfactor == null) {
+ hfactor = -.5;
}
- this.canvas.translate(pt[0], pt[1]);
-
- this.canvas.mozDrawText(style.label);
- this.canvas.translate(-1*pt[0], -1*pt[1]);
+ var vfactor =
+ OpenLayers.Renderer.Canvas.LABEL_FACTOR[style.labelAlign[1]];
+ if (vfactor == null) {
+ vfactor = -.5;
+ }
+ var lineHeight = this.canvas.mozMeasureText('xx');
+ pt[1] += lineHeight*(1 + (vfactor*numRows));
+ for (var i = 0; i < numRows; i++) {
+ var x = pt[0] + (hfactor*this.canvas.mozMeasureText(labelRows[i]));
+ var y = pt[1] + (i*lineHeight);
+ this.canvas.translate(x, y);
+ this.canvas.mozDrawText(labelRows[i]);
+ this.canvas.translate(-x, -y);
+ }
}
this.setCanvasStyle("reset");
},
@@ -478,5 +497,18 @@
*/
OpenLayers.Renderer.Canvas.LABEL_ALIGN = {
"l": "left",
- "r": "right"
+ "r": "right",
+ "t": "top",
+ "b": "bottom"
};
+
+/**
+ * Constant: OpenLayers.Renderer.Canvas.LABEL_FACTOR
+ * {Object}
+ */
+OpenLayers.Renderer.Canvas.LABEL_FACTOR = {
+ "l": 0,
+ "r": -1,
+ "t": 0,
+ "b": -1
+};
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -679,24 +679,23 @@
/**
* Method: drawText
* This method is only called by the renderer itself.
- *
- * Parameters:
+ *
+ * Parameters:
* featureId - {String}
* style -
* location - {<OpenLayers.Geometry.Point>}
*/
drawText: function(featureId, style, location) {
var resolution = this.getResolution();
-
+
var x = (location.x / resolution + this.left);
var y = (location.y / resolution - this.top);
-
+
var label = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX, "text");
- var tspan = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan", "tspan");
label.setAttributeNS(null, "x", x);
label.setAttributeNS(null, "y", -y);
-
+
if (style.fontColor) {
label.setAttributeNS(null, "fill", style.fontColor);
}
@@ -715,12 +714,9 @@
if (style.fontStyle) {
label.setAttributeNS(null, "font-style", style.fontStyle);
}
- if(style.labelSelect === true) {
+ if (style.labelSelect === true) {
label.setAttributeNS(null, "pointer-events", "visible");
label._featureId = featureId;
- tspan._featureId = featureId;
- tspan._geometry = location;
- tspan._geometryClass = location.CLASS_NAME;
} else {
label.setAttributeNS(null, "pointer-events", "none");
}
@@ -731,17 +727,43 @@
if (OpenLayers.IS_GECKO === true) {
label.setAttributeNS(null, "dominant-baseline",
OpenLayers.Renderer.SVG.LABEL_ALIGN[align[1]] || "central");
- } else {
- tspan.setAttributeNS(null, "baseline-shift",
- OpenLayers.Renderer.SVG.LABEL_VSHIFT[align[1]] || "-35%");
}
- tspan.textContent = style.label;
-
- if(!label.parentNode) {
- label.appendChild(tspan);
+ var labelRows = style.label.split('\n');
+ var numRows = labelRows.length;
+ while (label.childNodes.length > numRows) {
+ label.removeChild(label.lastChild);
+ }
+ for (var i = 0; i < numRows; i++) {
+ var tspan = this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan_" + i, "tspan");
+ if (style.labelSelect === true) {
+ tspan._featureId = featureId;
+ tspan._geometry = location;
+ tspan._geometryClass = location.CLASS_NAME;
+ }
+ if (OpenLayers.IS_GECKO === false) {
+ tspan.setAttributeNS(null, "baseline-shift",
+ OpenLayers.Renderer.SVG.LABEL_VSHIFT[align[1]] || "-35%");
+ }
+ tspan.setAttribute("x", x);
+ if (i == 0) {
+ var vfactor = OpenLayers.Renderer.SVG.LABEL_VFACTOR[align[1]];
+ if (vfactor == null) {
+ vfactor = -.5;
+ }
+ tspan.setAttribute("dy", (vfactor*(numRows-1)) + "em");
+ } else {
+ tspan.setAttribute("dy", "1em");
+ }
+ tspan.textContent = (labelRows[i] === '') ? ' ' : labelRows[i];
+ if (!tspan.parentNode) {
+ label.appendChild(tspan);
+ }
+ }
+
+ if (!label.parentNode) {
this.textRoot.appendChild(label);
- }
+ }
},
/**
@@ -989,6 +1011,15 @@
};
/**
+ * Constant: OpenLayers.Renderer.SVG.LABEL_VFACTOR
+ * {Object}
+ */
+OpenLayers.Renderer.SVG.LABEL_VFACTOR = {
+ "t": 0,
+ "b": -1
+};
+
+/**
* Function: OpenLayers.Renderer.SVG.preventDefault
* Used to prevent default events (especially opening images in a new tab on
* ctrl-click) from being executed for externalGraphic symbols
Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG2.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG2.js 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Renderer/SVG2.js 2011-03-31 12:31:16 UTC (rev 11840)
@@ -570,8 +570,8 @@
* Method: drawText
* Function for drawing text labels.
* This method is only called by the renderer itself.
- *
- * Parameters:
+ *
+ * Parameters:
* featureId - {String|DOMElement}
* style - {Object}
* location - {<OpenLayers.Geometry.Point>}, will be modified inline
@@ -583,14 +583,12 @@
var g = OpenLayers.Renderer.NG.prototype.drawText.apply(this, arguments);
var text = g.firstChild ||
this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_text", "text");
- var tspan = text.firstChild ||
- this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan", "tspan");
var res = this.getResolution();
text.setAttributeNS(null, "x", location.x / res);
text.setAttributeNS(null, "y", - location.y / res);
g.setAttributeNS(null, "transform", "scale(" + res + ")");
-
+
if (style.fontColor) {
text.setAttributeNS(null, "fill", style.fontColor);
}
@@ -609,10 +607,9 @@
if (style.fontStyle) {
text.setAttributeNS(null, "font-style", style.fontStyle);
}
- if(style.labelSelect === true) {
+ if (style.labelSelect === true) {
text.setAttributeNS(null, "pointer-events", "visible");
text._featureId = featureId;
- tspan._featureId = featureId;
} else {
text.setAttributeNS(null, "pointer-events", "none");
}
@@ -623,18 +620,43 @@
if (OpenLayers.IS_GECKO === true) {
text.setAttributeNS(null, "dominant-baseline",
OpenLayers.Renderer.SVG2.LABEL_ALIGN[align[1]] || "central");
- } else {
- tspan.setAttributeNS(null, "baseline-shift",
- OpenLayers.Renderer.SVG2.LABEL_VSHIFT[align[1]] || "-35%");
}
- tspan.textContent = style.label;
-
- if(!text.parentNode) {
- text.appendChild(tspan);
+ var labelRows = style.label.split('\n');
+ var numRows = labelRows.length;
+ while (text.childNodes.length > numRows) {
+ text.removeChild(text.lastChild);
+ }
+ for (var i = 0; i < numRows; i++) {
+ var tspan = text.childNodes[i] ||
+ this.nodeFactory(featureId + this.LABEL_ID_SUFFIX + "_tspan_" + i, "tspan");
+ if (style.labelSelect === true) {
+ tspan._featureId = featureId;
+ }
+ if (OpenLayers.IS_GECKO === false) {
+ tspan.setAttributeNS(null, "baseline-shift",
+ OpenLayers.Renderer.SVG2.LABEL_VSHIFT[align[1]] || "-35%");
+ }
+ tspan.setAttribute("x", location.x / res);
+ if (i == 0) {
+ var vfactor = OpenLayers.Renderer.SVG2.LABEL_VFACTOR[align[1]];
+ if (vfactor == null) {
+ vfactor = -.5;
+ }
+ tspan.setAttribute("dy", (vfactor*(numRows-1)) + "em");
+ } else {
+ tspan.setAttribute("dy", "1em");
+ }
+ tspan.textContent = (labelRows[i] === '') ? ' ' : labelRows[i];
+ if (!tspan.parentNode) {
+ text.appendChild(tspan);
+ }
+ }
+
+ if (!text.parentNode) {
g.appendChild(text);
}
-
+
return g;
},
@@ -786,6 +808,15 @@
"b": "0"
};
+/**
+ * Constant: OpenLayers.Renderer.SVG2.LABEL_VFACTOR
+ * {Object}
+ */
+OpenLayers.Renderer.SVG2.LABEL_VFACTOR = {
+ "t": 0,
+ "b": -1
+};
+
/**
* Function: OpenLayers.Renderer.SVG2.preventDefault
* Used to prevent default events (especially opening images in a new tab on
Modified: sandbox/cmoullet/openlayers/tests/Control/Measure.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Control/Measure.html 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/tests/Control/Measure.html 2011-03-31 12:31:16 UTC (rev 11840)
@@ -19,7 +19,6 @@
}
- // test for <http://trac.openlayers.org/ticket/2691>
function test_cancel(t) {
t.plan(4);
@@ -37,7 +36,7 @@
map.addControl(control);
control.activate();
-
+
try {
control.cancel();
t.ok(true, "calling cancel before drawing works");
@@ -52,24 +51,29 @@
xy: new OpenLayers.Pixel(x, y)
})
};
+
+ // keep a reference to the line being drawn
+ var line = control.handler.line;
+
trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
trigger("mouseup", 0, 0);
trigger("mousemove", 10, 10);
trigger("mousedown", 10, 10);
trigger("mouseup", 10, 10);
+ trigger("dblclick", 10, 10);
+
+ // the geometry is finalized, we first confirm that it is persisted
+ t.ok(line.layer === control.handler.layer, "feature persists");
- // confirm that the sketch persists
- t.eq(control.handler.layer.features.length, 1, "feature persists");
- // cancel and see that sketch is gone (do not forget that
- // cancel will create the new feature)
+ // cancel and see that sketch is gone
control.cancel();
- t.eq(control.handler.layer.features.length, 2, "feature is gone after cancel");
-
+ t.eq(line.layer, null, "feature is gone after cancel");
+
map.destroy();
-
}
+ // test for <http://trac.openlayers.org/ticket/2691>
function test_partial(t) {
t.plan(28);
Modified: sandbox/cmoullet/openlayers/tests/Handler/Path.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Path.html 2011-03-31 12:26:56 UTC (rev 11839)
+++ sandbox/cmoullet/openlayers/tests/Handler/Path.html 2011-03-31 12:31:16 UTC (rev 11840)
@@ -105,7 +105,7 @@
}
function test_bounds(t) {
- t.plan(2);
+ t.plan(5);
var geometry;
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
@@ -115,16 +115,22 @@
var handler = new OpenLayers.Handler.Path(control, {},
{stopDown: true, stopUp: true});
var activated = handler.activate();
+ t.eq(handler.layer.features.length, 2,
+ "There are two features in the layer after activation.");
// click on (150, 75)
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
+ t.eq(handler.layer.features.length, 2,
+ "There are two features in the layer after first click.");
// click on (175, 100)
evt = {xy: new OpenLayers.Pixel(175, 100), which: 1};
handler.mousemove(evt);
handler.mousedown(evt);
handler.mouseup(evt);
+ t.eq(handler.layer.features.length, 2,
+ "There are two features in the layer after second click.");
t.ok(handler.line.geometry.getBounds().equals(
new OpenLayers.Bounds(0,-35.15625,35.15625,0)),
"Correct bounds");
More information about the Commits
mailing list