3

This question already has an answer here:

Given a GeoJSON in EPSG3857:

{
  "type": "Feature",
  "properties": {},
  "geometry": {
    "type": "LineString",
    "coordinates": [
      [
        -13720479.997764934,
        5688254.733325758
      ],
      [
        -13720479.47473932,
        5688241.794717406
      ]
    ]
  }
}

I am trying to convert the GeoJSON to EPSG 4326 for a Leaflet map. The user input in the map comes in EPSG 3857. I want to do the conversion with JavaScript after the user enters the GeoJSON. So I am looking for a JavaScript library that I can use. I am not looking for tools with whom I can convert the GeoJSON outside of my script (like GDAL/OGR) .

I tried Proj4 but didn't get it to work. Is it possible to use Proj4 to convert line strings? If not, what other options should I consider?

var epsg4326 = new Proj4js.Proj('EPSG:4326');
var epsg3857 = new Proj4js.Proj('EPSG:3857');

var geoJSONOBJ4 = new Proj4js.Point(geoJSONOBJ3);
Proj4js.transform(epsg4326,epsg3857,geoJSONOBJ4);

marked as duplicate by Devdatta Tengshe, BradHards, PolyGeo, Fezter, Curlew Jan 8 '14 at 9:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Which client map library do you use? Willing to to this with pure javascript objects? Map libraries usually have helpers to do this. – cavila Jan 7 '14 at 23:45
  • I use mapbox.js. I am open for all kinds of solutions. – ustroetz Jan 7 '14 at 23:46
1

If using Leaflet, try the Proj4Leaflet plugin:

https://github.com/kartena/Proj4Leaflet

Proj4Leaflet also adds support for GeoJSON in any projection, while Leaflet by itself assumes GeoJSON to always use WGS84 as its projection.

  • Could you please add some more explanation or some code on how exactly I could use that plugin. – ustroetz Jan 8 '14 at 3:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.