templates/isochrone/index.html.twig line 1

Open in your IDE?
  1. {% extends 'base.html.twig' %}
  2. {% block title %}Hello IsochroneController!{% endblock %}
  3. {% block body %}
  4.     <style type="text/css">
  5.         #theMap {
  6.             width:100%;
  7.             height:600px;
  8.         }
  9.         form .alert {
  10.             display:none;
  11.             margin:0;
  12.         }
  13.     </style>
  14.     <script type="text/javascript" src="/ekotools/javascripts/isochrone.js"></script>
  15. <div class="row">
  16.     <div class="col-12">
  17.         <div class="card">
  18.             <div class="card-body">
  19.                 <h3>Isochrones et Isodistance</h3>
  20.                 <form action="index.html" method="get" onsubmit="return testIsochrone();">
  21.                     <div class="form-group">
  22.                         <div class="col-xs-12 row">
  23.                             <div class="col-xs-6">
  24.                                 <div class="clearfix">
  25.                                     <div class="col-xs-2"></div>
  26.                                     <div class="col-xs-5"><label><input type="radio" name="type" id="typeDuration" checked="checked"/> Temps (isochrone)</label></div>
  27.                                     <div class="col-xs-3"><input type="text" name="value" id="durationValue" value="10" size="7" class="form-control"/></div>
  28.                                     <div class="col-xs-2">en minutes</div>
  29.                                 </div>
  30.                                 <div class="clearfix">
  31.                                     <div class="col-xs-2">- ou -</div>
  32.                                     <div class="col-xs-5"><label><input type="radio" name="type"/> distance (isodistance)</label></div>
  33.                                     <div class="col-xs-3"><input type="text" name="value" id="distanceValue" value="1000" size="7" class="form-control"/></div>
  34.                                     <div class="col-xs-2">metres</div>
  35.                                 </div>
  36.                             </div>
  37.                             <div class="col-xs-6">
  38.                                 <div class="col-xs-6">
  39.                                     <input type="submit" value="Calcul du polygone" class="form-control"/>
  40.                                 </div>
  41.                                 <div class="col-xs-6">
  42.                                     <div class="alert alert-warning" id="computing">Calcul en cours...</div>
  43.                                     <div class="alert alert-danger" id="error">Erreur...</div>
  44.                                 </div>
  45.                             </div>
  46.                         </div>
  47.                         <div class="col-xs-12">
  48.                             <div class="col-xs-1">Mode</div>
  49.                             <div class="col-xs-9">
  50.                                 <label><input type="radio" name="mode" id="modeWalking" checked="checked"/> Marche</label>
  51.                                 <label><input type="radio" name="mode" id="modeBicycling"/> VĂ©lo</label>
  52.                                 <label><input type="radio" name="mode" id="modeDriving"/> Voiture</label>
  53.                                 <label><input type="radio" name="mode"/> Transport</label>
  54.                             </div>
  55.                         </div>
  56.                     </div>
  57.                 </form>
  58.             </div>
  59.         </div>
  60.         <div class="card">
  61.             <div class="card-body">
  62.             <div class="text-center alert alert-info">Cliquer sur la carte pour choisir un emplacement</div>
  63.             <div id="theMap"></div>
  64.             </div>
  65.         </div>
  66.     </div>
  67. </div>
  68.     <script type="text/javascript">
  69.         $( document ).ready(function() {
  70.             var marker = false,
  71.                 polygon = false,
  72.                 latitude = 48.858254,
  73.                 longitude = 2.294563;
  74.             isochrone.load({
  75.                 map: 'theMap',
  76.                 key: 'AIzaSyBdNRvl5qARhD6X3JaQ1En7f4ETuJDl95A', // Do change the key: it won't work on your domain anyway :-)
  77.                 callback: function (iso) {
  78.                     marker = new google.maps.Marker({position: {lat: latitude, lng: longitude}, map: iso.map.map});
  79.                     iso.map.map.setOptions({
  80.                         clickableIcons: false,
  81.                         draggableCursor: 'pointer',
  82.                         styles: [{
  83.                             featureType: "poi",
  84.                             elementType: "labels",
  85.                             stylers: [{visibility: "off"}]
  86.                         }]
  87.                     });
  88.                     iso.map.map.addListener('click', function (data) {
  89.                         latitude = data.latLng.lat();
  90.                         longitude = data.latLng.lng();
  91.                         marker.setPosition({lat: latitude, lng: longitude});
  92.                     });
  93.                 },
  94.                 debug: true
  95.             });
  96.             /* Allow to click on the map */
  97.             function testIsochrone() {
  98.                 document.getElementById('error').style.display = 'none';
  99.                 document.getElementById('computing').style.display = 'block';
  100.                 if (polygon) {
  101.                     polygon.setMap(null);
  102.                     polygon = null;
  103.                 }
  104.                 let value = parseFloat(document.getElementById(document.getElementById('typeDuration').checked ? 'durationValue' : 'distanceValue').value.replace(',', '.'));
  105.                 if (document.getElementById('typeDuration').checked) {
  106.                     value = value * 60;
  107.                 }
  108.                 isochrone.compute({
  109.                     lat: latitude,
  110.                     lng: longitude,
  111.                     cycles: 5,
  112.                     slices: 8,
  113.                     type: document.getElementById('typeDuration').checked ? 'duration' : 'distance',
  114.                     value: value,
  115.                     mode: document.getElementById('modeWalking').checked ? 'walking' : (document.getElementById('modeBicycling').checked ? 'bicycling' : (document.getElementById('modeDriving').checked ? 'driving' : 'transit')),
  116.                     callback: function (status, points) {
  117.                         document.getElementById('computing').style.display = 'none';
  118.                         if (status === 'OK') {
  119.                             polygon = new google.maps.Polygon({path: points});
  120.                             polygon.setMap(isochrone.map.map);
  121.                         } else {
  122.                             document.getElementById('error').innerHTML = status;
  123.                             document.getElementById('error').style.display = 'block';
  124.                         }
  125.                     }
  126.                 });
  127.                 return false;
  128.             }
  129.         });
  130.     </script>
  131. {% endblock %}