Currently when enable the bounding box strategy and drag the map round it doesn't always send a request to the server for more information from your layer.

I have attached a patch that lets you change the resFactor see resFactor when you set this to 1 it will send an update everytime the resolution of the bounding box changes.

This is under the "Use Bounding Box Strategy" checkbox in the layers screen

this is against 7.x-2.x

diff --git a/plugins/layer_types/openlayers_layer_type_geojson.inc b/plugins/layer_types/openlayers_layer_type_geojson.inc
index 69d9530..23a8a5f 100644
--- a/plugins/layer_types/openlayers_layer_type_geojson.inc
+++ b/plugins/layer_types/openlayers_layer_type_geojson.inc
@@ -66,6 +66,25 @@ class openlayers_layer_type_geojson extends openlayers_layer_type {
         '#description' => t('Bounding Box strategy will add a query string onto the GeoJSON URL, which means that only data in the viewport of the map will be loaded.  This can be helpful if you have lots of data coming from the feed.'),
         '#default_value' => isset($this->data['useBBOX']) ? $this->data['useBBOX'] : FALSE,
       ),
+      //see http://dev.openlayers.org/docs/files/OpenLayers/Strategy/BBOX-js.html#OpenLayers.Strategy.BBOX.resFactor
+      'resFactor' => array(
+        '#type' => 'select',
+        '#title' => t('Used to determine when previously requested features are invalid (set to 1 if unsure)'),
+        '#description' => t('The resFactor will be compared to the resolution of the previous request to the current map resolution.  <br />
+          If resFactor > (old / new) and 1/resFactor < (old / new). 
+          <ul>          
+          <li>If you set a resFactor of 1, data will be requested every time the resolution changes.  </li>
+          <li>If you set a resFactor of 3, data will be requested if the old resolution is 3 times the new, or if the new is 3 times the old.  </li>
+          <li>If the old bounds do not contain the new bounds new data will always be requested (with or without considering resFactor).</li>
+          </ul>
+          '),
+        '#options' => array(
+            1 => t('1'),
+            2 => t('2'),
+            3 => t('3')
+        ),
+        '#default_value' => isset($this->data['resFactor']) ? $this->data['resFactor'] : 1
+      ),
       'geojson_data' => array(
         '#type' => 'textarea',
         '#title' => t('GeoJSON Data'),
diff --git a/plugins/layer_types/openlayers_layer_type_geojson.js b/plugins/layer_types/openlayers_layer_type_geojson.js
index f694d26..e4e6420 100644
--- a/plugins/layer_types/openlayers_layer_type_geojson.js
+++ b/plugins/layer_types/openlayers_layer_type_geojson.js
@@ -39,7 +39,7 @@ Drupal.openlayers.layer.geojson = function(title, map, options) {
     }
   }
   else if (options.useBBOX) {
-    options.strategies = [ new OpenLayers.Strategy.BBOX() ];
+    options.strategies = [new OpenLayers.Strategy.BBOX(options.resFactor)];
     options.protocol = new OpenLayers.Protocol.HTTP({
       url: options.url,
       format: new OpenLayers.Format.GeoJSON(),

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

p4ul’s picture

As a patch

Status: Needs review » Needs work

The last submitted patch, openlayers_bbox_resfactor-1555292-1.patch, failed testing.

p4ul’s picture

fixed patch!

p4ul’s picture

Status: Needs work » Needs review
Pol’s picture

Status: Needs review » Needs work

Patch is working but some formatting problems here...

+++ b/plugins/layer_types/openlayers_layer_type_geojson.incundefined
@@ -66,6 +66,25 @@ class openlayers_layer_type_geojson extends openlayers_layer_type {
+          If resFactor > (old / new) and 1/resFactor < (old / new). ¶

Remove useless spaces.

+++ b/plugins/layer_types/openlayers_layer_type_geojson.incundefined
@@ -66,6 +66,25 @@ class openlayers_layer_type_geojson extends openlayers_layer_type {
+          <ul>          ¶

Remove useless spaces.

+++ b/plugins/layer_types/openlayers_layer_type_geojson.incundefined
@@ -66,6 +66,25 @@ class openlayers_layer_type_geojson extends openlayers_layer_type {
+            1 => t('1'),
+            2 => t('2'),
+            3 => t('3')

Why t() here ?

jeffschuler’s picture

Thanks for implementing this, p4ul!
Besides the code style issues Pol raised, a few things:

  1. resFactor can be any float -- 1 and 3 are just examples -- and is NULL by default.
  2. I would make resFactor the #title, or better yet, Bounding Box resFactor.
  3. We can probably chop the first couple sentences off the #description, or otherwise make it more succinct.
p4ul’s picture

Thanks for the comments, t() was there so better explanations can be provided for each option the numbers where just a filler.
I will look at implementing those suggestions this week and resubmitting a patch.

p4ul’s picture

Hi,

Can you guys give me some feedback on this please.

Original line:

'Bounding Box strategy will add a query string onto the GeoJSON URL, which means that only data in the viewport of the map will be loaded. This can be helpful if you have lots of data coming from the feed.'

proposed:

'The Bounding Box strategy will improve performance by only loading data on the visible area of the map.'

Pol’s picture

Good for me :)

jeffschuler’s picture

@p4ul, I think that's a good improvement and we should go with it.
However, I was referring to the description for resFactor -- that's the long one...

Pol’s picture

Status: Needs work » Fixed

Committed, thanks !

jeffschuler’s picture

Status: Fixed » Needs work

Please see my comments in #6, particularly:

resFactor can be any float -- 1 and 3 are just examples -- and is NULL by default.

Pol’s picture

Status: Needs work » Fixed
jeffschuler’s picture

For reference, commits 3150369 and fdc4e58.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

missed out default value when copying