0

so I have some awesome basemap raster layers that use L.TileLayer to load, but the GeoJSON I have for my country polygons is all Web Mercator. My tile map is WGS84 or EPSG4326 (I think).

But I couldn't figure it out... I tried loading the "conversion methods" in Leaflet documentation, but couldn't figure out how to use it for pointToLayer() or coordsToLatLng() functions that are available as options on L.GeoJSON. I kept getting 'function not found' for static conversion methods. If they're static, they should be available but it means that I'm not doing this the proper way.

Using ES6 Leaflet:

let countryLayer = L.geoJSON(this.countriesGeoJson, {
          onEachFeature: function(feature, layer) {} });

Why is sample code so difficult to find for projecting to a different coordinate system? Obviously the "crs" option on Leaflet doesn't work because my GeoJSON is generated from the wrong map (was generated with Web Mercator projection) and there seems to be no easy way to convert.

I was trying to find a way without downloading a plugin like Proj4Leaflet ,but is that the only way??

  • Strictly, latest version of GeoJSON has only one projection WGS84 with coordinates in lon/lat order (aka CRS:84), so that's not EPSG:4326 which is WGS84 with coordinates in lat lon order. – nmtoken Mar 16 at 9:16
  • You could use Per Liedman's reproject (haven't tried it myself): github.com/perliedman/reproject – TomazicM Mar 16 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.