Isochrones

Calculate random isochrone

Calculate isochrone from random position inside Spain.

main.js
var startPosition = new cercaliagl.LonLat(-3.686865589, 40.427757860);
var map = new cercaliagl.Map({
  target: 'map',
  center: startPosition,
  zoom: 12
});
var isoColors = ['#5F5FF3', '#A9A5EF', '#CDCCEB'];
map.whenReady(function () {
  var markerCentroid = new cercaliagl.Marker({
    position: startPosition
  });
  map.addMarker(markerCentroid);
  var isochrone = new cercaliagl.service.Isochrone({
    position: markerCentroid.getPosition(),
    weight: 'distance',
    method: 'concavehull',
    isolevels: '1000,3000,5000'
  });
  isochrone.calculate(function (data) {
    data.cercalia.isochrones.isochrone.forEach(function (element, index) {
      var feature = new cercaliagl.Feature({
        wkt: element.value,
        fillColor: isoColors[index],
        strokeColor: isoColors[index],
        outlineColor: isoColors[index]
      });
      map.addFeature(feature);
    });
  });
});
index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Isochrones</title>
    <style>
      .map {
        width: 100%;
        height: 640px;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    
    <link rel="stylesheet" type="text/css" href="//maps.cercalia.com/gl/v1.0/cercaliagl.css">
    <script src="//maps.cercalia.com/gl/v1.0/cercaliagl.js?key=YOUR_API_KEY"></script>
    <script src="main.js"></script>
  </body>
</html>