{% extends 'content_base.html.twig' %}
{% block title %}Show all Events{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<link rel="stylesheet" href="{{ asset('css/map.css') }}">
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet.markercluster@1.3.0/dist/MarkerCluster.Default.css" />
<link rel="stylesheet" href="{{ asset('css/cluster.css') }}">
{% endblock %}
{% block content_body %}
<div class="container">
<div class="row">
<div class="col-sm-6 mt-2">
<div class="article-text table-responsive">
{{ knp_pagination_render(pagination) }}
<table class="table hoverTable table-striped table-hover">
<thead>
<tr>
<th scope="col" class="col-3 mx-3">{{knp_pagination_sortable(pagination, 'Type', 'l.type') }}</th>
<th scope="col" class="col-6 mx-3">{{knp_pagination_sortable(pagination, 'Name', 'l.name') }}</th>
<th scope="col" class="col-3 mx-3" style="min-width: 120px;">{{knp_pagination_sortable(pagination, 'Approved', 'l.approved') }}</th>
</tr>
<tr>
<th colspan="3">
<form>
<div class="input-group mb-3">
<input type="text"
name="q"
class="form-control"
placeholder="Search..."
value="{{ app.request.query.get('q') }}"
>
<div class="input-group-append">
<button type="submit"
class="btn btn-outline-secondary">
<span class="fa fa-filter"></span>
</button>
</div>
</div>
</form>
</th>
</tr>
</thead>
{% for location in pagination %}
<tr>
{% set location = location.update(app.user) %}
<td>
<a href="{{path('location_show', {
id: location.id
})}}">
<img class="article-icon" src="{{ location.image | imagine_filter('squared_thumbnail_icon') }}">
</a>
</td>
<td>
{{ location.name}}
</td>
<td>
<a href="{{path('location_show', {
id: location.id
})
}}"><span class="fa fa-eye"></span>
</a>
{% if is_granted('ROLE_EDIT_ENTITY') %}
<a href="{{path('location_edit', {
id: location.id
})
}}"><span class="fa fa-pencil"></span>
</a>
{% endif %}
{# }% if is_granted('ROLE_ACCEPT_CHANGES') and not location.approved %}
<a href="{{path('location_edit', {
id: location.id
})
}}"><span class="fa fa-check-circle "></span>
</a>
{% endif %#}
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
<div class="col-sm-6 mt-3">
<div id="mapid"></div>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src="https://unpkg.com/leaflet.markercluster@1.4.1/dist/leaflet.markercluster.js"></script>
<script type="text/javascript">
var data = {{ locationsSerialized| json_encode|raw }};
var map = L.map('mapid');
mapLink =
'<a href="http://openstreetmap.org">OpenStreetMap</a>';
/* L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
}).addTo(map);*/
/*var Esri_WorldShadedRelief = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Shaded_Relief/MapServer/tile/{z}/{y}/{x}', {
//var Esri_WorldShadedRelief = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/WorldPhysical/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri',
maxZoom: 13
});
Esri_WorldShadedRelief.addTo(map);*/
/* var Stamen_Terrain = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}{r}.{ext}', {
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> — Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 18,
ext: 'png'
});
Stamen_Terrain.addTo(map);*/
var Esri_World_Imagery = L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', {
attribution: 'Tiles © Esri — Source: Esri',
maxZoom: 18
});
Esri_World_Imagery.addTo(map);
var markerGroups = [];
var markers =[];
var myRenderer = L.canvas({ padding: 0.5 });
data.forEach(function (d,i) {
var type = 'all';// d.type
if(markerGroups[type] === undefined)
{ markerGroups[type] = L.markerClusterGroup({
iconCreateFunction: function(cluster) {
// get the number of items in the cluster
var count = cluster.getChildCount();
// figure out how many digits long the number is
var digits = (count + '').length;
// Return a new L.DivIcon with our classes so we can
// style them with CSS. Take a look at the CSS in
// the <head> to see these styles. You have to set
// iconSize to null if you want to use CSS to set the
// width and height.
return L.divIcon({
html: count,
className: 'cluster digits-' + digits,
iconSize: null
});
}
});
}
var marker = L.circleMarker([d.lat,d.lon], {
color: getTypeColor(d.type),
renderer: myRenderer,
radius : 5,
name: d.name,
type: d.type,
id: d.id,
})
.bindPopup(d.name)
.on('mouseover', function (e) {
this.openPopup();
})
.on('mouseout', function (e) {
this.closePopup();
})
.on({
click: highlightFeature,
})
markerGroups[type].addLayer(marker);
});
var latlngbounds = L.latLngBounds();
for (var key in markerGroups) {
latlngbounds.extend(markerGroups[key].getBounds());
map.addLayer(markerGroups[key]);
};
map.fitBounds(latlngbounds, { padding: [10, 10] });
function getTypeColor(d) {
return d =="town" ? '#ff0000' : d =="river" ? '#0000ff': d =="sea" ?
'#0000ff' : d =="mountain" ? '#aa6600' : '#000000';
}
function iconCreateFunction (cluster) {
// get the number of items in the cluster
var count = cluster.getChildCount();
// figure out how many digits long the number is
var digits = (count + '').length;
// Return a new L.DivIcon with our classes so we can
// style them with CSS. Take a look at the CSS in
// the <head> to see these styles. You have to set
// iconSize to null if you want to use CSS to set the
// width and height.
return L.divIcon({
html: count,
className: 'cluster digits-' + digits,
iconSize: null
});
}
function highlightFeature(e) {
var layer = e.target;
info.update(layer.options);
/*layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});*/
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
}
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (props) {
{% if is_granted('ROLE_EDIT_ENTITY') %}
var editUrl = '';
{% endif %}
var infoUrl = '';
if(props) {
infoUrl = '{{ path("location_show", {'id': 'location_id'})|escape('js') }}';
infoUrl = infoUrl.replace("location_id", props.id);
{% if is_granted('ROLE_EDIT_ENTITY') %}
editUrl = '{{ path("location_edit", {'id': 'location_id'})|escape('js') }}';
editUrl = editUrl.replace("location_id", props.id);
{% endif %}
}
this._div.innerHTML = '<h4>Location Info</h4>' + (props ?
'<b>' + props.name + '</b> (' + props.type + ')<br /><a href='+infoUrl+'><span class="fa fa-eye"></span></a>'
{% if is_granted('ROLE_EDIT_ENTITY') %}
+ '<a href='+editUrl+'><span class="fa fa-pencil"></span></a>'
{% endif %}
: '');
};
info.addTo(map);
</script>
{% endblock %}