From f321e9df3f6f7a24924877384bbb88e27a87e488 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Sat, 13 Oct 2018 10:36:14 +0200 Subject: [PATCH] carto: use initMap in new design carto --- app/javascript/new_design/carto.js | 40 ++++++++---------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/app/javascript/new_design/carto.js b/app/javascript/new_design/carto.js index 895a613ba..3cf8a57a5 100644 --- a/app/javascript/new_design/carto.js +++ b/app/javascript/new_design/carto.js @@ -1,9 +1,5 @@ -import L from 'leaflet'; -import { getJSON } from '@utils'; - import { getData } from '../shared/data'; -import { DEFAULT_POSITION } from '../shared/carto'; - +import { initMap } from '../shared/carto'; import { drawCadastre, drawQuartiersPrioritaires, @@ -12,31 +8,17 @@ import { function initialize() { if (document.getElementById('map')) { - getJSON(getData('carto').getPositionUrl).then( - position => initializeWithPosition(position), - () => initializeWithPosition(DEFAULT_POSITION) - ); + const position = getData('carto').position; + const map = initMap(position); + const data = getData('carto'); + + // draw external polygons + drawCadastre(map, data); + drawQuartiersPrioritaires(map, data); + + // draw user polygon + drawUserSelection(map, data); } } 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: - '© OpenStreetMap contributors' - }).addTo(map); - - const data = getData('carto'); - - // draw external polygons - drawCadastre(map, data); - drawQuartiersPrioritaires(map, data); - - // draw user polygon - drawUserSelection(map, data); -}