Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Im trying to perform routing with openlayers, geoserver and mysql. In order to get the start and end points, I need to be able to get a feature of the node layer (which has point features) that lies closest to an arbitrary point I click on the map. Does openlayers provide any functionality for this. If not, kindly suggest any alternative methods for achieving this. Thanks in advance.

Regards

share|improve this question
    
What routing engine are you using? Routing data is in mySql? –  user1702401 May 22 '13 at 8:09
    
I haven't made use of any routing engine. MySql does not provide any support for routing unlike pgsql. The algorithm was developed and implemented on the server side in java and the result was visualized with openlayers. –  Nik May 22 '13 at 9:48

2 Answers 2

up vote 4 down vote accepted

With a bit of comparison you can:

  1. detect the point clicked
  2. find the feature closest to this point
  3. use the selectFeatureControl to programatically select this feature

see: http://jsfiddle.net/XfEmn/

(note, I use underscore.js _.min function, you could of course do this with a foor loop etc, the clue is to loop the features and get the one with the shortest distanceTo the clicked point)

share|improve this answer
    
Thanks a lot. This was exactly what I had been looking for. Thanks again for providing the perfect example. Greetings. –  Nik May 22 '13 at 9:38
    
Glad to be able to help. Perhaps you could accept my answer then? –  atlefren May 22 '13 at 11:52
    
@atlefren +1 nice use of jsfiddle (interactive code) and solves rashad question clearly. –  Mapperz May 22 '13 at 13:35

Yes, OpenLayers has this functionality. Its called SelectFeature Control. see docs here.

you should check how the following examples work(uses: OpenLayers.Control.SelectFeature).

  1. OpenLayers Select and Highlight Feature Example
  2. OpenLayers Select Feature Example

You can get full list of examples here and apply keywords filter for select or higlight

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.