cvalenzuela / Mappa

A canvas wrapper for Maps 🗺 🌍
https://mappa.js.org
359 stars 104 forks source link

this.scriptTag is undefined #22

Open sirrah23 opened 5 years ago

sirrah23 commented 5 years ago

I get the error message this.scriptTag is undefined and a blank Mappa canvas when I build my code to get it ready for deployment for a project that I am working on. My code is instantiating a Mappa object via the Leaflet provider and the error message appears when I call the overlay method on said object using an existing canvas as the argument.

After some tracing and print-debugging I found the following in Mappa/src/providers/tile/Leaflet.js:

if (this.constructor.name === 'Leaflet') {
    this.loadSrc();
}

The project that I am working on is using the Vue.js framework and it uses the vue-cli's build command to minify/uglify the code. As a part of this process classes get renamed to single character variants and so this.constructor.name no longer equals Leaflet (in my case it became the single character t) which causes this.loadSrc() to not run. Because of this the scriptTag property is not getting defined thus leading to the the error that I see.

I took a look at the code for the other tile-based providers and I can't see a reason for this check to be here, I don't think we need. Once the check is removed the issue that I've observed will get resolved as well.

54M5M17H commented 5 years ago

I’ve been experiencing the same issue when building with webpack, as part of a Vanilla JS application.