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.

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
    
dont forget to improve your accept rate for getting good answers! –  Aragon Oct 20 '12 at 12:45
    
What have you tried so far? –  R.K. Oct 20 '12 at 16:53

2 Answers 2

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) {
       console.log(e.feature.id);
       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);
       vectorLayer_B.addFeatures(vc);
    };

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


    map.addControl(highlightCtrl);
    highlightCtrl.activate();

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

 
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.