Download & Extend

geoJSON data from URL breaks openlayers map

Project:OpenLayers
Version:7.x-2.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Problem/Motivation

Problem Behavior

Using geoJSON Layer Type works fine if giving arbitrary GeoJSON Data on (/admin/structure/openlayers/layers/list/).

However, if using the URL option it is breaking the openlayers map. If it is set up to use URL (without any GeoJSON Data) and this layer is enabled then the map is not displayed at all.

Technical Explanation

This issue is caused by how the geoJSON data is being loaded when the BBOX option is disabled.
If the BBOX option is enabled it loads correctly because it is being loaded from another part of the code.

In addition, the logic used to choose the BBOX strategy could share some common code with other strategies as well.

Modules versions

openlayers 7.x-2.0-beta1+83-dev
views_geojson 7.x-1.0-alpha2

Proposed resolution

  • Change how the geoJSON URL is loaded, making it similar to the code used for BBOX strategy.
  • Share code between BBOX, Fixed , and other possible strategies. Only the strategy type must be changed, all the remaining loading code is the same.

edit: moved this issue to openlayers module as the patch is against one of its files.
edit[2]: added better issue description

Comments

#1

Project:Views GeoJSON» OpenLayers
Version:7.x-1.0-alpha2» 7.x-3.x-dev

Moving to openlayers module.

#2

Including patch to fix this issue.

BBOX filter is not working, see #1806048: BBOX filter not working

AttachmentSizeStatusTest resultOperations
openlayers-fix_getting_geoJSON_layer_from_URL-1805844-2.patch2.32 KBIdlePASSED: [[SimpleTest]]: [MySQL] 238 pass(es).View details

#3

Status:active» needs review

#4

Status:needs review» needs work

The last submitted patch, openlayers-fix_getting_geoJSON_layer_from_URL-1805844-2.patch, failed testing.

#5

Status:needs work» needs review

#2: openlayers-fix_getting_geoJSON_layer_from_URL-1805844-2.patch queued for re-testing.

#6

Status:needs review» needs work

The last submitted patch, openlayers-fix_getting_geoJSON_layer_from_URL-1805844-2.patch, failed testing.

#7

Version:7.x-3.x-dev» 7.x-2.x-dev
Status:needs work» needs review

#8

#9

Changed OpenLayers documentation links to version 2.12, as suggested by zzolo

AttachmentSizeStatusTest resultOperations
openlayers-fix_getting_geoJSON_layer_from_URL-1805844-9.patch2.32 KBIdlePASSED: [[SimpleTest]]: [MySQL] 238 pass(es).View details

#10

Status:needs review» needs work

+++ b/plugins/layer_types/openlayers_layer_type_geojson.jsundefined
@@ -39,33 +39,28 @@ Drupal.openlayers.layer.geojson = function(title, map, options) {
-    var layer = new OpenLayers.Layer.Vector(title, options);
-
-    // Use an AJAX like call to get data from URL
-    OpenLayers.loadURL(options.url, {}, null, function (response) {
-      var format = new OpenLayers.Format.GeoJSON(geojson_options);
-      var features = format.read(response.responseText);
-      // Add features, if needed
-      if (features) {
-        layer.addFeatures(features);
-        layer.events.triggerEvent('loadend');
-      }
-    });

Are you sure about removing this part ?

#11

Status:needs work» needs review

@pol yes, I am sure. Test it.

I removed it because it can use the same code on the lines before it, and that's how this new code is handling this part on this logic.

#12

Status:needs review» fixed

Ok cool, committed then !

Thanks!

#13

Pol, your commit is not removing the part you asked me on #10.
That part is never used in the new logic.

http://drupalcode.org/project/openlayers.git/blob/148267ea2e75ac1addcb5b...

#14

Oops, looks like PHPStorm made a poo poo !

It's fixed again :)

http://drupalcode.org/project/openlayers.git/commitdiff/42bf5caacf03b729...

#15

Status:fixed» closed (fixed)

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