Hello,

I am not quite sure if I understood you right. You want to access attributes of a clicked line segment? If this is your problem this code snippet should help you:


            // your style code is skipped here
            // ...
            //

            // here I build some example features with attributes
var g1 = new OpenLayers.Geometry.LineString([new OpenLayers.Geometry.Point(0, 0), new OpenLayers.Geometry.Point(10, 10)]); var g2 = new OpenLayers.Geometry.LineString([new OpenLayers.Geometry.Point(10, 10), new OpenLayers.Geometry.Point(25, 30)]); var f1 = new OpenLayers.Feature.Vector(g1, {firstAttrribute: 'firstValue', secondAttribute: 'secondValue'}); var f2 = new OpenLayers.Feature.Vector(g2, {firstAttrribute: 123, secondAttribute: 456});

            // from here on this is your corrected code
            features = [f1, f2];
            result_linea.addFeatures(features);


var options = new OpenLayers.Control.SelectFeature(result_linea, {
                hover: false,
                highlightOnly: true,
                clickout: true,
                onSelect: function(feature){
                    console.log(feature);
                    for (var key in feature.attributes) {
// access the key and value of the clicked line's attributes
                        alert(key+ ': ' + feature.attributes[key]);
                    }

                },
                selectStyle: linea_style2
            });
            map.addLayers([result_linea]);
            map.addControl(options);

            options.activate();
            map.zoomToMaxExtent();

Best regards,
Chris


Am 13.01.2011 20:15, schrieb Valeria Muñoz:
HI!!

i need assign data to a segmet (painted with vector class), so when i click on it return to me the assigned data .... can you help me please?

this is my code.

var linea_style = OpenLayers.Util.extend({},
  OpenLayers.Feature.Vector.style['default']);
  linea_style.strokeWidth = 6;
  linea_style.strokeColor = "#ff0000";
  linea_style.strokeOpacity = 0.5;

  var linea_style20 = OpenLayers.Util.extend({},
    OpenLayers.Feature.Vector.style['default']);
    linea_style.strokeWidth = 7;
    linea_style.strokeColor = "blue";
    linea_style.strokeOpacity = 0.5;

  result_linea = new OpenLayers.Layer.Vector(
         "Routing results",
         {style: linea_style});
         map.addLayer(result_linea);

features=[a lot of segment];
result_linea.addFeatures(features);
    var options= new OpenLayers.Control.SelectFeature(result_linea, {
                hover: false,
                highlightOnly: true,
                clickout:true,
                onSelect: function(feature) {
                    //alert(feature);
                    for (var us in feature ){
//campo va tomando los nombres de las propiedades
                                       alert( feature[us] );
                                    }

                },
                selectStyle: linea_style2
            });
    map.addControl(options);

            options.activate();

that part I can assign the data?

RG


_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to