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.
This is just a question...
I see that I can define a source (for example: Google Maps), and include that in a map, without also defining a layer.
But in a lot of the examples, both a source and a layer are defined. Is it recommended to always have a source+layer pair? Or is it ok to define only the source, and include that in a map by itself?
I can see why you would want a layer, for example, if you are using a layer switcher component - but if you're not and you just want the source to be displayed all the time (like a base Google Maps layer), then is it OK to only use a source?
Comments
Comment #1
PolHello,
It's written on the project page: https://www.drupal.org/project/openlayers
Every layers needs a source, except for the google layer which is an amazing hack that das-peter did.
Comment #2
m.stentaOK, you say "every layer needs a source" - that makes sense.
But what about: "does every source need a layer"?
Is the answer "yes", but with an exception for the Google sources?
Out of curiosity, can you point me to where that "hack" is so I can understand it better?
Thanks Pol!
Comment #3
PolNo, the source doesn't needs a layer.
Sometimes, sources like Clusters needs another source too. It's a bit tricky but we've managed to find a way in Openlayers so it's transparent for the user.
Comment #4
m.stentaThanks for the clarification!
Are there any considerations if I only add a source, and not a corresponding layer? Will it all work the same with just a source?
Comment #5
PolIt's useless actually.
Here's the simplified hierarchy of a map:
Maps are composed of:
- Controls
- Interactions
- Layers
- Components (hybrid Drupal object manually added on purpose)
Layers are composed of:
- Sources
AFAIK, adding a source to a map doesn't make any sense.
Comment #6
m.stentaOk... I guess I am just confused about the GoogleMaps source, but it sounds like that is an exception to the rule?
I am able to create a GoogleMaps source (not layer), and add that to a map, and it works.
Comment #7
PolIndeed, the Google map is a hack and this is why it's a bit different from the standard established by Openlayers JS.
Comment #8
m.stentaOk copy that. I just tested a different type of source (the TileWMS patch I am working on in #2475355: Add WMS Layer Support to OL3), and you're right: it does not show up if there is no layer. So you do need both.
Thanks again for helping me to understand! :-)
Comment #9
PolFYI, it won't be possible to add Source to a Map after this branch has been committed: https://github.com/drupol/openlayers/pull/9
Hardly working on this now.
Comment #10
m.stentaGood to know.
I looked at that branch... I am about to undertake some LayerSwitcher work myself... that ol3-layerswitcher project looks very nice! Do you mind if I give your branch a try, and maybe continue where you left off?
Comment #11
PolSure, go ahead... That's why I've setup a Github clone of the repo :)
Comment #12
m.stenta@Pol: I started looking at the LayerSwitcherChanges branch this morning, but then realized that you had deleted it from Github, and partially merged it into 7.x-3.x? I'm still trying to understand the git log... it appears that there are a couple of commits in different branches with the same title - all saying that LayerSwitcherChanges was merged......... But when I try out the latest code it is still using the old layer switcher.
What's the status on that branch?
I'm in IRC right now, if you are available...