manilly
manilly

Reputation: 3

OpenLayers Click on selected Feature triggering function

I am using OpenLayers to draw point features on a map with a cluster strategy.

        strategy = new OpenLayers.Strategy.Cluster();

        clusters = new OpenLayers.Layer.Vector("Clusters", {
            strategies: [strategy],
            styleMap: new OpenLayers.StyleMap({
                "default": style,
                "select": {
                    fillColor: "#ff0000",
                    strokeColor: "#ffbbbb"
                }
            })
        });

        [.......]

        clusters.addFeatures(features);

I'm also using a SelectFeature to select the point features on my map.

        select = new OpenLayers.Control.SelectFeature(
                clusters, {
                    clickout: false,
                    toggle: false, 
                    hover: false
                }
            );

        map.addControl(select);
        select.activate();

        clusters.events.on({"featureselected": clickPoint});

When the user selects a clustered Feature a popup appears with a list of containing features to select. When he selects one of these the popup closes and the clustered feature remains selected.

Now comes the problem. I want to be able click on the clustered feature so the popup appears again. The only thing I'm able to do is to set toggle:true but then the feature gets unselected.

Is there a way to trigger an event when the user clicks on a selected Feature?

Thx in advance, illy

Upvotes: 0

Views: 8385

Answers (2)

X-HuMan
X-HuMan

Reputation: 1488

You could also unSelect your feature when the feature is selected. For me it was the shortest way to achieve for the click event for the feature. Also set the toggle flag to true to fire unselect event in case of clicks.

var pdfFeatureSelector = new OpenLayers.Control.SelectFeature(pdfLayer,{
        clickout: true,
        multiple: true,
        toggle: true,
        autoActivate: true,
        onSelect: function(){
            OpenLayers.Control.SelectFeature.prototype.unselectAll.apply(
                    pdfFeatureSelector);//unselect the feature when it is selected
        }
});

Upvotes: 0

xamamano -jorix-
xamamano -jorix-

Reputation: 401

To solve this problem I overwrite unselectAll as:

mySelectControl.unselectAll = function(options) {
    OpenLayers.Control.SelectFeature.prototype.unselectAll.apply(
                              mySelectControl, arguments);
    if (options && options.except) {
        var myReselecteFeature = options.except;
        ... your code to show the popup of myReselecteFeature ...
    }
};

You may be interested to look at this example:

http://jorix.github.com/OL-FeaturePopups/examples/feature-popups.html

It is a control that does this you do and a little more. For example keeps the selection after zooming using clusters.

NOTE: The default behavior is not what you are looking for but can be customized.

Upvotes: 1

Related Questions