[GIS] Add a label to a mouse pointer

bearinglabelingmouse positionmouse-cursoropenlayers-2

I am drawing a bearing line using a line with max vertices of 2, I have the calculations for figuring out the actual bearing from the lat lon of the original point and the mouse latlon

I want to place the label on the actual mouse before the second point is placed and the line feature is drawn.

Is this actually possible?

getMouseBearing : function(firstLatLon)
{
    this.map.addControl(new OpenLayers.Control.MousePosition());

    this.map.events.register("mousemove", map, function(e) {
        var mousePosition = this.getLonLatFromPixel(e.xy);
        var bearing = getLineData(false, mousePosition, firstLatLon);
        //Need something here to add label to mouse cursor
    });
},

Best Answer

what about

<div id="tooltip"></div>

--

 map.events.register("mousemove", map, function (e) {
    var position = map.getLonLatFromViewPortPx(e.xy);

    OpenLayers.Util.getElement("tooltip").innerHTML = "<label>Latitude: " + position.lat + "</label><br/><label>Longitude: " + position.lon + "</label>";
    $("#tooltip").css({position:"absolute", left:e.x+15,top:e.y});
});

see jsfiddle: http://jsfiddle.net/expedio/56gd9eb1/