I have a map on my Geoserver, which I am displaying via wms and Openlayers. I am using a projection that is optimal for the whole area. However, when zooming in I would like to switch to a different projection which has proved to be best for a particular locality.

How can I achieve this? Any examples out there?

1 Answer 1


The methodology would be to detect a zoom change and apply a updated view with the new projection to the map.

First you have to detect the change of the resolution:

map.getView().on('change:resolution', changeProjection);

Secondly you look if you have reached the desired zoom level and then apply the projection:

var changeProjection = function() {
  var zoomLevel = map.getView().getZoom();

  // look if zoom level is reached
  if (zoomLevel > 15) {

    //define new view and apply to map
    map.setView(new ol.View({
      center: map.getView().getCenter(),
      zoom: zoomLevel,
      projection: newProjection /* typeof == ol.proj.ProjectionLike */

Note: The code is untested and you have to set variable newProjection to make it work.

  • Thank you! It looks like what I am looking for. However, it is not working, I am unable to switch to the new projection (my layer becomes invisible after executing setView).
    – Qaisa
    Oct 7, 2015 at 12:26
  • You are right. I just created a jsfiddle but after changing zoom level layer becomes invisible. hmm, a bug or a feature?
    – geraldo
    Oct 14, 2015 at 14:23
  • I have found that it works if I set center to ol.proj.transform(map.getView().getCenter(), 'EPSG:32622', 'EPSG:3574'). I agree with you that it must be a bug.
    – Qaisa
    Oct 16, 2015 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.