JSFiddle - React, Tailwind, and code Playground

by Hemerson Prestes

HTML

<script src="http://openlayers.org/en/v3.15.0/build/ol.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.15.0/css/ol.css">
    <meta charset="utf-8">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.14.1/build/ol.js"></script>
    
    
<div id="map" class="map"></div>
<div id="scaleline"></div>
<select id="units">
  <option value="degrees">degrees</option>
  <option value="imperial">imperial inch</option>
  <option value="us">us inch</option>
  <option value="nautical">nautical mile</option>
  <option value="metric" selected>metric</option>
</select>

JavaScript

var scaleLineControl = new ol.control.ScaleLine({
target: document.getElementById('scaleline')
});

var map = new ol.Map({
  controls: ol.control.defaults({
    attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
      collapsible: false
    })
  }).extend([
    scaleLineControl
  ]),
  layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    })
  ],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    zoom: 2
  })
});


var unitsSelect = document.getElementById('units');
function onChange() {
  scaleLineControl.setUnits(unitsSelect.value);
}
unitsSelect.addEventListener('change', onChange);
onChange();