Only load Leaflet once, as module

This commit is contained in:
Yohan Boniface 2023-12-29 15:07:27 +01:00 committed by Alexis Métaireau
parent 95212dbdf5
commit ce22a2ee74
3 changed files with 231 additions and 95 deletions

View file

@ -1,7 +1,144 @@
import { Util } from '../../vendors/leaflet/leaflet-src.esm.js' import {
bind,
Bounds,
Browser,
Canvas,
Circle,
Class,
Control,
control,
DivIcon,
DomEvent,
DomUtil,
Draggable,
Evented,
extend,
FeatureGroup,
featureGroup,
GeoJSON,
Handler,
Icon,
LatLng,
latLng,
LatLngBounds,
latLngBounds,
Layer,
LayerGroup,
LineUtil,
Map,
map,
Marker,
Mixin,
Path,
Point,
point,
Polygon,
Polyline,
polyline,
Popup,
Projection,
Rectangle,
rectangle,
setOptions,
stamp,
svg,
TileLayer,
Util,
} from '../../vendors/leaflet/leaflet-src.esm.js'
// expose the modules to the window.vendors global scope // expose the modules to the window.vendors global scope
window.vendors = { window.L = {
bind,
Bounds,
Browser,
Canvas,
Circle,
Class,
Control,
control,
DivIcon,
DomEvent,
DomUtil,
Draggable,
Evented,
extend,
FeatureGroup,
featureGroup,
GeoJSON,
Handler,
Icon,
LatLng,
latLng,
LatLngBounds,
latLngBounds,
Layer,
LayerGroup,
LineUtil,
Map,
map,
Marker,
Mixin,
Path,
Point,
point,
Polygon,
Polyline,
polyline,
Popup,
Projection,
Rectangle,
rectangle,
setOptions,
stamp,
svg,
TileLayer,
Util,
}
export {
bind,
Bounds,
Browser,
Canvas,
Circle,
Class,
Control,
control,
DivIcon,
DomEvent,
DomUtil,
Draggable,
Evented,
extend,
FeatureGroup,
featureGroup,
GeoJSON,
Handler,
Icon,
LatLng,
latLng,
LatLngBounds,
latLngBounds,
Layer,
LayerGroup,
LineUtil,
Map,
map,
Marker,
Mixin,
Path,
Point,
point,
Polygon,
Polyline,
polyline,
Popup,
Projection,
Rectangle,
rectangle,
setOptions,
stamp,
svg,
TileLayer,
Util, Util,
} }
export { Util }

View file

@ -3,51 +3,50 @@
<head> <head>
<title>Umap front Tests</title> <title>Umap front Tests</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<script src="../vendors/leaflet/leaflet-src.js"></script> <script type="module" src="{{ STATIC_URL }}umap/js/modules/vendors.js" defer></script>
<script src="../vendors/editable/Path.Drag.js"></script> <script src="../vendors/editable/Path.Drag.js" defer></script>
<script src="../vendors/editable/Leaflet.Editable.js"></script> <script src="../vendors/editable/Leaflet.Editable.js" defer></script>
<script src="../vendors/hash/leaflet-hash.js"></script> <script src="../vendors/hash/leaflet-hash.js" defer></script>
<script src="../vendors/i18n/Leaflet.i18n.js"></script> <script src="../vendors/i18n/Leaflet.i18n.js" defer></script>
<script src="../vendors/editinosm/Leaflet.EditInOSM.js"></script> <script src="../vendors/editinosm/Leaflet.EditInOSM.js" defer></script>
<script src="../vendors/minimap/Control.MiniMap.js"></script> <script src="../vendors/minimap/Control.MiniMap.js" defer></script>
<script src="../vendors/csv2geojson/csv2geojson.js"></script> <script src="../vendors/csv2geojson/csv2geojson.js" defer></script>
<script src="../vendors/togeojson/togeojson.js"></script> <script src="../vendors/togeojson/togeojson.js" defer></script>
<script src="../vendors/osmtogeojson/osmtogeojson.js"></script> <script src="../vendors/osmtogeojson/osmtogeojson.js" defer></script>
<script src="../vendors/contextmenu/leaflet.contextmenu.js"></script> <script src="../vendors/contextmenu/leaflet.contextmenu.js" defer></script>
<script src="../vendors/loading/Control.Loading.js"></script> <script src="../vendors/loading/Control.Loading.js" defer></script>
<script src="../vendors/markercluster/leaflet.markercluster-src.js"></script> <script src="../vendors/markercluster/leaflet.markercluster-src.js" defer></script>
<script src="../vendors/photon/leaflet.photon.js"></script> <script src="../vendors/photon/leaflet.photon.js" defer></script>
<script src="../vendors/heat/leaflet-heat.js"></script> <script src="../vendors/heat/leaflet-heat.js" defer></script>
<script src="../vendors/fullscreen/Leaflet.fullscreen.js"></script> <script src="../vendors/fullscreen/Leaflet.fullscreen.js" defer></script>
<script src="../vendors/toolbar/leaflet.toolbar-src.js"></script> <script src="../vendors/toolbar/leaflet.toolbar-src.js" defer></script>
<script src="../vendors/formbuilder/Leaflet.FormBuilder.js"></script> <script src="../vendors/formbuilder/Leaflet.FormBuilder.js" defer></script>
<script src="../vendors/measurable/Leaflet.Measurable.js"></script> <script src="../vendors/measurable/Leaflet.Measurable.js" defer></script>
<script src="../vendors/iconlayers/iconLayers.js"></script> <script src="../vendors/locatecontrol/L.Control.Locate.js" defer></script>
<script src="../vendors/locatecontrol/L.Control.Locate.js"></script> <script src="../vendors/dompurify/purify.js" defer></script>
<script src="../vendors/dompurify/purify.js"></script> <script src="../vendors/togpx/togpx.js" defer></script>
<script src="../vendors/togpx/togpx.js"></script> <script src="../vendors/tokml/tokml.js" defer></script>
<script src="../vendors/tokml/tokml.js"></script> <script src="../vendors/simple-statistics/simple-statistics.min.js" defer></script>
<script src="../vendors/simple-statistics/simple-statistics.min.js"></script> <script src="../vendors/colorbrewer/colorbrewer.js" defer></script>
<script src="../vendors/colorbrewer/colorbrewer.js"></script> <script type="module" src="../js/modules/index.js" defer></script>
<script type="module" src="../js/modules/index.js"></script> <script src="../js/umap.core.js" defer></script>
<script src="../js/umap.core.js"></script> <script src="../js/umap.autocomplete.js" defer></script>
<script src="../js/umap.autocomplete.js"></script> <script src="../js/umap.popup.js" defer></script>
<script src="../js/umap.popup.js"></script> <script src="../js/umap.xhr.js" defer></script>
<script src="../js/umap.xhr.js"></script> <script src="../js/umap.forms.js" defer></script>
<script src="../js/umap.forms.js"></script> <script src="../js/umap.icon.js" defer></script>
<script src="../js/umap.icon.js"></script> <script src="../js/umap.features.js" defer></script>
<script src="../js/umap.features.js"></script> <script src="../js/umap.layer.js" defer></script>
<script src="../js/umap.layer.js"></script> <script src="../js/umap.controls.js" defer></script>
<script src="../js/umap.controls.js"></script> <script src="../js/umap.slideshow.js" defer></script>
<script src="../js/umap.slideshow.js"></script> <script src="../js/umap.tableeditor.js" defer></script>
<script src="../js/umap.tableeditor.js"></script> <script src="../js/umap.permissions.js" defer></script>
<script src="../js/umap.permissions.js"></script> <script src="../js/umap.datalayer.permissions.js" defer></script>
<script src="../js/umap.datalayer.permissions.js"></script> <script src="../js/umap.browser.js" defer></script>
<script src="../js/umap.browser.js"></script> <script src="../js/umap.importer.js" defer></script>
<script src="../js/umap.importer.js"></script> <script src="../js/umap.share.js" defer></script>
<script src="../js/umap.share.js"></script> <script src="../js/umap.js" defer></script>
<script src="../js/umap.js"></script> <script src="../js/umap.ui.js" defer></script>
<script src="../js/umap.ui.js"></script>
<link rel="stylesheet" href="../vendors/leaflet/leaflet.css" /> <link rel="stylesheet" href="../vendors/leaflet/leaflet.css" />
<link rel="stylesheet" href="../vendors/minimap/Control.MiniMap.css" /> <link rel="stylesheet" href="../vendors/minimap/Control.MiniMap.css" />
<link rel="stylesheet" href="../vendors/editinosm/Leaflet.EditInOSM.css" /> <link rel="stylesheet" href="../vendors/editinosm/Leaflet.EditInOSM.css" />

View file

@ -1,52 +1,52 @@
{% load compress %} {% load compress %}
{% compress js %} {% compress js %}
<script src="{{ STATIC_URL }}umap/vendors/leaflet/leaflet-src.js"></script> <script type="module" src="{{ STATIC_URL }}umap/js/modules/vendors.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editable/Path.Drag.js"></script> <script src="{{ STATIC_URL }}umap/vendors/editable/Path.Drag.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editable/Leaflet.Editable.js"></script> <script src="{{ STATIC_URL }}umap/vendors/editable/Leaflet.Editable.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/hash/leaflet-hash.js"></script> <script src="{{ STATIC_URL }}umap/vendors/hash/leaflet-hash.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/i18n/Leaflet.i18n.js"></script> <script src="{{ STATIC_URL }}umap/vendors/i18n/Leaflet.i18n.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/editinosm/Leaflet.EditInOSM.js"></script> <script src="{{ STATIC_URL }}umap/vendors/editinosm/Leaflet.EditInOSM.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/minimap/Control.MiniMap.js"></script> <script src="{{ STATIC_URL }}umap/vendors/minimap/Control.MiniMap.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/csv2geojson/csv2geojson.js"></script> <script src="{{ STATIC_URL }}umap/vendors/csv2geojson/csv2geojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/togeojson/togeojson.js"></script> <script src="{{ STATIC_URL }}umap/vendors/togeojson/togeojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/osmtogeojson/osmtogeojson.js"></script> <script src="{{ STATIC_URL }}umap/vendors/osmtogeojson/osmtogeojson.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/loading/Control.Loading.js"></script> <script src="{{ STATIC_URL }}umap/vendors/loading/Control.Loading.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/markercluster/leaflet.markercluster-src.js"></script> <script src="{{ STATIC_URL }}umap/vendors/markercluster/leaflet.markercluster-src.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/contextmenu/leaflet.contextmenu.js"></script> <script src="{{ STATIC_URL }}umap/vendors/contextmenu/leaflet.contextmenu.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/photon/leaflet.photon.js"></script> <script src="{{ STATIC_URL }}umap/vendors/photon/leaflet.photon.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js"></script> <script src="{{ STATIC_URL }}umap/vendors/georsstogeojson/GeoRSSToGeoJSON.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/heat/leaflet-heat.js"></script> <script src="{{ STATIC_URL }}umap/vendors/heat/leaflet-heat.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/fullscreen/Leaflet.fullscreen.js"></script> <script src="{{ STATIC_URL }}umap/vendors/fullscreen/Leaflet.fullscreen.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/toolbar/leaflet.toolbar-src.js"></script> <script src="{{ STATIC_URL }}umap/vendors/toolbar/leaflet.toolbar-src.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/formbuilder/Leaflet.FormBuilder.js"></script> <script src="{{ STATIC_URL }}umap/vendors/formbuilder/Leaflet.FormBuilder.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/measurable/Leaflet.Measurable.js"></script> <script src="{{ STATIC_URL }}umap/vendors/measurable/Leaflet.Measurable.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/iconlayers/iconLayers.js"></script> <script src="{{ STATIC_URL }}umap/vendors/togpx/togpx.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/togpx/togpx.js"></script> <script src="{{ STATIC_URL }}umap/vendors/iconlayers/iconLayers.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/tokml/tokml.js"></script> <script src="{{ STATIC_URL }}umap/vendors/tokml/tokml.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/locatecontrol/L.Control.Locate.js"></script> <script src="{{ STATIC_URL }}umap/vendors/locatecontrol/L.Control.Locate.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/dompurify/purify.js"></script> <script src="{{ STATIC_URL }}umap/vendors/dompurify/purify.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/colorbrewer/colorbrewer.js"></script> <script src="{{ STATIC_URL }}umap/vendors/colorbrewer/colorbrewer.js" defer></script>
<script src="{{ STATIC_URL }}umap/vendors/simple-statistics/simple-statistics.min.js"></script> <script src="{{ STATIC_URL }}umap/vendors/simple-statistics/simple-statistics.min.js" defer></script>
{% endcompress %} {% endcompress %}
{% if locale %}<script src="{{ STATIC_URL }}umap/locale/{{ locale }}.js"></script>{% endif %} {% if locale %}<script src="{{ STATIC_URL }}umap/locale/{{ locale }}.js" defer></script>{% endif %}
{% compress js %} {% compress js %}
<script type="module" src="{{ STATIC_URL }}umap/js/modules/index.js"></script> <script type="module" src="{{ STATIC_URL }}umap/js/modules/index.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.core.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.core.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.autocomplete.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.autocomplete.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.popup.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.popup.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.xhr.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.xhr.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.forms.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.forms.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.icon.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.icon.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.features.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.features.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.permissions.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.permissions.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.datalayer.permissions.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.datalayer.permissions.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.layer.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.layer.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.controls.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.controls.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.slideshow.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.slideshow.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.tableeditor.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.tableeditor.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.browser.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.browser.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.importer.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.importer.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.share.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.share.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.js" defer></script>
<script src="{{ STATIC_URL }}umap/js/umap.ui.js"></script> <script src="{{ STATIC_URL }}umap/js/umap.ui.js" defer></script>
{% endcompress %} {% endcompress %}