I have a regular page view setup that has exposed filters so you can search for nodes which are then displayed in a table (easy stuff).
However, what I'd like to do is something similar to this request and display each of the returned nodes in an OpenLayers map as well (since each node has a WKT field).

How would I go about doing this?

CommentFileSizeAuthor
#5 1043164_attachment_display.jpg46 KBAnonymous (not verified)
#5 1043164_openlayers_display.jpg34.61 KBAnonymous (not verified)
#2 views_search_results_in_map.txt25.38 KBAnonymous (not verified)

Comments

tmcw’s picture

You could use OpenLayers CCK displays for this purpose.

Anonymous’s picture

Status: Active » Fixed
StatusFileSize
new25.38 KB

I actually worked out how to do this myself just now. Here's my setup:

I have my existing page view setup with normal filters and exposed filters. I have set the exposed filters form to display in a block.

I then added an attachment display to my view (not attached to anything), which was the same as the page display, but with the following changes:
- The only field it outputs is the Node ID
- The exposed filters were changed to arguments (normal filters stayed the same) - to do this, I had to use the Views patch from here to allow the arguments to use the 'contains' operator (the same as my exposed filters)

This attachment display allowed me to get the NIDs of the nodes returned when doing a search on the page display. I simply got the page displays search terms from the URL using $_GET[], then passed those terms as arguments to the attachment display to get a list of NIDs.

This code was placed in a filter (using ViewsPHPFilter) in an OpenLayers Data display so that the OpenLayers map would show the same nodes returned in the page display (this was the only filter used in the OpenLayers Data display). The fields output by the OpenLayers Data display were simply the ones I wanted displayed in the map popup boxes (plus the WKT field).

Finally, I added a block display which displayed a map based on the OpenLayers Data display, then placed this block in the sidebar on the page displays URL.

Now, when I search for nodes using my page displays exposed filters, I see the nodes on the page itself, as well as on a map in the sidebar. Awesome!
I've attached my view for anyone interested in doing something similar.

Devcal’s picture

Great!!!! , I want to do exactly the same thing. But I do not understand everything (my poor English), it is possible to have screenshot of your attachment display's configuration? and openlayers Data display's configuration?
I have long sought
thanks

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Here you go.

kapayne’s picture

Many thanks to all the good advice here, especially the good comments from BWPanda.
In case anyone else is looking through here I'd like to document an alternative solution that might come in handy.
In the case presented in #2 the developer used exposed filters to return a list of nodes on a page. The same terms from the exposed filter were in the URL so the developer grabbed the terms from the url using the GET command and passed them into arguments in the attachment display, essentially running the filter twice, one in the page and once in the attachement display. The attachemnent display returned the NIDs from the second filter and the phpfilter grabbed the nids from the attachment display to openlayers.

Alternatively, I set up a set of exposed filters on a page and in that same view, I grabbed the resulting nids from the filter and put them in a session variable in the footer (global text area). Then I used the php filter in the open layers data view to get the nids from the session.

The footer on the page display:


// Variables
$nids = "";

// Get the current view (in this case, the view with exposed filters).
$view = views_get_current_view();

// Put all nids from view into comma-delimited list.
for ($i = 0; $i < sizeof($view->result); $i++) {
  $nids = $nids . "," . $view->result[$i]->nid;
}
$nids = substr($nids, 1);

// Place $nids listing into session scope.
session_start();
session_register('nid');
$_SESSION['nid'] = $nids;

This is the phpfilter on the open layers data display:

return explode(",", $_SESSION['nid']);

rob70’s picture

Kapayne, BWPanda, I require something similar, with the added issue of needing to page the nodes to do slow performance in IE.
How many nodes can your solution display at a time efficiently?

Thanks to you both for the walkthroughs on these solutions!