VOL3 / v-ol3

Vaadin OpenLayers 3 wrapper
Apache License 2.0
15 stars 18 forks source link

Implement projection system #23

Closed Styp closed 9 years ago

Styp commented 9 years ago

Matthi, There is not much projection system implemented. I would appreciate it if you could implement it... :+1:

viliam-durina commented 9 years ago

You might find this useful:

public static OLCoordinate toWebMercator(double gpsLat, double gpsLng) {
    if ((Math.abs(lng) > 180 || Math.abs(lat) > 90))
        return new OLCoordinate(0, 0);

    double num = lng * 0.017453292519943295;
    double x = 6378137.0 * num;
    double a = lat * 0.017453292519943295;

    double mercatorX_lon = x;
    double mercatorY_lat = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));

    return new OLCoordinate(mercatorX_lon, mercatorY_lat);
}
mhosio commented 9 years ago

Thanks! In deed there is no support for projection transformations at the server side. Basically the only thing you can do is to set input projection for the view. Maybe I should include some third party library for doing the most typical conversions at the server side.

-Matti

On Mon, Apr 27, 2015 at 3:42 PM, viliam-durina notifications@github.com wrote:

You might find this useful:

public static OLCoordinate toWebMercator(double gpsLat, double gpsLng) { if ((Math.abs(lng) > 180 || Math.abs(lat) > 90)) return new OLCoordinate(0, 0);

double num = lng * 0.017453292519943295;
double x = 6378137.0 * num;
double a = lat * 0.017453292519943295;

double mercatorX_lon = x;
double mercatorY_lat = 3189068.5 * Math.log((1.0 + Math.sin(a)) / (1.0 - Math.sin(a)));

return new OLCoordinate(mercatorX_lon, mercatorY_lat);

}

— Reply to this email directly or view it on GitHub https://github.com/VOL3/v-ol3/issues/23#issuecomment-96635796.

Styp commented 9 years ago

Matti, I would suggest Proj4J... http://trac.osgeo.org/proj4j/

WebMercator is just one projection. But I would like to see more than just the WGS84 -> Mercator problem solved... Lets to this 'generic' so we keep flexibility...

mhosio commented 9 years ago

I added a bit more (re)projection support for the add-on. Now you should be able to use basemaps in various projections supported by proj4js library. Also you can add feature vectors in any projection supported by proj4js. See the org.vaadin.addon.vol3.demoandtestapp. Proj4jsMap demo in the test folder for usage.

I decided not to bundle the proj4js or proj4j with the add-on at this point. You can easily include those in your application in case you need additional projections.