I need to be able to auto-zoom to the location I've setup in the node. I'm using geocoder and it's working very well. The view shows the map point fine, and the map zooms into what's specified within the preset "Center + Bounds". However, when I try to use the "Zoom to location" behaviour, I'm getting terribly confused.

How do I use the geocoder query, or another method to auto-zoom into the location? The replacements patterns don't show the WKT field, which is what I would assume be used here. Please help, any suggestions would be greatly appreciated.

****
Zoom to location
Zoom to the boundary box of a specified location.

GEOCODER QUERY:

Query submitted to the geocoder. You can use replacement patterns below.

Query replacement patterns
Token Replacement value
Openlayers data tokens
[maps_openlayers_1-name] Attriubute: name
[maps_openlayers_1-title] Attriubute: title
[maps_openlayers_1-description] Attriubute: description
[maps_openlayers_1-field_prop_notes_value] Attriubute: field_prop_notes_value

Comments

Devcal’s picture

+1

ademarco’s picture

Project: Openlayers » OpenLayers Geocoder
Component: Behaviors » Code

Moving to Openlayers Geocoder issue queue.

c-c-m’s picture

I have the same question here

Anonymous’s picture

I also do not have an idea how to handle this, but would be interested in a solution.

c-c-m’s picture

Status: Active » Fixed

In order to achieve zooming to extents, you have to do the following:

  1. edit your desired preset.
  2. go to behaviours tab
  3. scroll down till you see "Zoom to layer"
  4. you'll be asked to select which layer do you want to zoom to and which amount of zoom you want to choose

It's pretty simple when you find the correct place!

Hope it helps.

Anonymous’s picture

This unfortunately does not work in here. If I chose e.g. zoom to layer with "google_normal" the zoom level does not have an influence. It might work with zooming to a views layer, I have not tried, yet.
Neverthless the apropriate point for the current node gets properly displayed, even without a views layer. Only zooming does not work.
I have the hope that there is a way for zooming properly without a views layer.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Should be reopened. From my point of view it is not fixed.

avr’s picture

In order to get the value from the "Zoom to Layer" configuration to effect the "Zoom to Location" you need to add a couple lines of javascript to openlayers_geocoder_zooomtolocation.js.

Specifically, you should add:

    if (data.map.behaviors['openlayers_behavior_zoomtolayer']) {
      data.openlayers.zoomTo(data.map.behaviors['openlayers_behavior_zoomtolayer'].point_zoom_level);
    }

so the final file looks like:


/**
 * @file
 * JS Implementation of OpenLayers behavior.
 */

/**
 * Zoom to location
 */
Drupal.behaviors.openlayers_geocoder_zoomtolocation = function(context) {
  var data = $(context).data('openlayers');
  if (data && data.map.behaviors['openlayers_geocoder_zoomtolocation']) {
    var bounds = data.map.behaviors['openlayers_geocoder_zoomtolocation'];

    // After geocoding perform zoom.
    if (!data.map.displayProjection) {
      data.map.displayProjection = 4326;
    }

    var displayProjection = new OpenLayers.Projection('EPSG:' + data.map.displayProjection);
    var projection = new OpenLayers.Projection('EPSG:' + data.map.projection);
    data.openlayers.zoomToExtent(new OpenLayers.Bounds(bounds.southwest.lng, bounds.southwest.lat, bounds.northeast.lng, bounds.northeast.lat).transform(displayProjection, projection));
    
    if (data.map.behaviors['openlayers_behavior_zoomtolayer']) {
      data.openlayers.zoomTo(data.map.behaviors['openlayers_behavior_zoomtolayer'].point_zoom_level);
    }
    
  }
}
Anonymous’s picture

Thanks avr for the hint. I changed it and uploaded the .js file. Nevertheless it does not seem to have any influence at all.
Whether setting the Zoom to layer point zoom level to 5, 10 or 15 does not change the map display.
Is there any other setting I could have forgotten? Also changeing the initial zoom level does not change anything.

keyser79’s picture

Here is what I did to achieve this functionality. My objective is to show a map on the node display to show the node's location. I have an OpenLayers WKT field with the geocoder widget type.

-Create a new Openlayers View. Add Nid as an argument and select the "provide a default argument" option under the "Action to take if argument is not present". Then select "Node ID from URL". Also select the WKT CCK as the field for this view.

-Create a new OpenLayers preset (or clone the default one). On the Layers and Styles tab make sure to enable the overlay that you just created in views. Then under the Behaviors tab, select "zoom to layer" and select the overlay view that you just enabled.

This is what worked for me. Its important that when you create a view, the view only chooses the one WKT value that corresponds to the node (hence the Nid argument).

Max1’s picture