2017-07-24 20:04:41 +02:00
|
|
|
function initCarto() {
|
|
|
|
if ($("#map").length > 0) {
|
|
|
|
var position = getPosition() || defaultGestionnairePosition();
|
|
|
|
|
|
|
|
var map = L.map('map', {
|
|
|
|
scrollWheelZoom: false
|
|
|
|
}).setView([position.lat, position.lon], position.zoom);
|
|
|
|
|
2017-10-11 14:42:27 +02:00
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
2017-07-24 20:04:41 +02:00
|
|
|
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
// draw external polygons
|
|
|
|
drawCadastre(map);
|
|
|
|
drawQuartiersPrioritaires(map);
|
|
|
|
|
|
|
|
// draw user polygon
|
|
|
|
drawUserSelection(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).on('turbolinks:load', initCarto);
|
|
|
|
|
|
|
|
function drawUserSelection(map) {
|
2017-08-30 15:31:51 +02:00
|
|
|
if (dossierJsonLatLngs.length > 0) {
|
|
|
|
var polygon = L.polygon(dossierJsonLatLngs, { color: 'red', zIndex: 3 }).addTo(map);
|
|
|
|
map.fitBounds(polygon.getBounds());
|
|
|
|
}
|
2017-07-24 20:04:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function defaultGestionnairePosition() {
|
|
|
|
var LON = '2.428462';
|
|
|
|
var LAT = '46.538192';
|
|
|
|
return { lon: LON, lat: LAT, zoom: 5 }
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPosition() {
|
|
|
|
var position;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: getPositionUrl,
|
|
|
|
dataType: 'json',
|
|
|
|
async: false
|
|
|
|
}).done(function (data) {
|
|
|
|
position = data
|
|
|
|
});
|
|
|
|
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawLayerWithItems(map, items, style) {
|
|
|
|
if (Array.isArray(items) && items.length > 0) {
|
|
|
|
var layer = new L.GeoJSON();
|
|
|
|
|
|
|
|
items.forEach(function (item) {
|
|
|
|
layer.addData(item.geometry);
|
|
|
|
});
|
|
|
|
|
|
|
|
layer.setStyle(style).addTo(map);
|
|
|
|
}
|
|
|
|
}
|