kartena / Proj4Leaflet

Smooth Proj4js integration with Leaflet.
http://kartena.github.io/Proj4Leaflet/
BSD 2-Clause "Simplified" License
589 stars 173 forks source link

Cannot add proj4.defs in a node environment (browserify) #79

Closed Casen closed 9 years ago

Casen commented 9 years ago

Not much more to say than that. Proj4leaflet requires proj4 internally, passing it to a factory function. This prevents a user from defining a new projection somewhere down in their code. Perhaps we could add "defs" to the proj4leaflet api?

perliedman commented 9 years ago

Proj4's defs dictionary should be shared throughout the app, so as long as you get the requirement ordering correct, using defs should work - as long as you use one Proj4 version throughout your code (which seems like a sensible thing to do anyway). Or am I missing some detail?

You can also provide a proj4 object to L.Proj.CRS's constructor, and avoid using defs altogether, if that makes it easier.

rob-murray commented 9 years ago

Yes, this works fine with Browserify, maybe something like

require('proj4leaflet')
proj4 = require('proj4')
proj4.defs({your crs})

As mentioned, check there is only one proj4 in your browserified output and/or npm dedupe.

perliedman commented 9 years ago

@rob-murray yes, good advice. Thanks for sharing!