I am trying to update a map that is using leaflet. I want to add a geo search bar. For that I installed this extension
geoportal-extensions-leaflet@2.2.2
Now I tried to run this code in the JS.
var searchCtrl = L.geoportalControl.SearchEngine({});
this.map.addControl(searchCtrl);
TypeError: L.geoportalControl is undefined
L is refering to :
const L = require('leaflet');
So now my question is : Does this error means I should do an other "require" for the leaflet geo-portal extensions ? Or does this means that I have installed the extension wrongly or that I did an other mistake ? Edit : I was misunderstanding how to import the library because I had only tried in online tools like codepen in which imports are different.
What needs to be done is import both leaflet and geoportal-extensions-leaflet.
After the
npm i geoportal-extensions-leaflet
The source of the extention is present inside
node_modules/geoportal-extensions-leaflet
The library should be imported in the JS using :
const Gp = require('geoportal-extensions-leaflet');
And this code will now works but we should refer to Gp in order to access to the geoportal-extensions-leaflet :
var searchCtrl = Gp.geoportalControl.SearchEngine({});
this.map.addControl(searchCtrl);