Please can you point me at any sample code / docs on how to achieve this.

Should I be adding code into views at some point, or can I use hook_openlayers_map_preprocess_alter ? If I use the OL hook, is it still possible for me to access the view so I know whether to ignore it, or read its argument and add in my overlay layers? Or is there an easier way altogether?

Background - I have the basics working: use a view to display a bunch of markers on a map, along with several overlay layers I've defined.

Next I'd like to create a new node type that contains information about a layer (a bounding box, and some stuff to display), then automatically add that information as an overlay layer.

eg when I display the layer node, I want it to show a view where the layer node's information appears as an overlay layer over a preset.

eg2 have a view that takes a lat/lon point as an argument, and displays a map with an overlay layer per layer node that contains that point within its bounding box.

I'll keep the views query for searching for markers. So I think I'll have to write the search for matching layer nodes as part of this project.

Any hints & advice welcome!

Thanks & regards, David

Comments

zzolo’s picture

Hi @gwulo. You should be able to do this with the map alter, but you'll have to create the layer object (in code or in the database). If you look at the Views layers, they are made "on the fly" from OL Views.

Also, I feel like @strk was trying to do something similar to this.

davidhk’s picture

@zzolo, thanks for the pointer. Thinking out loud, it looks like all the good stuff happens in function openlayers_build_map(), and that I've got two choices:

A. Build the layer object in the database, then use hook_openlayers_map_preprocess_alter() to add an entry to $map for it. Then _openlayers_layers_process() will take care of loading the layer object.

B. Build the layer object in code, then use hook_openlayers_map_alter() to add the object to $map.

There are comments above the call to hook_openlayers_map_alter() that say we shouldn't use it to add new styles or behaviours here. It doesn't specifically mention layers, but it looks as though option A will be the safer choice for now.

Does that sound reasonable?

tmcw’s picture

Next I'd like to create a new node type that contains information about a layer (a bounding box, and some stuff to display), then automatically add that information as an overlay layer.

eg when I display the layer node, I want it to show a view where the layer node's information appears as an overlay layer over a preset.

It doesn't seem like any map alters are necessary here: create an OpenLayers Data view that displays nodes and has an argument for the node ID, and put that on the page.

Same kind of thing with the other question relative to filtering nodes based on CCK contents; this is what OpenLayers data views are for.

davidhk’s picture

@tmcw, please could you expand on your comments? I'm ok using an OpenLayers Data view to display nodes that are points, but haven't tried the others (bounding box / WKT) yet.

The 'layer node' will contain information (eg bounding box, path to tiles) about a maptiler map.

Then have a view that takes the node ID as argument, and automatically adds that maptiler map as a layer.

Is that do-able with the current OL Data view?

Regards, David

tmcw’s picture

Oh, if you're trying to have nodes automatically be layers as well, then, yeah, you'll need to write a bit of code.

So, there are definitely ways to do this; probably the cleanest would be to do the whole creating-layers-by-querying-nodes-and-then-returning-the-in-a-_layers-callback thing, but the underlying question is:

Why are you creating nodes rather than layers? Is it not possible to, say, create the layers and then refer to them from the nodes, thus if your intent is to add extra data to these layers / the ability to comment, etc., then you have the best of both worlds? I can't help but see a bunch of cases in which nodes-as-layers are going to break, rather than a more discrete system.

davidhk’s picture

I agree, it looks a lot easier to define the layer via the OL Admin UI, then just link to it from the node. I'll go with that.

Then I'll use hook_openlayers_map_preprocess_alter() to add layers to the map.

Another question - within that hook is there a way to access the view? I'll need to check the view name and read some arguments, but I didn't see the view passed in.

Thanks for your help, David

zzolo’s picture

No, the view is not passed in, as it is not needed for map rendering. You may be able to take the name or id of the data overlay to then figure out which View it is.

davidhk’s picture

Thanks zzolo. I'm grabbing the info I need from the url at the moment, a bit clunky, but seems to work. All the basics are working, but it'll be another couple of weeks before I can work on it again. I'll post up a link when it's finished, in case it's useful to others.

zzolo’s picture

Status: Active » Fixed

Hi @gwulo, yeah sounds a little clunky, but glad its working. It might make sense to pass the view name with the preset.

Please post a link when done. Closing for now.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.