1

I need to solve two problems:

  1. convert my coordinates from wgs84 to epsg28992
  2. use external geojson from an jsonp url

Both problems are as far as I understand not supported by Leaflet itself. So I took a deep dive to found alternative methods.

The content of the jsonp looks like:

getmyjson({"type":"FeatureCollection","features":[
 { "type":"Feature",
   "properties":{"waarde":72.000000, "code":"002002", "klasse":1, "aant_min_stap":0, "stapgrootte":50.000000, "aant_stappen":4},
   "geometry":{"type":"Point", "coordinates":[129544.434902 , 512753.813614]}
 },
.....
 { "type":"Feature",
   "properties":{"waarde":54.000000, "code":"BDV032", "klasse":1},
   "geometry":{"type":"Point", "coordinates":[117763.299998 , 503647.849492]}
 }
]});

The first problem (convert coordinates) I solved by using jquery: Result

relevant code:

function getmyjson(data) {
      geojsonLayer.addData(data);
 }

 $.getJSON("rdtest.json", function(data) {
    var geojsonLayer = L.geoJson(data, {
      pointToLayer: function (feature, latlng) {
        latlngnw=RdWgs84(latlng.lng,latlng.lat)
    return L.circleMarker(latlngnw,{})
      }
    });
    geojsonLayer.addTo(map);
  });

The second problem (use external jsonp) I solved by using the plugin leaflet-ajax: Result

relevant code:

function getmyjson(data) {
      geojsonLayer.addData(data);
      geojsonLayer.addTo(map);
 }

 var geojsonLayer = new L.GeoJSON.AJAX(["wgs84test.jsonp"], {
      dataType:"jsonp",
      callbackParam:"getmyjson",
      });

What I want now is to combine both solutions and I have no clue how to do that.

Can anyone help me out ?


From ThomasG77 this is the solution to combine 1. and 2. Result

function getmyjson(data) {
   geojsonLayer.addData(data);
   geojsonLayer.addTo(mymap);

}

var geojsonLayer = new L.GeoJSON.AJAX(["rdtest.jsonp"], {
    dataType:"jsonp",
    callbackParam:"getmyjson",
    pointToLayer: function (feature, latlng) {
    latlngnw=RdWgs84(latlng.lng,latlng.lat)
    return L.circleMarker(latlngnw,{})
      }

});

But I will tweak further to look if I can use Proj4Leaflet to solve it.


Alternative for point 1 with use of Proj4Leaflet. Result

proj4.defs("EPSG:28992","+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs");
  $.getJSON("rdtest.json", function(data) {

    data.crs={
       "type": "name",
       "properties": {"name": "urn:ogc:def:crs:EPSG::28992"}
    };
    L.Proj.geoJson(data).addTo(map);
  });

Remaining question now is how I can combine the solutions of point 2 (jsonp) and the above.

Any suggestions ?


Final solution. Result

proj4.defs("EPSG:28992","+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725 +units=m +no_defs");

function getmyjson(data) {
   geojsonLayer.addData(data);
   geojsonLayer.addTo(mymap);
}

var geojsonLayer = new L.GeoJSON.AJAX(["rdtest.jsonp"], {
    dataType:"jsonp",
    callbackParam:"getmyjson",
    pointToLayer: function (data) {
          data.crs={
            "type": "name",
            "properties": {"name": "urn:ogc:def:crs:EPSG::28992"}
      };
    return L.Proj.geoJson(data)
        }
});
1

Point 1

For conversion, other answer already mentioned Proj4Leaflet (it relies on Proj4js) For your particular projection, EPSG 28992, look at this EPSG.io URL

Point 2

For the JSONP, read again the Leaflet-ajax page.

At the bottom, the doc mentioned below syntax where you can use JSONP with a custom function (and your case, make your coordinates transformation)

L.Util.jsonp("http://www.dif.ori/gin").then(function(data){
    doStuff(data);
});
3
  • Thanks. I tweaked around with that (jsonp) option, but did not succeed (sofar). I will post the tweak I tried later on.
    – waterbug
    Oct 2 '15 at 12:29
  • I tweaked around again I was success full this time. Thanks for putting me on the right track. I tried to higher your score, but looks like I am not allowed yet (not enough reputation ?). I edited my question with the right solution to point 2
    – waterbug
    Oct 2 '15 at 16:47
  • I read in the help 'The person who asked can mark one answer as "accepted" '. I would like to mark your answer as accepted but don' see how to do. Maybe I miss something or maybe I don't have enough reputation for that.
    – waterbug
    Oct 2 '15 at 22:35
0

With modern proj4Leaflet you should be able to define the projections by using proj4 strings, as demonstrated in https://kartena.github.io/Proj4Leaflet/ by (re-)defining EPSG:3006.

You can do the same by doing something like:

var crs = new L.Proj.CRS('EPSG:28992',
  '+proj=sterea +lat_0=52.15616055555555 +lon_0=5.38763888888889 +k=0.9999079 +x_0=155000 +y_0=463000 +ellps=bessel +towgs84=565.4171,50.3319,465.5524,-0.398957388243134,0.343987817378283,-1.87740163998045,4.0725 +units=m +no_defs',
  {
    resolutions: [
      8192, 4096, 2048, 1024, 512, 256, 128
    ],
    origin: [0, 0]
  })
1
  • great, I missed this. I will dive into this again. Will come back on that.
    – waterbug
    Oct 2 '15 at 11:17
-1

Sorry, no complete answer, but for Leaflet-side reprojection, have a look at Proj4Leaflet

2
  • Thanks. I tried something with proj4leaflet already, but I stopped after I got signals it is not supporting epsg28992: drupal.org/node/2330145 If that is not correct please let me know.
    – waterbug
    Oct 2 '15 at 9:49
  • I am now using my 'own' function RdWgs84 to make the converts, but I realize it is suboptimal. Better alternatives are welcome.
    – waterbug
    Oct 2 '15 at 10:11

Your Answer

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

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