Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a line feature in a vector layer "A", while i mouse over on that line. A point should be added to vector layer "B" with current mouse position. OR how can get lat lon of mouse position while mouse over on that line?

Thanks in advance... :)

share|improve this question
up vote 1 down vote accepted

this code can help you solving your problem.

     var vectorLayer_B = new OpenLayers.Layer.Vector("Point Layer");
     var vectorLayer_A = new OpenLayers.Layer.Vector("Line Layer");

     var make_hover= function(e) {
       var coords = OpenLayers.Util.getElement("OpenLayers.Control.MousePosition").innerHTML;
       var xy = coords.split(',');
       var po = new OpenLayers.Geometry.Point(xy[0], xy[1]);
       var vc = new OpenLayers.Feature.Vector(po);

    var highlightCtrl = new OpenLayers.Control.SelectFeature(vectorLayer_A, {
       hover: true,
       highlightOnly: true,               
       eventListeners: {
            beforefeaturehighlighted: another_Function,
            featurehighlighted: make_hover,
            featureunhighlighted: another_Function


i hope it helps you...

share|improve this answer

If you want to add point to vector layer use OpenLayers.Controls.DrawFeatureExample. If you want to draw without map clicking try use OpenLayers.Events.getMousePosition can't say you more never use this.

If you want get mouse position use OpenLayers.Control.MousePosition.

share|improve this answer

Your Answer


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.