nextzen / nextzen.js

Javascript SDK for Mapzen products
ISC License
84 stars 43 forks source link

mapzen.js doesn't load with requirejs #382

Open marianoguerra opened 7 years ago

marianoguerra commented 7 years ago

here's a minimal example:

http://marianoguerra.github.io/bugs/mapzen-requirejs/

you can see the code here:

https://github.com/marianoguerra/marianoguerra.github.io/blob/master/bugs/mapzen-requirejs/app.js

looking at the code in mapzen.js you call define(['leaflet'], factory) in line 1236 but leaflet is defined in line 1836 as define(L) (which I think it should be define('leaflet', L))

I tried using mapzen.standalone.min.js instead and loading my leaflet:

https://github.com/marianoguerra/marianoguerra.github.io/blob/master/bugs/mapzen-requirejs/app.standalone.js

but as you can see here, it complains that "ReferenceError: Tangram is not defined":

http://marianoguerra.github.io/bugs/mapzen-requirejs/standalone.html

reading the code, I passed _useTangram: false in options but then it renders a gray map and never request the tiles.

my code was working with leaflet and osm tiles, can I set mapzen tiles url template, api key and attribution directly on leaflet? is there something else I have to do?

marianoguerra commented 7 years ago

this line seems to assume that _importScript will register Tangram in the global scope:

https://github.com/mapzen/mapzen.js/blob/master/src/js/components/tangram.js#L61

but with requirejs it doesn't, I did another example where I load tangram before and put it in the global scope here:

http://marianoguerra.github.io/bugs/mapzen-requirejs/standalone-manual-tangram.html

code here https://github.com/marianoguerra/marianoguerra.github.io/blob/master/bugs/mapzen-requirejs/app.standalone.manual.tangram.js

marianoguerra commented 7 years ago

now I did the standalone.manual.tangram thing and it works during development but on production in firefox (nightly) it fails, it seems to be because of this: https://github.com/tangrams/tangram/issues/252

Tangram v0.12.4 [error]: Scene.load() failed to load https://mapzen.com/carto/bubble-wrap-style-more-labels/7/bubble-wrap-style-more-labels.zip: There was a network error[object ProgressEvent] Error: There was a network error[object ProgressEvent]
rfriberg commented 7 years ago

Hi @marianoguerra - thanks for the report.

That Tangram issue you pointed to has long been a blocker for bundling Tangram within mapzen.js. But we're now close to being able to import Tangram as a node module and require it in a way that will work with your examples.

At the moment, you can load your own versions of leaflet and Tangram - tangrams/tangram-frame currently does this. But keep in mind that if you go this route, Leaflet and Tangram should be considered dependencies of mapzen.js. I believe explicit dependencies can be set in requirejs by using the shim config.