1

I am working on a project to put google maps layer and adding our data layers on top of it. using openlayers and google maps layer with out layer of top of it

now the google layer has max resolution of 156543.0339 and 22 zoom levels, I can limit the zoom levels and max resolution etc but how do I stop the map at just one world/globe

i.e. I don't want it to scrolling off to another wrapped around world!

enter image description here

Please see this fiddle for example, http://jsfiddle.net/eaJHn/5

Anyone !!! ?

1
  • 3
    what do you mean by "stop the map at just one world/globe"?.you should explain your problem properly maybe with a figure and you will get better answers. Welcome to GIS SE.
    – rkm
    Commented May 14, 2013 at 2:41

4 Answers 4

2

OpenLayers.Layer.Google (which I assume you are using) has the property "wrapDateLine" set to true. This should be set to false, and as the source says you should also set sphericalMercator to true.

So, something like:

var layer = new OpenLayer.Layer.Google("Google", {
    wrapDateLine: false,
    sphericalMercator: true
});
1
  • 2
    hi Thanks for the reply, it does not seems to work, maybe I am doing something different , please see this fiddle jsfiddle.net/eaJHn/5 Commented May 16, 2013 at 17:46
1

Guessing from your description you are searching for a way to stop the user to zoom out at a certain zoom level. Am I right?

In the OpenLayers Wiki about Configuring ZoomLevels you find examples for doing that with the minZoomLevel option:

map = new OpenLayers.Map( $('map') );

var layer  = new OpenLayers.Layer.Google( "Google",
         { minZoomLevel: 3, maxZoomLevel: 8 });

// layer.numZoomLevels == 6

Though it can be a bit tricky it worked for me on a Google layer.

1
  • +1 This is exactly what I wanted to answer. And the fiddle is here: jsfiddle.net/eaJHn/6
    – Tomas
    Commented Jun 27, 2013 at 20:40
1

In addition to setting wrapDateLine : false as mentioned by atlefren. I found a way with restrictedExtent and pass it the bounds.

There is another way to attach listener to the openlayer map object and re-pan or re-cetner

due to popular demand here is the relevant snippet of code. However complete code can not be pasted as it spans 2 or 3 files, so see this fiddle http://jsfiddle.net/eaJHn/7/ for complete example

Rest of the answers on this questions are also very informative , as they all provide different info needed to create a proper google map with openlayers

var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
var restrictedExtent = maxExtent.clone();

var map = new OpenLayers.Map({
            div: "map",
            projection: proj4326,
            displayProjection: proj900913,
            maxExtent: maxExtent,
            restrictedExtent: restrictedExtent,
        });
7
  • Can you please decribe your solution? It is not clear from mere note "the I found a way with restrictedExtent and pass it the bounds". Possibly include your code and then accept your own answer! It is even encouraged to do this!!!
    – Tomas
    Commented Jun 27, 2013 at 20:44
  • The restrictedExtent takes a bound parameter, you can pass it the world bound in spherical mercator, something similar to maxExtent: new OpenLayers.Bounds(-20037508.34, -20037508.34, 20037508.34, 20037508.34), hth Commented Jul 14, 2013 at 21:51
  • can you possibly modify the example jsfiddle.net/eaJHn/5 to show this, and then accept your answer?
    – Tomas
    Commented Jul 15, 2013 at 9:19
  • 1
    sure , here it is the updated version , now this map does not wrap after one world, jsfiddle.net/eaJHn/7 Commented Jul 18, 2013 at 6:11
  • great. Maybe you should also include the code in your answer, then it will be perfect :) I will then upvote (but notify me so that I know), you can accept your answer and others will also upvote you :-)
    – Tomas
    Commented Jul 18, 2013 at 6:17
0
var maxExtent = new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508);
var restrictedExtent = maxExtent.clone();

var map = new OpenLayers.Map({
            div: "map",
            projection: proj4326,
            displayProjection: proj900913,
            maxExtent: maxExtent,
            restrictedExtent: restrictedExtent,
        });
1
  • Welcome to GIS Stack Exchange! The code may say it all, but I would recommend always providing a few words with it to provide readers with some context.
    – PolyGeo
    Commented Jul 18, 2013 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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