Follow these steps to start manipulating the default controls:
<!doctype html>
<html>
<head>
<title>Default controls</title>
<link rel="stylesheet" href="../assets/ol3/css/ol.css" type="text/css">
<link rel="stylesheet" href="../assets/css/samples.css" type="text/css" />
</head>
<body>
<div id="map" class="map"></div>
<script src="../assets/ol3/ol.js"></script>
<script>
</script>
</body>
</html><script> </script> add the declaration to the map:var osm_default = new ol.layer.Tile({
source: new ol.source.OSM()
});
var map = new ol.Map({
layers: [osm_default],
target: 'map',
view: new ol.View({
center: ol.proj.transform([-1.81185, 52.443141], 'EPSG:4326', 'EPSG:3857'),
zoom: 6 })
});python -m SimpleHTTPServer or node index.js (if you are using the code from the book samples) because some sources are sensitive to the URL context (or you will get a blank map).
ol.control.defaults to cancel all default controls parameters in the map constructor. See the following code to understand this:var map = new ol.Map({ layers: [osm_default],
controls: ol.control.defaults({
zoom: false,
attribution: false,
rotate: false
}),
});
Let's examine the interesting part of the code:
controls: ol.control.defaults({
zoom: false,
attribution: false,
rotate: false
})To manage default controls, we must use a parameter in the ol.control.defaults function. This first parameter is an object that contains a key referring to the default controls. You can set their value to false to disable the corresponding control.
This object also supports other keys to set options for each default controls. These keys are attributionOptions, rotateOptions, and zoomControlOptions. We mentioned them here but we will see them later when reviewing each control individually.
The following table, an excerpt from the API documentation of ol.control.defaults, summarizes these properties: