Based on examples from:



I have managed to create simple editor, which pastes me created vectors to the textarea and then I created buttons, which downloads this GeoJSON string in a file.

I don't know why, but my app still gives me created vectors in EPSG:3857 instead of EPSG:4326 and it doesn't care that I defined EPSG to 4326 in both vectorLayer and for View.

var vectorLayer = new ol.layer.Vector({
            source: new ol.source.StaticVector({
                format: format,
                **projection: 'EPSG:3857'**


var map = new ol.Map({
  view: new ol.View({
    **projection: 'EPSG:4326',**

The problem is, that common user isn't clever enough to work with GeoJSON (download, open in QGIS, set up EPSG:3857 and save as EPSG:4326 in some other format), so I decided to create second button (for downloading) and defined var format = new ol.format.KML(); which is easy to use (double click opens and shows it in Google Earth), but this is not possible, because this works only with WGS84 coordinates in that KML file and not with other systems.

Is there (in OpenLayers) any possibility to easily create new duplicate layer with different coordinate system (geometry will be reprojected and I can just export)?

For example something like this could be nice:

var DuplicateWithDifferentEPSG = ol.proj.transformVectorlayer(vectorlayer, 'EPSG:3857', 'EPSG:4326')

How to simply reproject everything in my layer?

Any ideas?

Should I post exact copy of my code?

I don't get any errors.

1 Answer 1


I am not totally sure if I understand what you want to do. But when calling writeFeatures on a format, you can specify the dataProjection (the projection you want to have in your output format) and the featureProjection (the projection of your features that you want to export). See ol.format.GeoJSON.writeFeatures.

So for example if your features are in 'EPSG:4326' and you want to have a GeoJSON in 'EPSG:3857', you would do:

var geoJson3857 = new ol.format.GeoJSON.writeFeatures(features4326, {
  dataProjection: 'EPSG:3857',
  featureProjection: 'EPSG:4326'
  • That is exactly what I wanted to do. I wasnt able to find it myself... I had my coordinates in 3857 and so I converted them this way to 4326 and exported to KML, which can be easily opened in GoogleEarth and it automaticaly shows correct position of my vectors. Thanks.
    – dkocich
    Feb 22, 2015 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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