2

I am trying to implement support for multiple projections in qgis2web. I believe that the correct approach would be to export the QGIS layers to EPSG:4326 geoJSON. I've implemented that.

However, I cannot get the points to display on the EPSG:3857 OL3 map. I've looked through the OL3 API, and I've only found that under ol.format.GeoJSON, the option defaultDataProjection exists. It's not clear to me whether I should set this to the JSON's projection 4326 or the map's 3857. I've tried both, but the points still do not appear.

A sample qgis2web OL3 map is here: https://www.dropbox.com/s/nyjvn8s0w14a04j/ol3map.zip?dl=0. Can anyone help me figure this out? What am I missing?

UPDATE: I might have figured this out. In the dropboxed code /layers/layers.js line 5, adding {dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857'} as the second argument to readFeatures might have done the job. Will confirm or deny after testing.

3

Yes, the answer is to add a second argument to ol.format.GeoJSON().readFeatures(): {dataProjection: 'EPSG:4326', featureProjection: 'EPSG:3857'}. That makes 4326 JSON work in a default (3857) OL3 map. Will ask a different question about other projections, which I still can't get to work.

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.