Friday, 25 January 2019

Using Proj4js in Openlayers - Proj4js is not defined



I want to use Proj4js.


    




I get a javascript error: ReferenceError: Proj4js is not defined. When I look at the source specified at /cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4-src.js, I do not see any specification of an object called Proj4js having a property defs. Still, that is what the tutorials are saying (like http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example).


What do I do wrong?



Answer



You have two choices


Solution 1:


You can change the reference to proj4js. OpenLayers 2.x default support is with Proj4js 1.1 whereas you use 2.x.















Demo 1 (open the browser console to see)


Solution 2:


Or you can use the new proj4js version by adding a wrapper to match previous version behaviour:














Demo 2 (open the browser console to see)


You may encounter some border effects although it seems minor according to the thread about OpenLayers 2.x support with Proj4js 2.x series


There was small difference between both results but now it's OK. It was due to parameters correction with proj4js for this particular projection (EPSG:31466).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...