Active
Project:
Geofield
Version:
7.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
11 Oct 2012 at 07:06 UTC
Updated:
27 May 2015 at 12:27 UTC
Jump to comment: Most recent
Comments
Comment #1
tky commentedI found the same issue here. Though I enabled the "Zoom to layer" function for my input map, it won't do the job it supposed to do when get geodata from addressfield.
It would be better that the map can zoom in with data input while user click "find using XXX field" function in edit form. Would improve the accuracy if user can navigate the location and check it.
Comment #2
FrancoNogarin commented+1 on this
Comment #3
Sinovchi commentedIt would be really helpful if the edit form also zoomed to the drawn feature.
Comment #4
flaw commented+1
Comment #5
maijs commentedIn case you want "Zoom to Layer" behaviour to work in geofield widget (on the edit node page), you can use a hook which injects "openlayers_behavior_geofield" layer to possible "Zoom to layer" behavior options:
After you add this hook, do the following:
1. Go to Structure > OpenLayers > Maps > (your widget map) > Edit > Behaviors > Geofield and make sure Geofield checkbox is checked.
2. Save the form by clicking "Save and edit"
3. When map edit form reappears, go to Behaviors > Zoom to layer, enable "Zoom to layer" option and choose "openlayers_behavior_geofield" layer in layers list.
4. Now when you edit an entity which has a geofield field attached (with OpenLayers map widget), "Zoom to Layer" will zoom to the features layer.
Comment #6
fonant commentedPerfect! #5 works just how it should, thanks maijs.
Comment #7
vistree commentedHi, is #5 expected to work with actual openlayers and Drupal-core 7.26?
I can't get it to work ;-(
UPDATE: Sorry, works great!!! I tried to implement the hook in template.php (which was not working).
After putting the code in a module it works - thank you!!!
Comment #8
drupalok commentedcan't get it to work...
added your code to a new module, enabled it. checked geofield...
but the new layer is not showing in "zoom to layer"
can you upload your working module please?
Comment #9
m.stentaI'd like to know if there's a way this can be added to the Geofield module itself. It seems like a common requirement.
I don't quite understand why the code in #5 works, though. Is there a way to do it in the Geofield module without a hook_form_alter()?
Comment #10
m.stentaHere's another way to accomplish the same thing: hook_openlayers_map_alter().
You can either enable it on a per-map basis:
or for all maps that have both a Geofield and Zoom-To-Layer behavior:
I don't think either of these will work in the Geofield module, because both require pretty specific assumptions.
What I still don't understand is WHY this works. The "oppenlayers_behavior_geofield" is a BEHAVIOR. Not a LAYER. So why can we add it to the list of LAYERS that are zoomed to??
Comment #11
japo32 commentedThanks for this. #10 worked for our use case. We used the second solution to apply it to out custom maps.
Comment #12
ngunner commented#10, 2nd option worked like a charm! Just make sure to clear caches after implementing it. My users will be so happy!