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.

As far as I know that openlayers can display our mouse coordinate position. However, I do not know how to display map center coordinate? Can anyone help me?

thanks for your helping guys!

share|improve this question
add comment

2 Answers

You need to build a new Control, say OpenLayers.Control.MapCenter(). You can take OpenLayers.Control.MousePosition, rename it and change the registering of the events in the activate method. Remember also to change the unregistering in the deactivate method. Then you need to include js file with the definition of the new control and add it to you map: map.addControl(new OpenLayers.Control.MapCenter())

share|improve this answer
add comment

The easiest way would be to add an event to the map object so that on moveend some div (or something else) is updated. The map center itself can easily be retrieved from the map object with getCenter. For example:

map.events.on({
        "moveend":function(){
            alert(map.getCenter().toString());
        }
    });
share|improve this answer
    
Thanks om henners, it is very helpful for me. But, that I want really is that the map center coordinate automatically appear in map as like as mouse coordinate position automatically appear in map (map.addControl(new OpenLayers.Control.MousePosition());) –  rendi Oct 11 '12 at 5:54
    
use map.getCenter() inside the moveend event. goo.gl/zUf6J –  D_Guidi Oct 11 '12 at 6:48
add comment

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.