I use a custom content type with a Geofield field, it containt a linestring.
To display this field i use the format Openlayers Openlayers
map: Openlayers Geofield: Formatter Map
Openlayers layer: openlayers_geofield_layer_formatter
Data options: Use full geometry
The component « Openlayers Geofield: Zoom to Source » is enable and attach at this map

$ol_component = new stdClass();
$ol_component->disabled = FALSE; /* Edit this to true to make a default ol_component disabled initially */
$ol_component->api_version = 1;
$ol_component->machine_name = 'openlayers_geofield_component_zoom_to_source';
$ol_component->name = 'Openlayers Geofield: Zoom to Source';
$ol_component->description = '';
$ol_component->factory_service = 'openlayers.Component:ZoomToSource';
$ol_component->options = array(
'source' => array(
'openlayers_geofield_source_vector' => 'openlayers_geofield_source_vector',
),
'animations' => array(
'pan' => 500,
'zoom' => 500,
),
'zoom' => 'auto',
'enableAnimations' => 1,
'process_once' => 1,
'max_zoom' => 0,
);

But the view shows the map with the position and zoom defined in the map setting.
If move and zoom manualy the map to the location of my geofield it’s ok i can see it.

Is « Openlayers Geofield: Zoom to Source » the right way to get a map center on the geofield

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MichelE created an issue. See original summary.

MichelEnezy’s picture

Issue summary: View changes
scottbedmonds’s picture

I am having the same issue. When I edit the Component Type Options for Zoom to Source, I can not set the Attach This to a Map? field. I can select, but it won't store the value.

m.stenta’s picture

@scottbedmonds - I think the "Attach This to a Map?" option is broken (I seem to remember that it was actually removed in the dev branch, but I didn't look). In either case, you can add your component to your map by editing the Map itself, clicking on "Components" and checking the box next to your Zoom to Source component. Hope that helps!

scottbedmonds’s picture

@m.stenta Thank you for your reply. I have done what you mentioned. But it still does not zoom to my vector point when the map is displayed. To be clear, like the OP, I have a geofield with a lat/long widget. On Display I am selecting: Openlayers map: Openlayers Geofield: Formatter Map
Openlayers layer: openlayers_geofield_layer_formatter
Data options: Use full geometry

The map shows, but zoomed all the way out. If I change the maps default zoom, then it zooms way in to 0,0 and does not zoom to my point.

I am using 7.x-3.1+92-dev because I want to use OSM instead of broken mapquest

Thank you for any insight.

scottbedmonds’s picture

FileSize
93.36 KB

Sorry, adding screenshot of Components edit

m.stenta’s picture

Did you edit the Zoom to Source component and specify the Source that you want to zoom to?

I am using Zoom to Source in the farmOS distro (http://drupal.org/project/farm). You can set up a running farmOS instance on http://simplytest.me and see how it is configured in there for comparison.

scottbedmonds’s picture

@m.stenta, I appreciate that. Btw, Simplytest.me is asking for a username/pass

Your tip lead me in the right direction however, I had set Zoom source correctly, but there is a check box that is set by default, in Component Type Options: Zoom just on map build is checked. Unchecking this works, and that makes sense, as it allows the zoom to happen after map build.

Thank you, and I hope this helps someone else. I would still be very interested in your FarmOS config if you don't mind allowing me in.

Thank you again

m.stenta’s picture

Huh. Not sure why simplytest.me is requiring a username/password - might be a bug. I don't run that site - it's just a service that lets you test Drupal modules/themes/distros (gives you 30 minutes or something before the site is destroyed automatically).

You can take a look at the farmOS code for one of the zoom to source components directly here: https://github.com/farmOS/farmOS/blob/7.x-1.x/modules/farm/farm_map/farm...

scottbedmonds’s picture

@m.stenta Thank you!

ken-g’s picture

Status: Active » Needs review

To summarise the above comments, to get this working you need to:

  • create new new component "Zoom to Source"
  • ensure the correct source is specified in the component type options screen
  • add the new component to the required map (this wasn't working properly, but was fixed in 7.x-3.2)

Setting issue to "Needs review".

ken-g’s picture

Title: automatically zoom to a geofield » Automatically zoom to a geofield