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 source = new ol.VectorSource({wrapX: false});
var vector = new ol.VectorLayer({source: source});
      

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()
    }),
    vector
  ],
  target: 'map',
  view: new ol.View({
    center: [0, 0],
    projection: 'EPSG:4326',
    zoom: 2
  })
});


/* var points = new Array(
    new ol.Geometry.Point(72.0, -60.0),
    new ol.Geometry.Point(75.0, 0)
);
var line = new ol.Geometry.LineString(points);
map.addLayers([line]); */





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