leaflet - projections

by Leo

HTML

<link rel="stylesheet" href="http://openlayers.org/en/v3.14.2/css/ol.css">
<script src="http://openlayers.org/en/v3.11.2/build/ol.js"></script>
<div id="map" class="map"></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

/*

Running OpenLayers v3.11.2

Using EPSG:4326.

Pan north and south to see the scale line width change.

*/


var scaleLineControl = new ol.control.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],
    projection: 'EPSG:4326',
    zoom: 2
  })
});


var polyline = L.polyline( [
    new L.LatLng(72.0, -60.0),
    new L.LatLng(75.0, 0)
]).addTo(map);


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