Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature attributes in featureselected #11

Closed
noog opened this issue Nov 15, 2013 · 2 comments
Closed

feature attributes in featureselected #11

noog opened this issue Nov 15, 2013 · 2 comments

Comments

@noog
Copy link

noog commented Nov 15, 2013

hello
if i use the function "featureselected" the string feature.attributes.id_test; is undefined
how can i get this value or another one from "attributes" of a feature ?

   for (var i=0; i<data.length; i++) {
            var lon = data[i].x;
            var lat = data[i].y;
            var id_poi = data[i].id_poi; // --> i have the value

            var f = new OpenLayers.Feature.Vector(
                new OpenLayers.Geometry.Point( lon, lat ).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject()),
                {
                    "id_test":data[i].id_poi // --> i add the value
                }
            );  

            features.push(f);
           }
    couche_markers.addFeatures(features); // add POI

// active control
click = new OpenLayers.Control.SelectFeature( [couche_markers], { clickout: false, toggle: false});

map.addControl(click); 
            couche_markers.events.on({ 
        "featureselected": function(e) { 
            var feature = e.feature;
            id_poi = feature.attributes.id_test;
        console.log("show id poi"+id_poi"; //--> ERROR the variable is undefined
        } 
    }); 
@acanimal
Copy link
Owner

Once clustered each cluster is a feature wich contains the set of features near to that point.
"Original" features are stored withint the feature.cluster attribute. Take a look on that.

@noog
Copy link
Author

noog commented Nov 15, 2013

ok thanks
i can access my value like this
couche_markers.events.on({
"featureselected": function(e) {
var feature = e.feature.cluster[0].data;
var cpt_cluster = e.feature.cluster.length;
if(cpt_cluster == 1)id_poi = e.feature.cluster[0].data.id_test;
}
});

now i want to have a specific external graphic when there is only one poi
so i have created this rule but i don't know how to get one of the feature.cluster value here

externalGraphic: "/drawable-hdpi/theme/${cat_poi}_poi.png",
instead of
externalGraphic: "/drawable-hdpi/theme/Cat_20_02_poi.png",

thanks :)

        // Define three rules to style the cluster features.
        var oneRule = new OpenLayers.Rule({
            filter: new OpenLayers.Filter.Comparison({
                type: OpenLayers.Filter.Comparison.LESS_THAN,
                 property: "count",
                value: 2
            }),
            symbolizer: {
                 fillOpacity: 1, 
               opacity : 1,
                externalGraphic: "/drawable-hdpi/theme/Cat_20_02_poi.png",
                graphicHeight: 50, graphicWidth: 50, graphicXOffset:-25, graphicYOffset:-25
            }
        });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants