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 = ol.polyline( [
    new ol.LatLng(72.0, -60.0),
    new ol.LatLng(75.0, 0)
]).addTo(map);

var start_point = new ol.Geometry.Point(72.0, -60.0);
var end_point = new ol.Geometry.Point(75.0, 0);

var vector = new ol.Layer.Vector();
vector.addFeatures([new ol.Feature.Vector(new OpenLayers.Geometry.LineString([
   start_point, end_point
]))]);
map.addLayers([vector]);




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