demarches-normaliennes/app/javascript/old_design/carto.js

53 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-10-16 10:49:00 +02:00
import { CREATE } from 'leaflet-freedraw';
import { on } from '@utils';
import { getData } from '../shared/data';
2018-10-16 10:49:00 +02:00
import {
initMap,
geocodeAddress,
drawUserSelection,
drawCadastre,
drawQuartiersPrioritaires,
addFreeDrawEvents
} from '../shared/carto';
function initialize() {
2018-10-16 10:49:00 +02:00
const element = document.getElementById('map');
if (element) {
const data = getData('carto');
2018-10-16 10:49:00 +02:00
const map = initMap(element, data.position, true);
2018-10-16 10:49:00 +02:00
addAddressSelectEvent(map);
2018-10-16 10:49:00 +02:00
on('#new', 'click', () => {
map.freeDraw.mode(CREATE);
});
2018-10-16 10:49:00 +02:00
const cartoDrawZones = data => {
drawCadastre(map, data, true);
drawQuartiersPrioritaires(map, data, true);
};
window.DS = { cartoDrawZones };
2018-10-03 10:39:35 +02:00
2018-10-16 10:49:00 +02:00
// draw external polygons
cartoDrawZones(data);
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
}
}
addEventListener('turbolinks:load', initialize);
2018-10-16 10:49:00 +02:00
function addAddressSelectEvent(map) {
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
}