templates/location/list.html.twig line 1

Open in your IDE?
  1. {% extends 'content_base.html.twig' %}
  2. {% block title %}Show all Events{% endblock %}
  3. {% block stylesheets %}
  4.     {{ parent() }}
  5.     <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
  6.           integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
  7.           crossorigin=""/>
  8.     <link rel="stylesheet" href="{{ asset('css/map.css') }}">
  9.     <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
  10.     <link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
  11.     <link rel="stylesheet" href="{{ asset('css/cluster.css') }}">
  12. {% endblock %}
  13. {% block content_body %}
  14.     <div class="container">
  15.         <div class="row">
  16.             <div class="col-sm-6 mt-2">
  17.                 <div class="article-text table-responsive">
  18.                     {{ knp_pagination_render(pagination) }}
  19.                     <table class="table hoverTable table-striped table-hover">
  20.                     <thead>
  21.                         <tr>
  22.                             <th scope="col" class="col-3 mx-3">{{knp_pagination_sortable(pagination, 'Type', 'l.type') }}</th>
  23.                             <th scope="col" class="col-6 mx-3">{{knp_pagination_sortable(pagination, 'Name', 'l.name') }}</th>
  24.                             <th scope="col" class="col-3 mx-3" style="min-width: 120px;">{{knp_pagination_sortable(pagination, 'Approved', 'l.approved') }}</th>
  25.                         </tr>
  26.                         <tr>
  27.                             <th colspan="3">
  28.                             <form>
  29.                                 <div class="input-group mb-3">
  30.                                     <input type="text"
  31.                                            name="q"
  32.                                            class="form-control"
  33.                                            placeholder="Search..."
  34.                                            value="{{ app.request.query.get('q') }}"
  35.                                     >
  36.                                     <div class="input-group-append">
  37.                                         <button type="submit"
  38.                                                 class="btn btn-outline-secondary">
  39.                                             <span class="fa fa-filter"></span>
  40.                                         </button>
  41.                                     </div>
  42.                                 </div>
  43.                             </form>
  44.                             </th>
  45.                         </tr>
  46.                     </thead>
  47.                     {% for location in pagination %}
  48.                         <tr>
  49.                             {% set location = location.update(app.user) %}
  50.                             <td>
  51.                                 <a href="{{path('location_show', {
  52.                                     id: location.id
  53.                                 })}}">
  54.                                     <img class="article-icon" src="{{ location.image | imagine_filter('squared_thumbnail_icon') }}">
  55.                                 </a>
  56.                             </td>
  57.                             <td>
  58.                                 {{ location.name}}
  59.                             </td>
  60.                             <td>
  61.                                 <a href="{{path('location_show', {
  62.                                     id: location.id
  63.                                 })
  64.                                 }}"><span class="fa fa-eye"></span>
  65.                                 </a>
  66.                                 {% if is_granted('ROLE_EDIT_ENTITY') %}
  67.                                 <a href="{{path('location_edit', {
  68.                                     id: location.id
  69.                                 })
  70.                                 }}"><span class="fa fa-pencil"></span>
  71.                                 </a>
  72.                                 {% endif %}
  73.                                 {# }% if is_granted('ROLE_ACCEPT_CHANGES') and not location.approved %}
  74.                                     <a href="{{path('location_edit', {
  75.                                         id: location.id
  76.                                     })
  77.                                     }}"><span class="fa fa-check-circle "></span>
  78.                                     </a>
  79.                                 {% endif %#}
  80.                             </td>
  81.                         </tr>
  82.                     {%  endfor %}
  83.                     </table>
  84.                 </div>
  85.             </div>
  86.             <div class="col-sm-6 mt-3">
  87.                 <div id="mapid"></div>
  88.             </div>
  89.         </div>
  90.     </div>
  91. {% endblock %}
  92. {% block javascripts %}
  93.     {{ parent() }}
  94.     <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
  95.             integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
  96.             crossorigin=""></script>
  97.     <script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
  98.     <script type="text/javascript">
  99.     var data = {{ locationsSerialized| json_encode|raw }};
  100.         var map = L.map('mapid');
  101.         mapLink =
  102.             '<a href="http://openstreetmap.org">OpenStreetMap</a>';
  103.        /* L.tileLayer(
  104.             'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
  105.                 attribution: '&copy; ' + mapLink + ' Contributors',
  106.                 maxZoom: 18,
  107.             }).addTo(map);*/
  108.     /*var Esri_WorldShadedRelief = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}', {
  109.         //var Esri_WorldShadedRelief = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/WorldPhysical/MapServer/tile/{z}/{y}/{x}', {
  110.         attribution: 'Tiles &copy; Esri &mdash; Source: Esri',
  111.         maxZoom: 13
  112.     });
  113.     Esri_WorldShadedRelief.addTo(map);*/
  114.    /* var Stamen_Terrain = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}{r}.{ext}', {
  115.         attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> &mdash; Map data &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
  116.         subdomains: 'abcd',
  117.         minZoom: 0,
  118.         maxZoom: 18,
  119.         ext: 'png'
  120.     });
  121.     Stamen_Terrain.addTo(map);*/
  122.     var Esri_World_Imagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
  123.         attribution: 'Tiles &copy; Esri &mdash; Source: Esri',
  124.         maxZoom: 18
  125.     });
  126.     Esri_World_Imagery.addTo(map);
  127.     var markerGroups = [];
  128.         var markers =[];
  129.         var myRenderer = L.canvas({ padding: 0.5 });
  130.         data.forEach(function (d,i) {
  131.             var type = 'all';// d.type
  132.             if(markerGroups[type]  === undefined)
  133.             {   markerGroups[type] = L.markerClusterGroup({
  134.                 iconCreateFunction: function(cluster) {
  135.                     // get the number of items in the cluster
  136.                     var count = cluster.getChildCount();
  137.                     // figure out how many digits long the number is
  138.                     var digits = (count + '').length;
  139.                     // Return a new L.DivIcon with our classes so we can
  140.                     // style them with CSS. Take a look at the CSS in
  141.                     // the <head> to see these styles. You have to set
  142.                     // iconSize to null if you want to use CSS to set the
  143.                     // width and height.
  144.                     return L.divIcon({
  145.                         html: count,
  146.                         className: 'cluster digits-' + digits,
  147.                         iconSize: null
  148.                     });
  149.                 }
  150.             });
  151.             }
  152.             var marker = L.circleMarker([d.lat,d.lon], {
  153.                 color: getTypeColor(d.type),
  154.                     renderer: myRenderer,
  155.                 radius : 5,
  156.                 name: d.name,
  157.                 type: d.type,
  158.                 id: d.id,
  159.             })
  160.                 .bindPopup(d.name)
  161.                 .on('mouseover', function (e) {
  162.                     this.openPopup();
  163.                 })
  164.                 .on('mouseout', function (e) {
  165.                     this.closePopup();
  166.                 })
  167.                 .on({
  168.                     click: highlightFeature,
  169.                 })
  170.             markerGroups[type].addLayer(marker);
  171.         });
  172.     var latlngbounds = L.latLngBounds();
  173.     for (var key in markerGroups) {
  174.         latlngbounds.extend(markerGroups[key].getBounds());
  175.         map.addLayer(markerGroups[key]);
  176.     };
  177.     map.fitBounds(latlngbounds, { padding: [10, 10] });
  178. function getTypeColor(d) {
  179.     return d =="town" ? '#ff0000' : d =="river" ?  '#0000ff': d =="sea" ?
  180.         '#0000ff' : d =="mountain" ? '#aa6600' : '#000000';
  181. }
  182. function iconCreateFunction (cluster) {
  183.     // get the number of items in the cluster
  184.     var count = cluster.getChildCount();
  185.     // figure out how many digits long the number is
  186.     var digits = (count + '').length;
  187.     // Return a new L.DivIcon with our classes so we can
  188.     // style them with CSS. Take a look at the CSS in
  189.     // the <head> to see these styles. You have to set
  190.     // iconSize to null if you want to use CSS to set the
  191.     // width and height.
  192.     return L.divIcon({
  193.         html: count,
  194.         className: 'cluster digits-' + digits,
  195.         iconSize: null
  196.     });
  197. }
  198. function highlightFeature(e) {
  199.     var layer = e.target;
  200.     info.update(layer.options);
  201.     /*layer.setStyle({
  202.         weight: 5,
  203.         color: '#666',
  204.         dashArray: '',
  205.         fillOpacity: 0.7
  206.     });*/
  207.     if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
  208.         layer.bringToFront();
  209.     }
  210. }
  211. var info = L.control();
  212. info.onAdd = function (map) {
  213.     this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
  214.     this.update();
  215.     return this._div;
  216. };
  217. // method that we will use to update the control based on feature properties passed
  218. info.update = function (props) {
  219.     {% if is_granted('ROLE_EDIT_ENTITY') %}
  220.         var editUrl = '';
  221.     {% endif %}
  222.     var infoUrl = '';
  223.     if(props) {
  224.         infoUrl = '{{ path("location_show", {'id': 'location_id'})|escape('js') }}';
  225.         infoUrl = infoUrl.replace("location_id", props.id);
  226.         {% if is_granted('ROLE_EDIT_ENTITY') %}
  227.         editUrl = '{{ path("location_edit", {'id': 'location_id'})|escape('js') }}';
  228.         editUrl = editUrl.replace("location_id", props.id);
  229.         {% endif %}
  230.     }
  231.     this._div.innerHTML = '<h4>Location Info</h4>' +  (props ?
  232.         '<b>' + props.name + '</b> (' + props.type + ')<br /><a href='+infoUrl+'><span class="fa fa-eye"></span></a>'
  233.             {% if is_granted('ROLE_EDIT_ENTITY') %}
  234.                + '<a href='+editUrl+'><span class="fa fa-pencil"></span></a>'
  235.             {% endif %}
  236.         : '');
  237. };
  238. info.addTo(map);
  239.     </script>
  240. {% endblock %}