map.tpl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {% extends 'layout/layout_1_col.tpl'|get_template %}
  2. {% block content %}
  3. <div id="map" style="width:100%; height:600px"></div>
  4. <script>
  5. function start()
  6. {
  7. var options = {
  8. center: new google.maps.LatLng(45.526, 6.255), // "Europe center"
  9. zoom: 5,
  10. mapTypeId: google.maps.MapTypeId.ROADMAP
  11. };
  12. var map = new google.maps.Map(document.getElementById("map"), options);
  13. var oms = new OverlappingMarkerSpiderfier(map);
  14. var cities = '{{ places | escape('js') }}';
  15. cities = JSON.parse(cities);
  16. var imageCity = {
  17. url: '{{ image_city }}'
  18. }
  19. var stageCity = {
  20. url:'{{ image_stage }}'
  21. }
  22. // Add markers
  23. var markers = [];
  24. if (cities.length) {
  25. for (var i = 0; i < cities.length; i++) {
  26. // Add ville
  27. if ('ville_lat' in cities[i]) {
  28. var markerOptions = {
  29. position: new google.maps.LatLng(cities[i]['ville_lat'], cities[i]['ville_long']),
  30. title: cities[i]['complete_name'],
  31. city: cities[i],
  32. icon: imageCity,
  33. };
  34. var marker = new google.maps.Marker(markerOptions);
  35. markers.push(marker);
  36. oms.addMarker(marker);
  37. }
  38. // Add stage
  39. if ('stage_lat' in cities[i]) {
  40. var markerOptions = {
  41. position: new google.maps.LatLng(cities[i]['stage_lat'], cities[i]['stage_long']),
  42. title: cities[i]['complete_name'],
  43. city: cities[i],
  44. icon: stageCity,
  45. };
  46. var marker = new google.maps.Marker(markerOptions);
  47. markers.push(marker);
  48. oms.addMarker(marker);
  49. }
  50. }
  51. // Enable cluster
  52. var markerClusterer = new MarkerClusterer(map, markers, {
  53. maxZoom: 9, // maxZoom set when clustering will stop
  54. imagePath: 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m'
  55. });
  56. // Auto-boxing
  57. if (markers.length) {
  58. var bounds = new google.maps.LatLngBounds();
  59. for (var i = 0; i < markers.length; ++i) {
  60. bounds.extend(markers[i].position);
  61. }
  62. // Disable re center of map to another location based in other points in the map
  63. //map.fitBounds(bounds);
  64. }
  65. // window when clicking
  66. var infoWindow = new google.maps.InfoWindow();
  67. oms.addListener('click', function (marker, event) {
  68. infoWindow.setContent('<a href="{{ url }}?u=' + marker.city['id'] + '">' + marker.city['complete_name'] + '</a>');
  69. infoWindow.open(map, marker);
  70. });
  71. google.maps.event.addListener(markerClusterer, 'clusterclick', function (cluster) {
  72. map.fitBounds(cluster.getBounds());
  73. if (map.getZoom() > 14) {
  74. map.setZoom(14);
  75. }
  76. });
  77. }
  78. }
  79. </script>
  80. <script async defer type="text/javascript" src="https://maps.google.com/maps/api/js?key={{ api_key }}&callback=start"></script>
  81. <img src="{{ image_city }}" /> {{ field_1 }} <br />
  82. <img src="{{ image_stage }}" /> {{ field_2 }}
  83. {% endblock %}