2018-08-09 11:53:59 +02:00
|
|
|
import $ from 'jquery';
|
2018-07-12 11:50:47 +02:00
|
|
|
import L from 'leaflet';
|
|
|
|
|
|
|
|
import { getData } from '../shared/data';
|
2018-10-03 10:39:35 +02:00
|
|
|
import { DEFAULT_POSITION } from '../shared/carto';
|
2018-07-12 11:50:47 +02:00
|
|
|
|
|
|
|
import {
|
|
|
|
drawCadastre,
|
|
|
|
drawQuartiersPrioritaires,
|
|
|
|
drawUserSelection
|
|
|
|
} from './carto/draw';
|
|
|
|
|
|
|
|
function initialize() {
|
|
|
|
if ($('#map').length > 0) {
|
|
|
|
$.getJSON(getData('carto').getPositionUrl).then(
|
|
|
|
position => initializeWithPosition(position),
|
|
|
|
() => initializeWithPosition(DEFAULT_POSITION)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
addEventListener('turbolinks:load', initialize);
|
|
|
|
|
|
|
|
function initializeWithPosition(position) {
|
|
|
|
const map = L.map('map', {
|
|
|
|
scrollWheelZoom: false
|
|
|
|
}).setView([position.lat, position.lon], position.zoom);
|
|
|
|
|
|
|
|
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
|
|
attribution:
|
|
|
|
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
|
|
|
}).addTo(map);
|
|
|
|
|
|
|
|
const data = getData('carto');
|
|
|
|
|
|
|
|
// draw external polygons
|
|
|
|
drawCadastre(map, data);
|
|
|
|
drawQuartiersPrioritaires(map, data);
|
|
|
|
|
|
|
|
// draw user polygon
|
|
|
|
drawUserSelection(map, data);
|
|
|
|
}
|