Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove standard controls in an OpenLayers-Map?

I use OpenLayers and want to create another navigation-control in the upper-left side. I know how to add Controls, but this navigation is added at default while creating the OpenLayers-Map. So I want to remove that Control, to add an own. I know already, that the default-control is an OpenLayers.Control.PanZoom.

like image 538
Mnementh Avatar asked Aug 09 '10 15:08

Mnementh


Video Answer


2 Answers

The map object has a property called controls that is an array of OpenLayers.Control objects. If this property is not explicitly set then OpenLayers will assume that you want the default control set, including OpenLayers.Control.Navigation(), OpenLayers.Control.PanZoom(), OpenLayers.Control.ArgParser(), and OpenLayers.Control.Attribution().

To remove PanZoom or any other default control, simply set the controls property array at the time you construct the Map object. Here is a code example:

var map = new OpenLayers.Map('map', {
    controls: [
        new OpenLayers.Control.Navigation(),
        new OpenLayers.Control.ArgParser(),
        new OpenLayers.Control.Attribution()
    ]
});

Here is a live example.

Please note that by setting the controls property that you will not get any Control objects be default. Any controls you need must be added manually.

Here is a link to the source code of the Map object if you want to see how it works for yourself.

like image 56
atogle Avatar answered Oct 16 '22 18:10

atogle


I would have expected map.removeControl(OpenLayers.Control.PanZoom) to work but apparently not.

like image 25
Leif Gruenwoldt Avatar answered Oct 16 '22 19:10

Leif Gruenwoldt