<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi:</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">


I am using openlayers 2.13.1, and  I meet some problems when dealing with the projection.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">


1 Change the projection on the fly.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Say I have to baselayers:</div>


<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">var osm=new OpenLayers.Layer.OSM();  // whose projection is <span style="font-family:arial">"EPSG:900913"</span></div>


<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial">var l4326=new Custome4326Layer();  </span>// whose projection is <span style="font-family:arial">"EPSG:4326"</span></div>


<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial">Now I want to switch between the two base layers.</span></div>


<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial"><br></span></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial">But it seems that ol does not support this out of the box. so  I do some fix job:</span></div>


<div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:arial"><br></span></div><div class="gmail_default"><div class="gmail_default">var setBaseLayer = ol.Map.prototype.setBaseLayer;</div>


<div class="gmail_default">ol.Map.prototype.setBaseLayer = function (baseLayer) {</div><div class="gmail_default">    var oldProjection = new ol.Projection(this.projection);</div><div class="gmail_default">
    var newProjection = baseLayer.projection;</div><div class="gmail_default"><br></div><div class="gmail_default">    var oldZoom = this.getZoom();</div><div class="gmail_default">    var oldCenter = this.getCenter();</div>


<div class="gmail_default">    setBaseLayer.apply(this, arguments);</div><div class="gmail_default">    if (newProjection) {</div><div class="gmail_default">        this.projection = newProjection.getCode();</div>
<div class="gmail_default">        this.maxExtent = baseLayer.maxExtent;</div><div class="gmail_default">        this.maxResolution = baseLayer.maxResolution;</div><div class="gmail_default">        this.resolutions = baseLayer.resolutions;</div>


<div class="gmail_default">    }</div><div class="gmail_default">    if (!newProjection.equals(oldProjection) && oldCenter) {</div><div class="gmail_default">        var newCenter = oldCenter.transform(oldProjection, newProjection);</div>


<div class="gmail_default">        this.setCenter(newCenter, oldZoom);</div><div class="gmail_default">    }</div><div class="gmail_default">}</div><div class="gmail_default"><br></div><div class="gmail_default">
It seems this works, when I change to another projection, the new tiles will be loaded correctly at least.</div><div class="gmail_default"><br></div><div class="gmail_default">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. </div>


<div class="gmail_default"><br></div><div class="gmail_default">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.</div>


<div class="gmail_default"><br></div><div class="gmail_default"><br></div><div class="gmail_default">2 Add custom project</div><div class="gmail_default"><br></div><div class="gmail_default">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.</div>

<div class="gmail_default"><br></div><div class="gmail_default">All I found is something like:</div><div class="gmail_default"><br></div><div class="gmail_default">var pro=new ol.Projection("EPSG:4326") </div><div class="gmail_default">

<br></div><div class="gmail_default">which can not meet my requirements.</div><div class="gmail_default"><br></div><div class="gmail_default">Did I  miss anything?</div><div class="gmail_default"><br></div><div class="gmail_default">

<br></div><div class="gmail_default">Yang</div></div></div>