2018-10-16 10:49:00 +02:00
|
|
|
import { CREATE } from 'leaflet-freedraw';
|
|
|
|
import { on } from '@utils';
|
2018-10-13 10:59:07 +02:00
|
|
|
import { getData } from '../shared/data';
|
2018-10-16 10:49:00 +02:00
|
|
|
import {
|
|
|
|
initMap,
|
|
|
|
geocodeAddress,
|
|
|
|
drawUserSelection,
|
|
|
|
drawCadastre,
|
|
|
|
drawQuartiersPrioritaires,
|
|
|
|
addFreeDrawEvents
|
2018-10-17 11:58:35 +02:00
|
|
|
} from '../shared/carte';
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2018-10-13 10:59:07 +02:00
|
|
|
function initialize() {
|
2018-10-16 10:49:00 +02:00
|
|
|
const element = document.getElementById('map');
|
|
|
|
|
|
|
|
if (element) {
|
2018-10-13 10:59:07 +02:00
|
|
|
const data = getData('carto');
|
2018-10-16 10:49:00 +02:00
|
|
|
const map = initMap(element, data.position, true);
|
2018-10-13 10:59:07 +02:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
addAddressSelectEvent(map);
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
on('#new', 'click', () => {
|
|
|
|
map.freeDraw.mode(CREATE);
|
|
|
|
});
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
const cartoDrawZones = data => {
|
|
|
|
drawCadastre(map, data, true);
|
|
|
|
drawQuartiersPrioritaires(map, data, true);
|
|
|
|
};
|
2015-11-12 17:34:12 +01:00
|
|
|
|
2018-10-13 10:59:07 +02:00
|
|
|
window.DS = { cartoDrawZones };
|
2018-10-03 10:39:35 +02:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
// draw external polygons
|
2018-10-13 10:59:07 +02:00
|
|
|
cartoDrawZones(data);
|
2016-01-18 14:45:08 +01:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
// draw user polygon
|
|
|
|
drawUserSelection(map, data, true);
|
|
|
|
addFreeDrawEvents(map, 'input[name=selection]');
|
2018-10-03 10:39:35 +02:00
|
|
|
}
|
2015-12-10 14:33:09 +01:00
|
|
|
}
|
|
|
|
|
2018-10-13 10:59:07 +02:00
|
|
|
addEventListener('turbolinks:load', initialize);
|
2016-01-27 15:48:27 +01:00
|
|
|
|
2018-10-16 10:49:00 +02:00
|
|
|
function addAddressSelectEvent(map) {
|
2018-10-13 10:59:07 +02:00
|
|
|
on(
|
|
|
|
'#search-by-address input[type=address]',
|
2018-10-03 10:39:35 +02:00
|
|
|
'autocomplete:select',
|
2018-10-16 10:49:00 +02:00
|
|
|
(_, { label }) => {
|
|
|
|
geocodeAddress(map, label);
|
2018-10-03 10:39:35 +02:00
|
|
|
}
|
|
|
|
);
|
2016-06-09 16:28:44 +02:00
|
|
|
}
|