(Closes #2148) enable vector features to be selectable from their text node. r=ahocevar

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9671 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Paul Spencer
2009-09-17 12:05:38 +00:00
parent 21b680868f
commit 3fcda4df56
4 changed files with 29 additions and 2 deletions
+11 -1
View File
@@ -25,7 +25,8 @@
new OpenLayers.Rule({ new OpenLayers.Rule({
symbolizer: { symbolizer: {
graphic: false, graphic: false,
label: "Label for invisible point" label: "Label for invisible point",
labelSelect: true
}, },
filter: new OpenLayers.Filter.Comparison({ filter: new OpenLayers.Filter.Comparison({
type: "==", type: "==",
@@ -105,6 +106,13 @@
vectorLayer.drawFeature(multiFeature); vectorLayer.drawFeature(multiFeature);
map.setCenter(new OpenLayers.LonLat(point.x, point.y), 4); map.setCenter(new OpenLayers.LonLat(point.x, point.y), 4);
vectorLayer.addFeatures([pointFeature, polygonFeature, multiFeature]); vectorLayer.addFeatures([pointFeature, polygonFeature, multiFeature]);
var select = new OpenLayers.Control.SelectFeature(vectorLayer, {
selectStyle: OpenLayers.Util.extend(
{fill: true, stroke: true},
OpenLayers.Feature.Vector.style["select"])
});
map.addControl(select);
select.activate();
} }
</script> </script>
</head> </head>
@@ -117,6 +125,8 @@
<div id="map" class="smallmap"></div> <div id="map" class="smallmap"></div>
<div id="docs"> <div id="docs">
This example shows how to use symbolizers with defaults for stroke, fill, and graphic. This example shows how to use symbolizers with defaults for stroke, fill, and graphic.
This also allows to create labels for a feature without the feature rendered. Click on
the label in the middle to see selection of features with labelSelect set to true.
</div> </div>
</body> </body>
</html> </html>
+2
View File
@@ -349,6 +349,8 @@ OpenLayers.Feature.Vector = OpenLayers.Class(OpenLayers.Feature, {
* alignment. Valid values for horizontal alignment: "l"=left, "c"=center, "r"=right. Valid values for 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 * 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". * support vertical alignment, it will always use "b".
* 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. * fontColor - {String} The font color for the label, to be provided like CSS.
* fontFamily - {String} The font family for the label, to be provided like in CSS. * fontFamily - {String} The font family for the label, to be provided like in CSS.
* fontSize - {String} The font size for the label, to be provided like in CSS. * fontSize - {String} The font size for the label, to be provided like in CSS.
+9 -1
View File
@@ -673,7 +673,6 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
label.setAttributeNS(null, "x", x); label.setAttributeNS(null, "x", x);
label.setAttributeNS(null, "y", -y); label.setAttributeNS(null, "y", -y);
label.setAttributeNS(null, "pointer-events", "none");
if (style.fontColor) { if (style.fontColor) {
label.setAttributeNS(null, "fill", style.fontColor); label.setAttributeNS(null, "fill", style.fontColor);
@@ -687,6 +686,15 @@ OpenLayers.Renderer.SVG = OpenLayers.Class(OpenLayers.Renderer.Elements, {
if (style.fontWeight) { if (style.fontWeight) {
label.setAttributeNS(null, "font-weight", style.fontWeight); label.setAttributeNS(null, "font-weight", style.fontWeight);
} }
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");
}
var align = style.labelAlign || "cm"; var align = style.labelAlign || "cm";
label.setAttributeNS(null, "text-anchor", label.setAttributeNS(null, "text-anchor",
OpenLayers.Renderer.SVG.LABEL_ALIGN[align[0]] || "middle"); OpenLayers.Renderer.SVG.LABEL_ALIGN[align[0]] || "middle");
+7
View File
@@ -818,6 +818,12 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
if (style.fontWeight) { if (style.fontWeight) {
textbox.style.fontWeight = style.fontWeight; textbox.style.fontWeight = style.fontWeight;
} }
if(style.labelSelect === true) {
label._featureId = featureId;
textbox._featureId = featureId;
textbox._geometry = location;
textbox._geometryClass = location.CLASS_NAME;
}
textbox.style.whiteSpace = "nowrap"; textbox.style.whiteSpace = "nowrap";
// fun with IE: IE7 in standards compliant mode does not display any // fun with IE: IE7 in standards compliant mode does not display any
// text with a left inset of 0. So we set this to 1px and subtract one // text with a left inset of 0. So we set this to 1px and subtract one
@@ -836,6 +842,7 @@ OpenLayers.Renderer.VML = OpenLayers.Class(OpenLayers.Renderer.Elements, {
(OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(1,1)]); (OpenLayers.Renderer.VML.LABEL_SHIFT[align.substr(1,1)]);
label.style.left = parseInt(label.style.left)-xshift-1+"px"; label.style.left = parseInt(label.style.left)-xshift-1+"px";
label.style.top = parseInt(label.style.top)+yshift+"px"; label.style.top = parseInt(label.style.top)+yshift+"px";
}, },
/** /**