From 442a6a3cdded6f6fe490ea6cc5e4a32e74d8efdc Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 15 Apr 2020 17:55:37 +0200 Subject: [PATCH] Remove deprecated map reader --- app/javascript/new_design/champs/carte.js | 4 - app/javascript/shared/carte.js | 104 ---------------------- 2 files changed, 108 deletions(-) delete mode 100644 app/javascript/shared/carte.js diff --git a/app/javascript/new_design/champs/carte.js b/app/javascript/new_design/champs/carte.js index 2ae19ac8d..a5b6c2ebe 100644 --- a/app/javascript/new_design/champs/carte.js +++ b/app/javascript/new_design/champs/carte.js @@ -16,10 +16,6 @@ async function loadAndDrawMap(element) { const { drawEditableMap } = await import('../../shared/carte-editor'); drawEditableMap(element, data); - } else { - const { drawMap } = await import('../../shared/carte'); - - drawMap(element, data); } } diff --git a/app/javascript/shared/carte.js b/app/javascript/shared/carte.js deleted file mode 100644 index cd0434076..000000000 --- a/app/javascript/shared/carte.js +++ /dev/null @@ -1,104 +0,0 @@ -import L from 'leaflet'; - -const MAPS = new WeakMap(); - -export function drawMap(element, data) { - const map = initMap(element, data); - - drawCadastre(map, data); - drawQuartiersPrioritaires(map, data); - drawParcellesAgricoles(map, data); - drawUserSelection(map, data); -} - -function initMap(element, { position }) { - if (MAPS.has(element)) { - return MAPS.get(element); - } else { - const map = L.map(element, { - scrollWheelZoom: false - }).setView([position.lat, position.lon], position.zoom); - - const loadTilesLayer = process.env.RAILS_ENV != 'test'; - if (loadTilesLayer) { - L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { - attribution: - '© OpenStreetMap contributors' - }).addTo(map); - } - - MAPS.set(element, map); - return map; - } -} - -function drawUserSelection(map, { selection }) { - if (selection) { - const layer = L.geoJSON(selection, { - style: USER_SELECTION_POLYGON_STYLE - }); - - layer.addTo(map); - - map.fitBounds(layer.getBounds()); - } -} - -function drawCadastre(map, { cadastres }) { - drawLayer(map, cadastres, noEditStyle(CADASTRE_POLYGON_STYLE)); -} - -function drawQuartiersPrioritaires(map, { quartiersPrioritaires }) { - drawLayer(map, quartiersPrioritaires, noEditStyle(QP_POLYGON_STYLE)); -} - -function drawParcellesAgricoles(map, { parcellesAgricoles }) { - drawLayer(map, parcellesAgricoles, noEditStyle(RPG_POLYGON_STYLE)); -} - -function drawLayer(map, data, style) { - if (Array.isArray(data) && data.length > 0) { - const layer = new L.GeoJSON(undefined, { - interactive: false, - style - }); - - for (let { geometry } of data) { - layer.addData(geometry); - } - - layer.addTo(map); - } -} - -function noEditStyle(style) { - return Object.assign({}, style, { - opacity: 0.7, - fillOpacity: 0.5, - color: style.fillColor - }); -} - -const POLYGON_STYLE = { - weight: 2, - opacity: 0.3, - color: 'white', - dashArray: '3', - fillOpacity: 0.7 -}; - -const CADASTRE_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, { - fillColor: '#8a6d3b' -}); - -const QP_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, { - fillColor: '#31708f' -}); - -const RPG_POLYGON_STYLE = Object.assign({}, POLYGON_STYLE, { - fillColor: '#31708f' -}); - -const USER_SELECTION_POLYGON_STYLE = { - color: 'red' -};