Download & Extend

Provide GeoJSON Layers from Views (integrating with views_geojson)

Project:OpenLayers
Version:7.x-2.x-dev
Component:OL Views
Category:feature request
Priority:normal
Assigned:Pol
Status:closed (fixed)

Issue Summary

Problem/Motivation

I would like to be able to provide layers from views based on views_geojson.

Proposed resolution

Change the view filter in Openlayers and create Layers from views having the style plugin 'views_geojson'.
Technically, I modified the function openlayers_views_openlayers_layers_info() in the openlayers_views.module file.
I've added a new condition based on 3 checks:

  1. Is the style_plugin of the display 'views_geojson' ?
  2. Is the display 'page' ?
  3. Is the path set ?

If all those conditions are met, a new layer is constructed programmatically.
You can use that feature on any map you want and enjoy :-)

Remaining tasks

You tell me.

User interface changes

No change.

API changes

No change.

Original report by Pol

Comments

#1

Patch for 7.x-2.x.

AttachmentSizeStatusTest resultOperations
0001-1370448-Enable-GeoJSON-Layer-from-Views-using-views_.patch1.83 KBIdlePASSED: [[SimpleTest]]: [MySQL] 236 pass(es).View details

#2

Status:active» needs review

#3

Status:needs review» needs work

I can't speak about the functionality but try to keep code indentation and style consistent please.

I guess you could put the if as an elseif after the check for display_plugin. Like that i'm not sure it's going to work all the time. What about a view with several geojson display ?

maybe we should look at making a hook somewhere to avoid having to change the function at every new display_plugin

#4

Actually it should already be pluggable, have you tried to implement hook_openlayers_layers() in views_geojson module to declare layers from there ? I think it should be the way to go.

#5

Status:needs work» closed (fixed)

Thanks @Nod_, I wasn't aware of that hook.

This is closed and a new patch has been rolled for views_geojson.

#6

Cool, sorry haven't thought about it yesterday night :)

#7

Title:Enable GeoJSON Layer from Views (using views_geojson)» Provide GeoJSON Layers from Views (integrating with views_geojson)
Status:closed (fixed)» active

Hey @Pol and @nod_.

I think this would be better in this module, as I think we should move to having this method of providing Drupal data (views_geojson) as the preferred way. It seems more appropriate for the integration to be here, as we should be managing display. Overall, there's not a great argument either way, but I would rather have it here so that we can make it robust.

So, in that regard, @Pol, you patch is pretty good. There are some minor formatting things, like spaces, and your array strucutres, but otherwise its the right direction. I'll need to test it out a bit before committing though.

#8

Here's a new patch with a correct indentation, I hope :)

AttachmentSizeStatusTest resultOperations
0001-1370448-Enable-GeoJSON-Layer-detection-from-Openlaye.patch1.69 KBIdlePASSED: [[SimpleTest]]: [MySQL] 236 pass(es).View details

#9

Status:active» needs review

#10

Last patch had an error, it has been pasted 2 lines after the braces, so => error.
Here's a reroll of the patch corrected.

AttachmentSizeStatusTest resultOperations
0001-1370448-Enable-GeoJSON-Layer-detection-from-Openlaye.patch1.78 KBIdlePASSED: [[SimpleTest]]: [MySQL] 236 pass(es).View details

#11

Damn indentation !

AttachmentSizeStatusTest resultOperations
0001-1370448-Enable-GeoJSON-Layer-detection-from-Openlaye.patch1.77 KBIdlePASSED: [[SimpleTest]]: [MySQL] 236 pass(es).View details

#12

coming from #915708: Context Background and Overview of the mapping module
http://drupal.org/node/915708#comment-5485792

i will look into that, maybe i can do the same for views integration of the leaflet module #1338326: Added support for views and some configuration options

#13

Status:needs review» reviewed & tested by the community

yay, just tested this and it works!

  1. create a view with the geojson plugin
  2. assign the automatically created geojson layer to your openlayers map of choice

just a side note:
while testing i used (the old fashioned openlayers way) the same view for both generating geojson (display 1) and displaying the map (display 2). as i forgot to check to override the format setting for one of the displays, it changed the geojson format to map and therefor produced the following error

Notice: Trying to get property of non-object in _openlayers_layers_process_sort() (line 60 of /.../modules/openlayers/includes/openlayers.render.inc).
Warning: usort() [function.usort]: Array was modified by the user comparison function in _openlayers_layers_process() (line 34 of /.../modules/openlayers/includes/openlayers.render.inc).

#14

Weird error, can you reproduce it ?

Do you think it's related to my patch ?

#15

Status:reviewed & tested by the community» needs work

Working great for me so far; thanks Pol!

Layer names weren't showing up properly for me, and this helped:

         $layer->api_version = 1;
         $layer->name = $view->name . '_' . $display;
         $layer->title =
-          !empty($view->display['default']->handler->options['title']) ?
-            $view->display['default']->handler->options['title'] :
+          !empty($data->display_title) ?
+            $data->display_title :
             $view->name;
-        $layer->description = $view->description . ' - ' . $layer->title;
+        $layer->description = $view->description . ' - ' . $data->display_title;
         $layer->data = array(
           'layer_type' => 'openlayers_layer_type_geojson',
           'url' => url($view->display_handler->get_option('path'), array('absolute' => TRUE)),

#16

Status:needs work» needs review

Thanks for testing it ;-)

Patch updated with recommandations from @jeffschuler.

AttachmentSizeStatusTest resultOperations
0001-1370448-Enable-GeoJSON-Layer-detection-from-Openlaye_1.patch.txt1.71 KBIgnored: Check issue status.NoneNone

#17

Status:needs review» reviewed & tested by the community

Great, thanks!
Back to RTBC.

#18

I'm not going to mess with RTBC status here at the moment, but I'm working on adding support for BBOX filtering that's now in Views GeoJSON 7.x-1.x-dev.

The bbox string is being queried and dealt with properly in the first request for the map (and upon enabling other layers,) but dragging/zooming around doesn't re-request data as I'd expect it to.

This diff is against OL + patch in #16:

diff --git a/plugins/layer_types/openlayers_layer_type_geojson.js b/plugins/layer_types/openlayers_layer_type_geojson.js
index a2eb38e..f9750cf 100644
--- a/plugins/layer_types/openlayers_layer_type_geojson.js
+++ b/plugins/layer_types/openlayers_layer_type_geojson.js
@@ -12,7 +12,6 @@ Drupal.openlayers.layer.geojson = function(title, map, options) {
   var features = null;
   options.projection = 'EPSG:' + options.projection;
   options.styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID);
-  var layer = new OpenLayers.Layer.Vector(title, options);

   // GeoJSON Projection handling
   var geojson_options = {
@@ -20,6 +19,15 @@ Drupal.openlayers.layer.geojson = function(title, map, options) {
     'externalProjection': new OpenLayers.Projection(options.projection)
   };

+  // Use BBOX strategy.
+  options.strategies = [ new OpenLayers.Strategy.BBOX() ];
+  options.protocol = new OpenLayers.Protocol.HTTP({
+    url: options.url,
+    format: new OpenLayers.Format.GeoJSON(geojson_options),
+  });
+
+  var layer = new OpenLayers.Layer.Vector(title, options);
+
   // If GeoJSON data is provided with the layer, use that
   if (options.geojson_data) {
     // Read data in.

Thoughts appreciated!

#19

Status:reviewed & tested by the community» fixed

Thanks for the patch and reviews! Committed:
http://drupalcode.org/project/openlayers.git/commit/b25cd7f

Let's move the BBOX strategy to a new issue.

#20

#21

Status:fixed» closed (fixed)

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

nobody click here