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

Pol’s picture

Hello,

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.

m.stenta’s picture

OK, 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!

Pol’s picture

No, 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.

m.stenta’s picture

Thanks 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?

Pol’s picture

It'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.

m.stenta’s picture

Ok... 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.

Pol’s picture

Indeed, the Google map is a hack and this is why it's a bit different from the standard established by Openlayers JS.

m.stenta’s picture

Status: Active » Closed (fixed)

Ok 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! :-)

Pol’s picture

FYI, 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.

m.stenta’s picture

Good 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?

Pol’s picture

Sure, go ahead... That's why I've setup a Github clone of the repo :)

m.stenta’s picture

@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...