Hi - I've been trying to figure out a solution to having the cck map widget zoom to a feature in node/edit for the past few hours and just can't see a way through. It works fine in node/view.
Have tried with hook_openlayers_map_alter to assign the zoomtolayer behaviour to the right layer but it strikes me that the problem is that that layer information is simply not available in edit mode.
While when in node/view we get an openlayers_cck_vector_layer in the $map array under behaviors with all the relevant WKT info in edit mode that is simply not there.
Also in the OL code I see this for the theming function in edit mode:
function theme_openlayers_cck_map($field = array(), $map = array()) {
// TODO: fix
return $map;
}
and I am guessing that TODO is a rather telling sign.
Would be grateful is you could:
a) Let me know if I am just being silly and it can easily be done or simply can't be done for some reason
b) Let me know if that TODO above points to just this type of work and a couple of pointers and will be happy to try to do the patch myself
c) Anything else you think might help!
Thanks
ps: have it as a bug report because I thought it should be there but it isn't but it may well be a feature request :-)
Comments
Comment #1
Sanjo CreditAttribution: Sanjo commented+1
Have the same problem. Maybe I will look into it tomorrow.
I think that's a feature of the OpenLayers Geocoder. (http://drupal.org/cvs?commit=359388)
So maybe we can port this feature to OpenLayers and add an option for this.
Comment #2
steinmb CreditAttribution: steinmb commented+1
Is this a "hidden" feature or is it still pending? I would love to see my node zoom to layer when edition the node.
Comment #3
zzolo CreditAttribution: zzolo commentedThis is not currently possible without a map_alter at the moment.
This "issue" is that there is no support in the interface for setting behaviors for the input layer on the widget. This could be done in a similar fashion as the widget behavior settings for the formatter map. The idea is the same; basically the preset interface doesn't know about the layers used for input and display on the map.
Also, note that the Geocoder behavior there is for zooming to a geocoded value.
Also, you could easily do this with a hook_openlayers_map_alter() if you wanted.
Comment #4
ronald_istos CreditAttribution: ronald_istos commentedzzolo tried to do it with hook_openlayers_map_alter but simply can't get it work. alters work fine in any other place... is there something I am missing?
Comment #5
zzolo CreditAttribution: zzolo commentedHey @ronald_istos. Have you tested to make sure the hook is firing? (suggestion would be to do a drupal_set_message())
From there, you just want to manually add the zoom_to_layer behavior with the CCK layer name in it. You'll have to look at the code and output the map array to see this all in action, but it should only be a few lines of code. Something like the following (though do not quote me as I am just going off memory here):
Comment #6
ronald_istos CreditAttribution: ronald_istos commentedzzolo the hook fires and you can adjust the zoom - but the information for where to zoom at is not available in the array. The centerpoint zoom is the one of the preset.
While, when viewing a node you have the cck_vector_layer to get the info from you don't have that info when editing a node.
I guess you would need to load the node - get the info if there is any to get at and then adjust the zoom and center point based on that.
Comment #7
zzolo CreditAttribution: zzolo commentedSo, what you have to do is look at the Draw Features behavior, as it creates the layer for the editing, which is named: "openlayers_drawfeatures_layer".
Then, look at the zoomtolayer behavior, and what the parameters are.
Again, untested, but should be able to:
Comment #8
Adam S CreditAttribution: Adam S commentedDoes OpenLayers not zoom to feature (point) in CCK node edit as is? Or, has this been fixed? I created a view with NID as argument and a single field of WKT. This enables the preset to zoom but there is a big problem with it -- the point does not move.
Comment #9
zzolo CreditAttribution: zzolo commented@Adam, this is still not in there at the moment.
You could do your method, but hide the feature layer you are zooming to with a blank style. The problem is that you are displaying the point you have created and t will not disappear because it is not on the editing layer.
Comment #10
mansspams CreditAttribution: mansspams commentedSome other approach is needed, zzolo. There is no info of points in $map array and http://drupalcontrib.org/api/function/hook_openlayers_map_alter/6 says 'Adding behaviors, pre-defined layers here will not work. This is good for minor tweaks after the map has been processed.' Is there another hook?
Comment #11
zzolo CreditAttribution: zzolo commentedHi @LavaMeTender ak.... That docs site might not be up to date, you should refer to the documentation that comes with the module. See:
http://drupalcode.org/viewvc/drupal/contributions/modules/openlayers/doc...
Specially see
hook_openlayers_map_preprocess_alter
.Comment #12
Agileware CreditAttribution: Agileware commentedFor anyone that needs it, here is the code that works for me to get the zoom to layer on the cck vector layer.
Keep in mind that this is not an entire solution as in this state the code will affect all openlayers maps.
So you need to add checks to make sure you only modify the maps you want.
There doesn't seem to be any great way to work out which maps you are you are but you could potentially use the url (if you don't have other maps on the same page you don't want to affect) or the $map['preset_name'] or something.
Comment #13
figs CreditAttribution: figs commentedCould someone please explain for a complete noob how to use this code? Would love to get this working...
Comment #14
Agileware CreditAttribution: Agileware commentedYou need to create a custom module, for this example called mymodule, by doing the following (this is just a basic example):
* Create a directory called mymodule in your sites/all/modules directory (or wherever you want to put it).
* Create a file called mymodule.info in the mymodule directory and in it have the following text (put whatever you want for the description):
* Create a file called mymodule.module in the mymodule directory and in it have the following text (just copy and paste this exactly into the empty file):
Then enable the "My module" module on the modules page (admin/build/modules).
You can change the name of the module to something more relevant by changing all occurrences of mymodule to something else (including directory names/file names/function names).
Comment #15
figs CreditAttribution: figs commentedThanks for that.
Comment #16
figs CreditAttribution: figs commented...
Comment #17
figs CreditAttribution: figs commentedThat works fine for me, IF I choose to zoom to the
openlayers_cck_vector_layer
layer. Can I use this same method to zoom to the Feature Layer?I've tried swapping out
openlayers_cck_vector_layer
foropenlayers_drawfeatures_layer
andopenlayers_cck_input_layer
, but neither are working. What is the correct name to address the "Feature Layer"?Thanks.
Comment #18
figs CreditAttribution: figs commentedDoes the Feature Layer info exist in the array at all? Zzolo you seem to imply that it does, but I can't see where anyone has zoomed to the Feature Layer when editting a node. So is it possible to use the map_preprocess_alter method at all for this?
Comment #19
zzolo CreditAttribution: zzolo commented@figs. It seems like people are able to make this happen. Output your map array in the map_alter to understand it better and to ensure that the pieces are there.
Comment #20
figs CreditAttribution: figs commentedZzolo, if I look at the $maps array when viewing a node, in one array entry I get a point..
..which I can zoom to with a hook (using the same method Agileware used), but there is no similar layer available in the $maps array when editing the node. I'm not sure if anyone else got this working this way? I'm in above my head here and really appreciate the help.
Comment #21
Agileware CreditAttribution: Agileware commentedFor me it works on the node view and edit pages.
This is what I have:
You would just need to change mymodule to your module name and mypresetname to the machine name of the preset that is being used on your cck field map.
Comment #22
figs CreditAttribution: figs commentedThanks Agileware, but unfortunately this still doesn't work for me. This was essentially the same as what I was doing before when it worked for viewing a node but not editing a node.
When viewing it zooms to the correct data points (see http://drupal.org/files/issues/view_16.png).
But when editing the zoom falls back to the default zoom to location (see http://drupal.org/files/issues/edit_13.png).
As far as I can tell this happens is because
openlayers_cck_vector_layer
doesn't exist in $maps when editing, which is strange because the data I want to zoom to is visible on the map when editing! Perhaps I'm doing something else different. I only have the one preset defined; do I need more?Comment #23
figs CreditAttribution: figs commentedNo ideas?
Comment #24
Dave-B CreditAttribution: Dave-B commented+1
Comment #25
mikejw CreditAttribution: mikejw commentedI had a similar problem and in my case it was because I had Default Style set to "Invisible" in my map preset for the overlay layer.
Comment #26
zzolo CreditAttribution: zzolo commentedClosing. Sounds like you all figured it pretty well. Patches are welcome to put this in the module.
Comment #27
naught101 CreditAttribution: naught101 commentedFor reference: #1516758: 2.X: Zoom to cluster