workshop ol simple map

by Francesco Boccacci

HTML

<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/css/ol.css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<body>
    <div id="map" class="map"></div>
</body>

CSS

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
}

.map {
  height: 100%;
  width: 100%;
}

JavaScript

//const target = document.querySelector('#map');
 const map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        target: 'map', // id  dell'elemento contenitore
        //target,
        view: new ol.View({
          center: [1429066.680820, 5282715.898845], //coordinate in epsg:3857
          zoom: 4
        })
      });