[OpenLayers-Users] Problems with labels, renderIntents and some other sutff

Robert Sanson Robert.Sanson at asurequality.com
Tue Dec 3 12:18:08 PST 2013


Hi David

To avoid labelling vertices of polygons when selected, use something
like the following - define your Styles, and then add a StyleMap with a
function that only labels the polygons:

var padd_style = new OpenLayers.Style();
  padd_style.label = "${getLabelp}";
  padd_style.pointRadius = 4;
  padd_style.strokeColor = "#006666"; 
  padd_style.strokeDashstyle = "solid";
  padd_style.fillColor = "#EBFFD6";
  padd_style.fillOpacity = 0.0;
  padd_style.strokeWidth = 2;
  padd_style.fontColor = "blue";
  padd_style.fontSize =10;
  padd_style.fontFamily = "Arial";
  padd_style.fontWeight = "bold";

var delf_style = new OpenLayers.Style({
	'strokeColor': '#666666',
	'strokeOpacity': 0.3,
	'fillColor': '#cccccc',
	'fillOpacity': 0.1,
	'fontColor': '#222222'
});

var padd_stylemap = new OpenLayers.StyleMap({
    "default": new OpenLayers.Style(padd_style, {
        context: {
            getLabelp: function (feature) {
                if (feature.geometry && feature.geometry.CLASS_NAME ==
"OpenLayers.Geometry.Polygon") {
                    return feature.attributes.name;
                } else {
                    return "";
                }
            }
        }
    }),
    "delf": delf_style
  }); 

regards,

Robert

>>> "David Alda Fernandez de Lezea" <dalda at hazi.es> 3/12/2013 10:01
p.m. >>>
Hi list,
 
I'm facing a strange behaviour regarding labelling features, in this
case polygons, and the rendering intents of my style map. I have some
features loaded into an OpenLayers.Layer.Vector layer. This layer has a
style map definition:
 
var styles = new OpenLayers.StyleMap({
                "default": new OpenLayers.Style(null,{
                    rules: [
                        new OpenLayers.Rule({
                            symbolizer: {
                                "Point": {
                                    pointRadius: 5,
                                    graphicName: "circle",
                                    fillColor: "#FFA500",
                                    fillOpacity: 0.25,
                                    strokeWidth: 1,
                                    strokeOpacity: 1,
                                    strokeColor: "#FFA500"
                                },
                                "Line": {
                                    strokeWidth: 3,
                                    strokeOpacity: 1,
                                    strokeColor: "#FFA500"
                                },
                                "Polygon": {
                                    strokeWidth: 2,
                                    strokeOpacity: 1,
                                    strokeColor: "#FFA500",
                                    fillColor: "#FFA500"
                                }
                            }
                        })
                    ]
                }),
                "select": new OpenLayers.Style({
                    strokeColor: "#00ccff",
                    strokeWidth: 4,
     strokeDashstyle: "solid"
                }),
                "temporary": new OpenLayers.Style(null, {
                    rules: [
                        new OpenLayers.Rule({
                            symbolizer: {
                                "Point": {
                                    pointRadius: 5,
                                    graphicName: "square",
                                    fillColor: "white",
                                    fillOpacity: 0.25,
                                    strokeWidth: 1,
                                    strokeOpacity: 1,
                                    strokeColor: "#333333"
                                },
                                "Line": {
                                    strokeWidth: 3,
                                    strokeOpacity: 1,
                                    strokeColor: "#00ccff"
                                },
                                "Polygon": {
                                    strokeWidth: 2,
                                    strokeOpacity: 1,
                                    strokeColor: "#0000ff",
                                    fillColor: "#0000ff"
                                }
 
                            }
                        })
                    ]
                })
            });
 
I've developed a function to label the features dynamically:
 
labelFeatures: function (etiquetas){
 
 //label : "name: ${name}\n\nage: ${age}",
  var label="";
  for (var i=0;i<=etiquetas.length-1;i++){
   label += "${" + etiquetas[i] + "}-";
  }
  label = label.substring(0,label.length-1);
  
  var pila = this.map.getLayersByName("pila")[0];
  for (var i=0;i<=pila.styleMap.styles["default"].rules.length-1;i++){
   if (pila.styleMap.styles["default"].rules[i].symbolizer.Polygon){
    pila.styleMap.styles["default"].rules[i].symbolizer.Polygon.label =
label;
   
pila.styleMap.styles["default"].rules[i].symbolizer.Polygon.labelAlign =
"rt";
   
pila.styleMap.styles["default"].rules[i].symbolizer.Polygon.fontSize =
"14px";
   
pila.styleMap.styles["default"].rules[i].symbolizer.Polygon.fontWeight =
"bold";
   }
   
   if (pila.styleMap.styles["default"].rules[i].symbolizer.Line){
    pila.styleMap.styles["default"].rules[i].symbolizer.Line.label =
label;
    pila.styleMap.styles["default"].rules[i].symbolizer.Line.labelAlign
= "rt";
    pila.styleMap.styles["default"].rules[i].symbolizer.Line.fontSize =
"14px";
    pila.styleMap.styles["default"].rules[i].symbolizer.Line.fontWeight
= "bold";
   }
   
   if (pila.styleMap.styles["default"].rules[i].symbolizer.Point){
    pila.styleMap.styles["default"].rules[i].symbolizer.Point.label =
label;
   
pila.styleMap.styles["default"].rules[i].symbolizer.Point.labelAlign =
"rt";
    pila.styleMap.styles["default"].rules[i].symbolizer.Point.fontSize
= "14px";
   
pila.styleMap.styles["default"].rules[i].symbolizer.Point.fontWeight =
"bold";
   }
   
   pila.styleMap.styles["default"].defaultStyle.label = label;
  }
 
 }
 
I also have the highlight control added to the map.

Then thing is that once the features are loaded and rendered the label
appears correctly, buy whenever I hover the pointer over the feature the
correct label disappears and I get the substitution value for the label,
i.e, something like ${myLabel}. Furthermore, whenever I select the
feature I get an 'undefined' label over all the feature's vertices. And
finally another weird behaviour is that if I try to draw a new feature
with the DrawPolygon control I get the following error:

Uncaught TypeError: Cannot read property 'x' of null OpenLayers.js:614
OpenLayers.Renderer.SVG.OpenLayers.Class.drawText OpenLayers.js:614
OpenLayers.Renderer.OpenLayers.Class.drawFeature OpenLayers.js:292
OpenLayers.Layer.Vector.OpenLayers.Class.drawFeature
OpenLayers.js:1578
OpenLayers.Layer.Vector.OpenLayers.Class.addFeatures
OpenLayers.js:1565
OpenLayers.Handler.Polygon.OpenLayers.Class.createFeature
OpenLayers.js:1994
OpenLayers.Handler.Path.OpenLayers.Class.mousedown OpenLayers.js:1846
OpenLayers.Events.OpenLayers.Class.triggerEvent OpenLayers.js:559
OpenLayers.Events.OpenLayers.Class.handleBrowserEvent
OpenLayers.js:562
(anonymous function)

I'm working with OpenLayers 2.9

I don't really know what to do. Any help is much appreciated.

Thanks in advance.

Regards,

 

David Alda Fernández de Lezea

 

UNIDAD DE EMPRENDIMIENTO Y DESARROLLO RURAL

Area de Sistemas de Información Geográfica, Planificación Territorial y
Forestal

 

Granja Modelo s/n

01192 Arkaute Araba
T 627923170 F 945 003 290

dalda at hazi.es <blocked::mailto:correo_electronico at hazi.es>  |
www.hazi.es <blocked::http://www.hazi.es/> 

 



<blocked::http://www.hazi.es/>  

*********************  LEGE OHARRA   *******************   AVISO LEGAL 
 *******************   DISCLAIMER   ******************

Mezu hau pertsonala eta isilpekoa da eta baimenik gabeko erabilera
debekatua dago legalki. Jasotzailea ez bazara ezabatu mezua, bidali eta
kontserbatu gabe.

Este mensaje es personal y confidencial y su uso no autorizado está
prohibido legalmente. Si usted no es el destinatario, proceda a
borrarlo, sin reenviarlo ni conservarlo.

This message is personal and confidential, unauthorised use is legally
prohibited. If you are not the intended recipient, delete it without
resending or backing it.    

_______________________________________________
Users mailing list
Users at lists.osgeo.org 
http://lists.osgeo.org/mailman/listinfo/openlayers-users


This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.

This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com


More information about the Users mailing list