sparna-git / Sparnatural

Sparnatural : Typescript visual SPARQL query builder for knowledge graphs, configurable with SHACL
http://sparnatural.eu
GNU Lesser General Public License v3.0
206 stars 34 forks source link

Map widget : use dynamic import for leaflet to avoid overriding the leaftlet from sparnatural-yasgui-plugin if it is imported first #584

Open tfrancart opened 2 months ago

tfrancart commented 2 months ago

This kind of thing:

// /!\ black magic warning : dynamic leaflet import
// to avoid importing it twice in the page
var L:typeof import("leaflet/index");
var markerIcon;
if(window.L == undefined) {
    import("leaflet").then((theLeaflet) => {
        L = theLeaflet;
        window.L = L;
        import('leaflet.markercluster');
        markerIcon = L.icon( {
            iconUrl:require("leaflet/dist/images/marker-icon.png"),
            shadowUrl: require("leaflet/dist/images/marker-shadow.png")
        } );
    });
} else {
    L = window.L;
    import('leaflet.markercluster');
    markerIcon = L.icon( {
        iconUrl:require("leaflet/dist/images/marker-icon.png"),
        shadowUrl: require("leaflet/dist/images/marker-shadow.png")
    } );
}
// /!\ end blackmagic