kartena / Proj4Leaflet

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

Breaking issue in proj4js >= 2.4.x #139

Closed per-frojdh closed 7 years ago

per-frojdh commented 7 years ago

In version >= 2.4.x of proj4s, the ways of exporting the proj4js library has changed from a more CommonJS-familiar way into a different way (I'm not too familiar with the exact consequences).

The proj4leaflet way of requiring proj4 through

proj4 = require('proj4')

now results in an ES6-module like this:

proj4 = require('proj4')
{
  __esModule: true,
  default: proj4,
}

This is due to the way that proj4js (2.4.x) is exported as an ES6-module.

For now, this can be fixed by changing the version of proj4js that proj4leaflet uses to stay in the 2.3.x range.

perliedman commented 7 years ago

Hm, there seems to be some missing context here. I successfully ran the tests with proj4 2.4.3:

per@angus:~/Documents/Projects/Proj4Leaflet$ npm install proj4@latest
proj4leaflet@1.0.1 /home/per/Documents/Projects/Proj4Leaflet
└── proj4@2.4.3 

per@angus:~/Documents/Projects/Proj4Leaflet$ npm t

> proj4leaflet@1.0.1 test /home/per/Documents/Projects/Proj4Leaflet
> mocha-phantomjs test/mocha.html

  L.Proj.Projection
    ✓ can create an instance from a SRS code and proj4 def

  L.Proj.CRS
    ✓ can create an instance from a SRS code and proj4 def
    ✓ can project a coordinate to a point in the defined SRS
    ✓ has a default transformation that is [1, 0, -1, 0]
    ✓ uses provided zoom level scales
    ✓ uses provided zoom level resolutions
    ✓ uses provided origin
    ✓ accepts custom transformation
    ✓ size from bounds
    ✓ converts zoom to scale and vice versa and returns the same values
    ✓ converts scale to zoom and returns Infinity if the scale passed in is bigger than maximum scale
    ✓ tests that distance works (L.CRS.Earth.Distance)

  12 passing (69ms)

Also, requiring in proj4 looks as expected:

per@angus:~/Documents/Projects/Proj4Leaflet$ node 
> require('proj4')
{ [Function: proj4$1]
  defaultDatum: 'WGS84',
  Proj: 
   { [Function: Projection$1]
     projections: 
      { start: [Function: start],
        add: [Function: add],
        get: [Function: get] } },
  WGS84: 

[...]

Just to be sure, I also browserified the following program and ran in the browser:

var proj4 = require('proj4');

console.log(proj4(proj4.defs['GOOGLE']).forward([11.9, 57.7]));

It works as I would expect.

So, any particular node version or something that could explain the issue you're seeing?

perliedman commented 7 years ago

Also verified with this program through browserify, using proj4leaflet 1.0.1 and proj4 2.4.3:

var L = require('leaflet');
var p4l = require('proj4leaflet');

var crs = new L.Proj.CRS('EPSG:3857', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext  +no_defs');

console.log(crs.project(L.latLng(11.9, 57.7)));

...which also works as expected, double checked at runtime that proj4.version is indeed 2.4.3.

per-frojdh commented 7 years ago

Apologies, I was being a bit vague in my opening issue. After doing some further digging it turns out this issue belongs with webpack, and the way it interprets exports/imports, so the issue does not lie with either proj4 or proj4leaflet.

Sorry for the inconvenience!