Skip to content
April 17, 2012 / fastr.de

Openlayers – selectFeature where did i clicked?

in my first Post about drag and select i didn’t saw, that i have to get the coordinates when i click on a lineFeature. So, when You want to get the Openlayers.Pixel Object you have to hand over this object to the clickFeature method of the selectFeature.

Original from my first Post:


[map and layer declaration goes here]

var selectFeature = new OpenLayers.Control.SelectFeature(layer,{});

var dragFeature = new OpenLayers.Control.DragFeature(layer, {
  onStart: function(feature, pixel){
    selectFeature.clickFeature(feature);
  }
});
map.addControl(dragFeature);
dragFeature.activate();
Altered version:

[map and layer declaration goes here]

var selectFeature = new OpenLayers.Control.SelectFeature(layer,{
 clickFeature: function(feature, pixel){
   //do something and/or call the parent clickFeature function
 }
});

var dragFeature = new OpenLayers.Control.DragFeature(layer, {
  onStart: function(feature, pixel){
    selectFeature.clickFeature(feature, pixel);
  }
});
map.addControl(dragFeature);
dragFeature.activate();
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: