If the layer I want to center my map to contains only one item, the Zoom to Layer behavior centers/zooms the map to the Initial Map View set in the Center & Bounds map properties section.

It should instead center the map to the layer only item and extend the map according to the point zoom level set in the Zoom to Layer behavior.

Members fund testing for the Drupal project. Drupal Association Learn more


Pol’s picture


We committed a fix that probably fix your problem, can you update your version to the latest dev and give me some feedback ?


goron’s picture

Status: Active » Fixed

I was experiencing this issue as well and updating to latest dev fixed it.

tryitonce’s picture

I found the same problem and believe the issue is not fixed.
I have the following observations:

  1. OpenLayers 7.x-2.0-beta1 - the map centres on the single location, but does not zoom in
  2. openlayers 7.x-2.0-beta1+54-dev (2012-Jul-31) - latest update as far as I can see -
    when I have only one or several locations in reach of a proximity search the map centres on its base location centre - i.e. 0,0.
  3. OpenLayers 7.x-3.x-dev (2012-Jul-20) - the map centres on the single location, but does not zoom in

I am using the set-up of http://drupal.org/project/ol_locator and am working on a more detailed tutorial here - Openlayer Proximity Search – Drupal 7 .

Hope this helps to find the solution - thanks ....

Pol’s picture


The last update on OL (-dev) isn't from 31 July. Are you sure that you are using the latest ?
I think the best is to use Git.

tryitonce’s picture

Ahh, something else to finally get round to doing - "to use Git" - sure, everyone talks about it.

In the meantime - any other link? Zip / tar.gz ...

Shall follow up on this - thanks

Pol’s picture

What you can do to be sure to get the latest source tree is:

git clone --recursive --branch 7.x-2.x http://git.drupal.org/project/openlayers.git

This will create a directory 'openlayers' and a checkout on the 7.x-2.x branch (the dev).

I'm on irc irc://chat.freenode.net/drupal-geo if you need help, my nick is drupol.

tryitonce’s picture

Pol, thanks for the git link - I got it - but it seems not to work (for me yet, breing new to git).
Thanks for the help and offering more via irc - another thing I need to understand first - 2 in a day.
I got the download - but it has an incomplete info file.

name = "OpenLayers"
description = "OpenLayers base API module"
core = 7.x
package = "OpenLayers"
php = 5.2
dependencies[] = ctools
; Core files
files[] = openlayers.module

With this the module is not showing up under .../admin/reports/updates. Let's see - but the function seem the be there - so it might have to be like this?
But - it is not working - the map centres to 0,0.
Time to have a look at irc ...

cesareaugusto’s picture

It seems to be fixed now!

tryitonce’s picture

Hi Cesare,

which version are you using.
What I got through git did not work. I am still using OpenLayers 7.x-2.0-beta1 which at least centres on a single location, but does not zoom in on it.


goron’s picture

tryitonce - please try the latest version of OpenLayers (7.x-2.x-dev from Aug 3). You can download this very easily by clicking on the (red) link on the module page. The problem is fixed there.

tryitonce’s picture

Thanks goron, I am now using (7.x-2.x-dev from Aug 10) and it seems to be working now.
Though, there are still some inconsistencies and if I can pint point them I will come back to update.

Just a general hint for all is to double check the map settings - the right layers have to be activated - also under "Behaviors".

There is another question related to this about whether or not the starting point for the proximity search should be included on the map centring - but I will add this to another issue.

JMC’s picture

Status: Fixed » Needs review


I've recently upgraded to the latest dev version (7.x-2.0-beta1+66-dev) and I can see that this has been fixed for most layers but I think it still doesn't zoom to "point level" when there's only one point on the layer AND when the layer is KML or GEOJSON. This is probably due to them being loaded by the browser, and I'm guessing the new additional code runs before the page has completely finished loading these types of layers?

I'm still new to OpenLayers/JS so apologies if I've got the wrong end of the stick completely, but I fixed my problem by adding the following code in the openlayers_behavior_zoomtolayer.js file:

     if (layers[i].layer_handler == 'kml' || layers[i].layer_handler == 'geojson') {
        layers[i].events.register('loadend', layers[i], function() {
          layerextent = layers[i].getDataExtent().scale(zoomtolayer_scale);
          // If unable to find width due to single point,  /* NEW */
          // zoom in with point_zoom_level option.         /* NEW */
          if (layerextent.getWidth() == 0.0) {             /* NEW */
            map.zoomTo(options.point_zoom_level);          /* NEW */
          }                                                /* NEW */

I'd be happy to try and create this as a patch but I thought I'd post this first in case I've misunderstood or someone more experienced might want to suggest a cleaner way to do the above.

Pol’s picture

I'll take care of this tomorrow at the Openlayers Sprint in Munich ;-)

thechumley’s picture

Hi all,

Be gentle, this is my first patch - thanks to Pol for helping me out with this at the sprint at DrupalCon 2012 in Munich.

Pol’s picture

Status: Needs review » Fixed

Committed, thanks @thechumley for your first patch :)

Link: http://drupalcode.org/project/openlayers.git/commit/f169e4a

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

drupalok’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

i think this issue is back
to recreate:
add openlayers widget to entity
add ONE POINT as feature
view node

it does work with multiple points, lines and polygons though...

  • Pol committed f169e4a on 7.x-3.1.x authored by thechumley
    Issue #1710634: Zoom to layer doesn't work the layer contains only one...