Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
it seems there is no possibility to zoom map at the display with cck openlayer addon.
I have installed Openlayers and everything works perfect. Just, I have a problem with displaying a map in a node.
The problem is that a map is always at same position an has same zoom.
What I would like is to zoom display map and center it where the polyline starts.
Is this possible, even via changing a code.
I need this for a project
Thanks in advance
Comments
Comment #1
zzolo CreditAttribution: zzolo commentedneddim, make sure you are using newest dev version.
There is no current way to zoom_to_features on a formatter. The main problem is that cck formatters dont have any options screen.
What you can do, is create a basic map with the zoom to features behavior in a spearate module with hook_openlayers_presets(), then it will be available in the presets, and you can clone and do whatever from there.
Comment #2
that0n3guy CreditAttribution: that0n3guy commentedSo... if zoom to features can just be added on a separate module to be shown in a preset. Why can't zoom to features be added in the "controls" section of any preset? (i'm no programmer.. .just wondering)
Comment #3
phayes CreditAttribution: phayes commentedThis is because zoom_to_features is a behavior that requires some configuration (specifically, it needs to know *which* layer is should be zooming to), the controls section does not allow for configuration, so we cannot add it there. In 2.0 we will be adding a hook for behaviors to define forms, which we can then load into the presets UI.
For more information on programatically creating custom presets see http://zzolo.org/thoughts/drupal-and-openlayers under the "Better than UI" section
Comment #4
that0n3guy CreditAttribution: that0n3guy commentedAhh I see... do you have an example of how to do what zzolo is talking about in #1?
Thanks
Comment #5
zzolo CreditAttribution: zzolo commented@that0n3guy
Try looking here to see an example. It's near the bottom:
http://zzolo.org/thoughts/drupal-and-openlayers
Comment #6
BWPanda CreditAttribution: BWPanda commentedI'm trying to do what was suggested above and create a preset via the API that has a zoom-to-features behariour, but I'm not sure of the syntax to add the behaviour to the preset. I think when you have an API, you really need to list all the possible options for a given function... :)
Here's my code so far:
Comment #7
BoobaaSubscribing
Comment #8
BWPanda CreditAttribution: BWPanda commentedStill needing urgent help with this please...
Comment #9
phayes CreditAttribution: phayes commentedsomething like this:
Comment #10
phayes CreditAttribution: phayes commentedNote: I updated the above code as I found some bugs.
Also, you may wish to use a hook to alter the map instead of writing out the preset. You could use hook_openlayers_map_preprocess_alter
Comment #11
BWPanda CreditAttribution: BWPanda commentedI must be doing something wrong...
I've got the code as per #9 above and I changed the value of 'Layer' to 'Location' (the Name I found under Layers > openlayers_cck_vector). However, my map's not displaying.
When I change the display type of my map (under Display Fields in CCK) to a preset I made using the GUI, it works. But when I change it to the 'node' preset (as above), it doesn't work...
What am I doing wrong?
Comment #12
BWPanda CreditAttribution: BWPanda commentedI just had another look at this, and realised from looking at other maps that the 'layer' should be 'openlayers_cck_vector', but after changing it, I still can't get it to work...
Here's my function:
I'm then just inserting the maps into the node via the .tpl.php file (from the $node object) and setting the display type of my location field to 'OpenLayers Map: Node', but still no luck.
Comment #13
jerdavisThe following implementation should work, I used this on a site today. Place a version of this command in a custom site module:
Comment #14
phayes CreditAttribution: phayes commentedHave you modified and saved the preset via the UI? This might be a good idea to do - it *should* still save your custom behaviour there. One thing to watch out for when using the google projection is you need to have the resolution and MaxExtent set just right. The UI will do this for you if it detects you are using a 900913 projection.
This is actually a reason why I prefer to use a hook_openlayers_map_preprocess_alter instead of a custom preset - although zzolo is right about the hook having a small performance hit as compared to the preset.
Comment #15
BWPanda CreditAttribution: BWPanda commentedI can't do anything to my preset via the UI as it only says 'Export' or 'Clone'...
I like the sound of the preprocess_alter hook, I might give that a try instead.
Comment #16
phayes CreditAttribution: phayes commentedI guess you would need to clone it...
The way I do things is I create my preset in the UI then modify it using the preprocess_alter hook. When it comes to rolling from dev to production you want speed, so then I export my preset and combine it with my preprocess_alter hook in code as a module preset. That way you don't need to hit the database to load the preset, and you don't need to invoke a hook_alter either. But during dev I use the UI and the alter all over the place. I don't know what other's do - I would be curious!
Comment #17
BWPanda CreditAttribution: BWPanda commentedImplementing hook_openlayers_map_preprocess_alter() worked a treat, thanks guys!
Comment #18
velosol CreditAttribution: velosol commented@BWPanda: Could you post your final code?
Comment #19
BWPanda CreditAttribution: BWPanda commentedHere you go:
Things to note:
- My module is called 'brat_custom' so you'll need to change this to whatever your module's called
- I've setup a preset (via the UI) called 'small' which is the one I want to apply this behaviour to, therefore the above code is only applied to maps that use the 'small' preset
- I've called this behaviour implementation 'brat_zoom_to_layer', but from what I understand you can call it whatever you like...
- Depending on your setup, you may need to change the value of 'layer' (mine's set to 'openlayers_cck_vector')
Enjoy!