0

qgis2web is a plugin for QGIS which creates webmaps. This question is about its OpenLayers 3 export. It exports QGIS layers to geoJSON to pull into the OL3 map. It writes them in EPSG:4326, as I believe this is at least a proposed standard for geoJSON. This works for default (EPSG:3857) OL3 maps.

However, I am trying to implement support for multiple projections in qgis2web. I cannot get the geoJSON EPSG:4326 points to display on the OL3 map if it uses any projection other than EPSG:3857.

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

2
  • Could you please post the html code that was generated by qgis2web?
    – Alexis_A
    Dec 7, 2015 at 18:31
  • It's the Dropbox zip. The output is structured in several files and folders. However, I'll try to pull out the relevant bits and paste them in. Dec 7, 2015 at 19:05

1 Answer 1

3

I didn't investigate all, but changing scripts loading order is already better: something is now visible.

I just replaced

<script src="./resources/ol.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>

with

<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
<script type="text/javascript">
  proj4.defs('EPSG:27700','+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs');
</script>
<script src="./resources/ol.js"></script>

It seems you missed that you need to load proj4js, then declare projections before any OpenLayers script whereas you were already calling your custom projection before declaring it.

4
  • +1 exacly the same and standardize relative path: ="./*" or delete all ./ Dec 7, 2015 at 19:22
  • Completely correct, and splendidly simple. Thanks very much @ThomasG77. Dec 7, 2015 at 19:34
  • Code is inherited from multiple authors @GeoStoneMarten, so standardization is definitely not complete - point taken. Dec 7, 2015 at 19:35
  • @TomChadwin no problem. This is just an information to get clean code Dec 7, 2015 at 19:51

Your Answer

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

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