OpenLayers – Why is My Shapefile Not Loading?

coordinate systemjavascriptopenlayers-2shapefile

This is my website for test: http://www.cv.nctu.edu.tw/tonywang/shapefile-js-openlayers/ol_simple.html

I want to put my Shapefile in OpenLayers. I found an example at https://github.com/mattwigway/shapefile-js/tree/openlayers

I tried it and put my Shapefile in OpenLayers using proj4 to convert EPSG:3826 (my Shapefile's projection is EPSG:3826) to EPSG:4326.

But, I can't see my Shapefile on the OpenLayers map. What's wrong?

Best Answer

If you look at the picture below, you'll see your Shapefile is actually being displayed on the map. But it's not being projected to your map's reference system.

enter image description here

Your Shapefile has EPSG:4326 (as you can see here) and your map has EPSG:900913. So, in your ol_simple.js file, change line:

var outProj = new OpenLayers.Projection('EPSG:3857');

by:

var outProj = map.getProjectionObject();

And that should do the trick. Your Shapefile should be located where it is expected to.

enter image description here