In order to learn better, let's try another example:
Set the center and zoom of the map at loading to different values from the usual one. You can get values reusing the view with
map.getView().getZoom()
andmap.getView().getCenter()
.Create a control named
zoomToExtentControl
:var zoomToExtentControl = new ol.control.ZoomToExtent({ extent: [-11243808.051695308, 4406397.202710291, -4561377.290892059, 6852382.107835932] });
Reuse it with the code that follows, after your
map
instantiation:addControl(zoomToExtentControl);
Find the control within the controls attached to the map:
var controls = map.getControls(); var attributionControl; controls.forEach(function (el){ if (el instanceof ol.control.Attribution) { attributionControl = el; } })
Remove the
ol.control.Attribution
control using the reference you retrieve and supposing map reference theol.Map
instance.map.removeControl(attributionControl...