templates/areas/karte/view.html.twig line 1

Open in your IDE?
  1. {# settings #}
  2. {% extends ('areas_shared/settings.html.twig') %}
  3. {% block content %}
  4.     {# default margin bottom #}
  5.     {% if marginBottom.isEmpty() %}
  6.         {% do marginBottom.setDataFromResource('full-margin-bottom') %}
  7.     {% endif %}
  8.     {# default background color #}
  9.     {% if backgroundColor.isEmpty() %}
  10.         {% do backgroundColor.setDataFromResource('background-white') %}
  11.     {% endif %}
  12.     {# latitude #}
  13.     {% set latitude = pimcore_input('latitude', {
  14.         'placeholder': '123.456'
  15.     }) %}
  16.     {# longitude #}
  17.     {% set longitude = pimcore_input('longitude', {
  18.         'placeholder': '123.456'
  19.     }) %}
  20.     {# zoom #}
  21.     {% set zoom = pimcore_input('zoom', {
  22.         'placeholder': '13'
  23.     }) %}
  24.     {# infowindow #}
  25.     {% set infowindow = pimcore_textarea('infowindow', {
  26.         'placeholder': 'Text',
  27.         'nl2br': true
  28.     }) %}
  29.     {# infowindow #}
  30.     {% set companyName = pimcore_input('companyName', {
  31.         'placeholder': 'Text'
  32.     }) %}
  33.     {# editmode #}
  34.     {% if editmode %}
  35.         <div class="editmode">
  36.             <div class="accordion-container">
  37.                 <div class="accordion-button">
  38.                     <span class="accordion-button-text">Karte</span>
  39.                     {{ include('svg/editmode/setting.html.twig') }}
  40.                 </div>
  41.                 <div class="panel">
  42.                     <div class="settings-container">
  43.                         <div class="setting input">
  44.                             <label>Anker:</label>
  45.                             {{ anchor|raw }}
  46.                         </div>
  47.                         <div class="setting select">
  48.                             <label>Abstand unten:</label>
  49.                             {{ marginBottom|raw }}
  50.                         </div>
  51.                         <div class="setting input">
  52.                             <label><strong>Standort</strong></label>
  53.                             <label>Breitengrad</label>
  54.                             {{ latitude|raw }}
  55.                             <label>Längengrad</label>
  56.                             {{ longitude|raw }}
  57.                             <label>Zoom:</label>
  58.                             {{ zoom|raw }}
  59.                             <label>Popup:</label>
  60.                             {{ infowindow|raw }}
  61.                             <label>Mouseover-Tooltip:</label>
  62.                             {{ companyName|raw }}
  63.                         </div>
  64.                     </div>
  65.                 </div>
  66.             </div>
  67.         </div>
  68.     {% endif %}
  69.     <div class="karte-brick brick-container {{ backgroundColor.data }} {{ marginBottom.data }}" id="mapContainer">
  70.         {# anchor #}
  71.         {% if anchor.data %}
  72.             <div class="anchor" id="{{ anchor.data }}"></div>
  73.         {% endif %}
  74.         <div class="container-1420">
  75.             <div class="map" id="map">
  76.             </div>
  77.             <script>
  78.                 // load map script
  79.                 function loadMap() {
  80.                     const script = document.createElement('script');
  81.                     script.src = "https://maps.googleapis.com/maps/api/js?key=" + window.googleMapsAPI + "&callback=initMap&libraries=&v=weekly";
  82.                     document.head.appendChild(script);
  83.                 }
  84.                 // initialize and add the map
  85.                 function initMap() {
  86.                     // location:
  87.                     // 47.18298765988833, 8.107441975161748
  88.                     {% if latitude.data and longitude.data %}
  89.                         const location = {
  90.                             lat: {{ latitude.data }},
  91.                             lng: {{ longitude.data }}
  92.                         };
  93.                     {% else %}
  94.                         const location = null;
  95.                     {% endif %}
  96.                     // styles
  97.                     /* const styles = [
  98.                         {
  99.                             "featureType": "administrative",
  100.                             "elementType": "all",
  101.                             "stylers": [
  102.                                 {
  103.                                     "saturation": "-100"
  104.                                 }
  105.                             ]
  106.                         },
  107.                         {
  108.                             "featureType": "administrative.province",
  109.                             "elementType": "all",
  110.                             "stylers": [
  111.                                 {
  112.                                     "visibility": "off"
  113.                                 }
  114.                             ]
  115.                         },
  116.                         {
  117.                             "featureType": "landscape",
  118.                             "elementType": "all",
  119.                             "stylers": [
  120.                                 {
  121.                                     "saturation": -100
  122.                                 },
  123.                                 {
  124.                                     "lightness": 65
  125.                                 },
  126.                                 {
  127.                                     "visibility": "on"
  128.                                 }
  129.                             ]
  130.                         },
  131.                         {
  132.                             "featureType": "poi",
  133.                             "elementType": "all",
  134.                             "stylers": [
  135.                                 {
  136.                                     "saturation": -100
  137.                                 },
  138.                                 {
  139.                                     "lightness": "50"
  140.                                 },
  141.                                 {
  142.                                     "visibility": "simplified"
  143.                                 }
  144.                             ]
  145.                         },
  146.                         {
  147.                             "featureType": "road",
  148.                             "elementType": "all",
  149.                             "stylers": [
  150.                                 {
  151.                                     "saturation": "-100"
  152.                                 }
  153.                             ]
  154.                         },
  155.                         {
  156.                             "featureType": "road.highway",
  157.                             "elementType": "all",
  158.                             "stylers": [
  159.                                 {
  160.                                     "visibility": "simplified"
  161.                                 }
  162.                             ]
  163.                         },
  164.                         {
  165.                             "featureType": "road.arterial",
  166.                             "elementType": "all",
  167.                             "stylers": [
  168.                                 {
  169.                                     "lightness": "30"
  170.                                 }
  171.                             ]
  172.                         },
  173.                         {
  174.                             "featureType": "road.local",
  175.                             "elementType": "all",
  176.                             "stylers": [
  177.                                 {
  178.                                     "lightness": "40"
  179.                                 }
  180.                             ]
  181.                         },
  182.                         {
  183.                             "featureType": "transit",
  184.                             "elementType": "all",
  185.                             "stylers": [
  186.                                 {
  187.                                     "saturation": -100
  188.                                 },
  189.                                 {
  190.                                     "visibility": "simplified"
  191.                                 }
  192.                             ]
  193.                         },
  194.                         {
  195.                             "featureType": "water",
  196.                             "elementType": "geometry",
  197.                             "stylers": [
  198.                                 {
  199.                                     "hue": "#ffff00"
  200.                                 },
  201.                                 {
  202.                                     "lightness": -25
  203.                                 },
  204.                                 {
  205.                                     "saturation": -97
  206.                                 }
  207.                             ]
  208.                         },
  209.                         {
  210.                             "featureType": "water",
  211.                             "elementType": "labels",
  212.                             "stylers": [
  213.                                 {
  214.                                     "lightness": -25
  215.                                 },
  216.                                 {
  217.                                     "saturation": -100
  218.                                 }
  219.                             ]
  220.                         }
  221.                     ]; */
  222.                     // map
  223.                     var map = new google.maps.Map(document.getElementById("map"), {
  224.                         mapTypeId: google.maps.MapTypeId.ROADMAP,
  225.                         //styles: styles
  226.                     });
  227.                     // marker
  228.                     const fontawesomeMarker = "M27.648-41.399q0-3.816-2.7-6.516t-6.516-2.7-6.516 2.7-2.7 6.516 2.7 6.516 6.516 2.7 6.516-2.7 2.7-6.516zm9.216 0q0 3.924-1.188 6.444l-13.104 27.864q-.576 1.188-1.71 1.872t-2.43.684-2.43-.684-1.674-1.872l-13.14-27.864q-1.188-2.52-1.188-6.444 0-7.632 5.4-13.032t13.032-5.4 13.032 5.4 5.4 13.032z";
  229.                     var markers = [];
  230.                     const marker = new google.maps.Marker({
  231.                         position: location,
  232.                         map: map, 
  233.                         icon: {
  234.                             path: fontawesomeMarker,
  235.                             scale: 0.7,
  236.                             strokeWeight: 1,
  237.                             strokeColor: '#b21610',
  238.                             strokeOpacity: 1,
  239.                             fillColor: '#ea4336',
  240.                             fillOpacity: 1,
  241.                             anchor: new google.maps.Point(18.25, -5)
  242.                         },
  243.                         title: '{{ companyName.data }}'
  244.                     });
  245.                     markers.push(marker);
  246.                     /* if (location) {
  247.                         if (window.innerWidth < 460) {
  248.                             var markerSursee = new google.maps.Marker({
  249.                                 position: location,
  250.                                 map,
  251.                                 //title: "artimelt AG",
  252.                                 icon: {
  253.                                     url: '/assets/svg/map_icon_mobile.svg',
  254.                                     size: new google.maps.Size(50, 50),
  255.                                     origin: new google.maps.Point(0, 0),
  256.                                     anchor: new google.maps.Point(25, 50)
  257.                                 }
  258.                             });
  259.                         } else {
  260.                             var markerSursee = new google.maps.Marker({
  261.                                 position: location,
  262.                                 map,
  263.                                 //title: "artimelt AG",
  264.                                 icon: {
  265.                                     url: '/assets/svg/map_icon.svg',
  266.                                     size: new google.maps.Size(70, 70),
  267.                                     origin: new google.maps.Point(0, 0),
  268.                                     anchor: new google.maps.Point(35, 70)
  269.                                 }
  270.                             });
  271.                         }
  272.                         markers.push(markerSursee);
  273.                     } */
  274.                     var bounds = new google.maps.LatLngBounds();
  275.                     for (i = 0; i < markers.length; i++) {
  276.                         bounds.extend(markers[i].getPosition());
  277.                     }
  278.                     // center the map
  279.                     if (markers.length > 1) {
  280.                         map.setCenter(bounds.getCenter());
  281.                     } else {
  282.                         map.setCenter(location);
  283.                     }
  284.                     // center the map to the geometric center of all markers
  285.                     if (markers.length > 1) {
  286.                         map.fitBounds(bounds, 35);
  287.                         // remove one zoom level to ensure no marker is on the edge.
  288.                         //map.setZoom(map.getZoom() + 1);
  289.                         if (window.innerWidth > 1200) {
  290.                             map.fitBounds(bounds, 50);
  291.                         }
  292.                     } else if (markers.length == 1) {
  293.                         map.setZoom({{ zoom.data }});
  294.                     } else {
  295.                         map.setZoom(13);
  296.                     }
  297.                     // info windows
  298.                     var infoWindows = [];
  299.                     {% if infowindow.data %}
  300.                         const infowindow = new google.maps.InfoWindow({
  301.                             content: '{{ infowindow.data|replace({"\n": ' ', "\r": ' '})|raw }}',
  302.                             maxWidth: 500
  303.                         });
  304.                         infoWindows.push(infowindow);
  305.                     {% endif %}
  306.                     // info windows popup
  307.                     {% if infowindow.data %}
  308.                         for (var i = 0; i < markers.length; i++) {
  309.                             const marker = markers[i];
  310.                             const counter = i;
  311.                             marker.addListener('click', () => {
  312.                                 infoWindows[counter].open({
  313.                                     anchor: marker,
  314.                                     map,
  315.                                     shouldFocus: false
  316.                                 });
  317.                             });
  318.                         }
  319.                     {% endif %}
  320.                 }
  321.             </script>
  322.             {% if editmode %}
  323.                 <script>
  324.                     let map = document.getElementById('map');
  325.                     let mapContainer = document.getElementById('mapContainer');
  326.                     
  327.                     if (map && mapContainer) {
  328.                         mapContainer.classList.add('active');
  329.                         // script exists
  330.                         if (typeof google !== undefined && typeof google === 'object' && typeof google.maps === 'object') {
  331.                             initMap();
  332.                         // load script
  333.                         } else {
  334.                             loadMap();
  335.                         }
  336.                     }
  337.                 </script>
  338.             {% endif %}
  339.         </div>
  340.     </div>
  341. {% endblock %}