OL 2.13.1 + latest Proj4js (?)

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

OL 2.13.1 + latest Proj4js (?)

Andrea Battisti
Hello,

Looks like that the latest version of Proj4js from:
https://github.com/proj4js/proj4js

has a slightly different API then before, and indeed it does not seem to
work with the plain OL 2.13.1.

Question: is there a patch available to use OL against the new Proj4js?
If not, which is the best way to make it compatible?

As far as I see the code to adapt will be the OpenLayers.Projection
class in Projection.js; is that enough? are there other changes needed
from the OL perspective?


Thanks in advance!
--
Ing. Andrea Battisti
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: OL 2.13.1 + latest Proj4js (?)

Andreas Hocevar-4
Hey,

You'll have to add the following wrapper before you load projections from spatialreference.org and before you load OpenLayers.js:

    <script>
        window.Proj4js = {
            Proj: function(code) { return proj4(Proj4js.defs[code]); },
            defs: proj4.defs,
            transform: proj4
        };
    </script>

This is all.

Andreas.


On Thu, Oct 3, 2013 at 7:28 AM, Andrea Battisti <[hidden email]> wrote:
Hello,

Looks like that the latest version of Proj4js from:
https://github.com/proj4js/proj4js

has a slightly different API then before, and indeed it does not seem to work with the plain OL 2.13.1.

Question: is there a patch available to use OL against the new Proj4js?
If not, which is the best way to make it compatible?

As far as I see the code to adapt will be the OpenLayers.Projection class in Projection.js; is that enough? are there other changes needed from the OL perspective?


Thanks in advance!
--
Ing. Andrea Battisti
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev


_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: OL 2.13.1 + latest Proj4js (?)

Andrea Battisti
Il 03/10/13 21.11, Andreas Hocevar ha scritto:

> Hey,
>
> You'll have to add the following wrapper before you load projections
> from spatialreference.org <http://spatialreference.org> and before you
> load OpenLayers.js:
>
>      <script>
>          window.Proj4js = {
>              Proj: function(code) { return proj4(Proj4js.defs[code]); },
>              defs: proj4.defs,
>              transform: proj4
>          };
>      </script>
>
> This is all.
>
>

Andreas,

thanks for the quick reply, the above wrapper helps!

Just for the record for who might be interested, I noticed that the
internal projection object
(as returned by: OpenLayers.Map.getProjectionObject().proj) has changed
as well, so any code that was accessing its properties should be adapted.

--
Ing. Andrea Battisti

_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: OL 2.13.1 + latest Proj4js (?)

kevint
In reply to this post by Andreas Hocevar-4
In addition to the wrapper, I had to overwrite the Projection getCode function:

<script>
OpenLayers.Projection.prototype.getCode = function() {
    return this.proj ? this.proj.oProj.srsCode : this.projCode;
};
</script>

instead of "return this.proj ? this.proj.srsCode : this.projCode;", or else was having problems with this line in OpenLayers.Layer.ArcGIS93Rest.getURL:

var projWords = this.projection.getCode().split(":");



Andreas Hocevar-4 wrote
Hey, You'll have to add the following wrapper before you load projections from spatialreference.org and before you load OpenLayers.js: <script> window.Proj4js = { Proj: function(code) { return proj4(Proj4js.defs[code]); }, defs: proj4.defs, transform: proj4 }; </script> This is all. Andreas.