[OpenLayers-Users] projection in openlayers
maven apache
apachemaven0 at gmail.com
Thu Sep 4 00:52:53 PDT 2014
Hi:
I am using openlayers 2.13.1, and I meet some problems when dealing with
the projection.
1 Change the projection on the fly.
Say I have to baselayers:
var osm=new OpenLayers.Layer.OSM(); // whose projection is "EPSG:900913"
var l4326=new Custome4326Layer(); // whose projection is "EPSG:4326"
Now I want to switch between the two base layers.
But it seems that ol does not support this out of the box. so I do some
fix job:
var setBaseLayer = ol.Map.prototype.setBaseLayer;
ol.Map.prototype.setBaseLayer = function (baseLayer) {
var oldProjection = new ol.Projection(this.projection);
var newProjection = baseLayer.projection;
var oldZoom = this.getZoom();
var oldCenter = this.getCenter();
setBaseLayer.apply(this, arguments);
if (newProjection) {
this.projection = newProjection.getCode();
this.maxExtent = baseLayer.maxExtent;
this.maxResolution = baseLayer.maxResolution;
this.resolutions = baseLayer.resolutions;
}
if (!newProjection.equals(oldProjection) && oldCenter) {
var newCenter = oldCenter.transform(oldProjection, newProjection);
this.setCenter(newCenter, oldZoom);
}
}
It seems this works, when I change to another projection, the new tiles
will be loaded correctly at least.
But the vector data are not re-projected. For example, when the `osm` is
the baselayer, and I add a marker to the map, when I change to `l4326`, the
marker will disappeared since its location is not re-projected.
So is the instances of `Feature.Vector` and etc. Of course, I can hold the
reference to each feature,marker added to the map, and re-project them
manually,but I wonder if there is a better choice.
2 Add custom project
We have tiles with projection neither 4326 or 3857, so we can not use the
internal projection transformation out of box, however I do not find
anything about create custom projection and register the related transform
methods.
All I found is something like:
var pro=new ol.Projection("EPSG:4326")
which can not meet my requirements.
Did I miss anything?
Yang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20140904/d78126a2/attachment.html>
More information about the Users
mailing list