Latest Updates:

Can everyone please try to reproduce this issue on 7.x-2.0-beta7, it was introduced by feature enhancements that were committed but not properly tested. The 2 issues for those are:

#1516758: 2.X: Zoom to cluster: 2.X: Zoom to cluster (Patch - https://www.drupal.org/files/1516758-zoomtofeature-26.patch)
#2038463: Automatically zoom into cluster when layer only has 1 feature which is a cluster: Automatically zoom into cluster when layer only has 1 feature which is a cluster (Patch - https://www.drupal.org/files/openlayers-zoom-to-layer-cluster-zoom-3.patch)

The patch in #8 reverted the feature's properly when the dev release was at that state but may be broken now, I need to reroll the patch but haven't had time to get to this yet. You could quite easily revert the patches linked above (these were what were committed).

I also remember from experience sometimes I was getting false positives, as in, I'd turn off the features and the bug still persisted but it wasn't until I nuked every cache in existence before each page load that I was able to nail down the root of the problem. Apologies for not being able to reroll the patch just yet.

Original Post:

This is a really strange bug and it took me a long time to figure out what was actually going wrong, I'll try to explain as best I can:

I have a large dataset of points over New Zealand with clusters enabled. What is happening is when ANY interaction other than simple zooming occurs, the Openlayers feature which appears first in the cluster (i.e if you were to use popups it would appear at the top of the list, which seems to be alphabetic) seems to remember the location of the cluster and either a) the point shows at that location rather than the real location, or b) the popup for that point will appear at that location. I can replicate this on my map in a number of ways:

1) Firstly, if there's a large cluster that then gets split into smaller clusters when zooming in, the point which was the first feature in the original cluster will either appear in the location of the original cluster OR the popup will appear in that location:

cluster1.pngcluster2.png

2) Secondly, using the Zoom to cluster functionality on a small cluster will make the first feature of the cluster appear at the cluster's location rather than it's actual location:

cluster2.1.png

After clicking to zoom:

cluster2.2.png

After zooming with mouse scroll.

cluster2.3.png

These are just 2 examples of ways to trigger this strange behaviour but it's currently a massive issue since any "special" type of interaction with clusters causes data integrity to be lost.

If someone starts helping me on this I am happy to provide database exports etc as I imagine this will be extremely hard to reproduce.

I found this originally on beta7, moving to --dev did not fix it, neither did upgrading the openlayers library to 2.13.

Comments

acbramley’s picture

Priority:Normal» Critical
acbramley’s picture

Bumping this issue as we urgently need help with this, we've noticed some pretty serious plotting integrity issues that change the location of the points depending on clustering threshold settings.

acbramley’s picture

StatusFileSize
new5.96 KB

An extract of my lat lon points are attached. I will work on getting these into a vanilla drupal instance soon.

acbramley’s picture

I believe this may be occuring as a side effect of the "zoom to cluster" functionality I developed for the module as part of the Popup behaviour. - Finally confirmed this is not the case, shrunk my dataset to 6 points and disabled zoomtocluster and got other points breaking.

If I disable it the issue seems to go away (I had tested this previously and thought I could reproduce it without that setting but maybe I mistested something).

I can confirm that it is an issue with where Openlayers thinks the point should be as the output of the following is identical for the cluster AND the point when that setting is enabled:

  console.log(feature.geometry.getBounds().getCenterLonLat());

I added this just above where the popup var is created in openlayers_behaviour_popup.js

acbramley’s picture

This may help track it down:

Using the latest dev version of the zoom to layer code over the beta7 release, with zoom to layer enabled I can get this happening on map load, with the stock 7.x-2.0-beta7 it does not happen.

acbramley’s picture

Looks like the accumulate_extent function is at least one of the issues here. This is a function I extended with a patch to auto zoom into a cluster if there was only 1 feature on the layer and it was a cluster. I thought I could test this by using:

    var featureCount = layer.features.length;
    // If there is only one feature and it's a cluster, zoom into that cluster.
    if (featureCount == 1 && layer.features[0].cluster) {

But I have just discovered that layer.features.length returns 1 even though I console.log(layer) and see an attribute "features" with length 4. Very confused.

acbramley’s picture

After much testing last night, I came to the conclusion that BOTH the zoomtolayer enhancement to zoom into a cluster, and the popup behaviour to zoom to a cluster were causing these issues. It strikes me that the API may have slightly changed as the information returned by layer.features does not give you any way of determining how many clusters are on the map, which means it's impossible to determine if there's 1 cluster and to zoom into it.

Further more, the popup zoom behaviour is causing issues, but I'm not sure why. The code seems logical, but upon zooming the points get muddled up.

acbramley’s picture

Issue summary:View changes
StatusFileSize
new1.46 KB
Test request sent.
[ View ]

Attached patch to revert the zoom to layer single cluster functionality

Arjandew’s picture

#8 worked for me

acbramley’s picture

Status:Active» Reviewed & tested by the community

Yeah this needs to be committed and a proper solution needs to be worked out for adding that functionality back in. I am curious how that code caused the issues it did as well.

Pol’s picture

Can't wait to see a proper solution guys !

joebest’s picture

acbramley,
The patch did not work.

Plus I had to revert from the latest dev (2014-Apr-23) to beta 9 because of:

  1. strange overlay behavior
  2. custom marker styles are broken

let me know if I should open an separate issue.

kind regards,
Jose

joebest’s picture

  1. strange overlay behavior. This has been reported: Layer gets pushed down in map
  2. custom marker styles are broken
lodey’s picture

#8 didn't work for me unfortunately. I tried this first on the beta 9 release, then upgraded to the latest dev release (Apr) and tried again with no luck.

I can confirm we have the exact same issue. One of the points inside the cluster always adopts the position of the cluster itself - exactly as described above.

basvredeling’s picture

I believe this also causes an issue with the geofield proximity filter.
If both "zoom to layer" and "cluster" behaviours are set and if I have an exposed geofield proximity filter, one of the behaviours will relocate the first feature of the result set to the absolute center of the zoom extent.

To reproduce:
# create a node type with a geofield wkt or lat-lon
# create an openlayers map + views datalayer +view map display
# add geofield proximity filter to a map... expose it and have it look up locations via geocoded value from Google geocoder
# enable both clustering and zoom to layer behaviours
# generate a bunch of nodes via devel_generate
# look up nodes within 100 kms from "Amsterdam" (if your generated nodes set actually fall within this radius)
# zoom in all the way... you'll end up at the first map pin of your result set which shouldn't be located exactly at the projected location

acbramley’s picture

Status:Reviewed & tested by the community» Needs work

Can everyone please try to reproduce this issue on 7.x-2.0-beta7, it was introduced by feature enhancements that were committed but not properly tested. The 2 issues for those are:

#1516758: 2.X: Zoom to cluster
#2038463: Automatically zoom into cluster when layer only has 1 feature which is a cluster

The patch in #8 reverted the feature's properly when the dev release was at that state but may be broken now, I need to reroll the patch but haven't had time to get to this yet.

djh007’s picture

I chose Openlayers for the clustering feature and it's disappointing that it is not usable :(

I just installed 7.x-2.0-beta9, but still the map wrongly positions one of the location points to the place where the original cluster marker position was located, Zooming using the zoom bar does not create this behaviour, but zoom-on-click does.

djh007’s picture

I tried using the patch in #8 on 7.x-2.0-beta9 and 7.x-2.x-dev with no success.

acbramley’s picture

Issue summary:View changes
acbramley’s picture

Issue summary:View changes
acbramley’s picture

Status:Needs work» Needs review
StatusFileSize
new5.88 KB
Test request sent.
[ View ]

Ok, finally managed to try to generate a patch against 2.x that removes the functionality introduced in the issues mentioned in the summary.

To test, please try to test this using a fresh drupal install, I have seen many occurrences of forceful caching giving false positives with this bug.

I haven't had a chance to test this myself.

joebest’s picture

Hi,
I downloaded beta 7, applied the following patches as listed below. The zoom to cluster feature is gone but everything else seems to be working ok.

Patches I applied to Beta 7:

  1. https://www.drupal.org/files/1516758-zoomtofeature-26.patch
  2. https://www.drupal.org/files/openlayers-zoom-to-layer-cluster-zoom-3.patch
  3. https://www.drupal.org/files/issues/2116437-revert-cluster-functionality...

  • Pol committed 95ffdf8 on 7.x-2.x authored by acbramley
    Issue #2116437 by acbramley: Clustering seems to make first feature of...
Pol’s picture

Status:Needs review» Fixed

Thanks for your insights all, I've committed the patch in #21 by acbramley, booyah !

@joebest: you may now use 7.x-2.x instead of a patched beta7 ;-)

acbramley’s picture

Apologies to all who were affected by my feature enhancements, I'm glad that we've got this resolved now! :)

joebest’s picture

@Pol: I updated to the latest dev version but the following options in Pop Up for Features are gone:

  • Zoom to point: When a point is clicked, zoom to it instead of displaying a popup.
  • Zoom to cluster: When a cluster is clicked, zoom to it instead of displaying a popup.
Pol’s picture

Yes, I reverted the feature, it was causing some problems. I hope a new patch will fix that.

Status:Fixed» Closed (fixed)

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

Ericmaster’s picture

Priority:Critical» Normal
Status:Closed (fixed)» Needs work

In my case I needed the zoom to cluster functionality, so I tried to figure out what was wrong with, sorry I hadn't had time to make a patch since I've been working on a forked version of the plugin behavior that I needed for a specific project but solution is simple, in the onSelect event handler for the popup the fullExtent variable references to the bounds of the first feature, so when we apply extent to it, the first feature location gets modified. So, solution was to create new empty bounds and then extend from first feature instead of using first feature as initial base

<?php
  fullExtent
= new OpenLayers.Bounds();
  for (var
i = 0; i < feature.cluster.length; i++) {
    var
point = feature.cluster[i];
   
fullExtent.extend(point.geometry.getBounds());
  }
?>

Zoom to cluster is a really nice feature to have when using clusters. I'm sorry for not having have time to make a proper patch, if somebody can do it so we can have this feature back I'll appreciate it.

acbramley’s picture

@Ericmaster it's really hard to make a patch from a code snippet when there's no indication of the file or where this change occurs. Could you please indicate at least file names and line numbers? Or you could easily create a patch by doing the following:

git clone http://git.drupal.org/project/openlayers.git
git checkout 7.x-2.x

Copy your new file into the git repo in the correct location. And from the git repo root:

git diff --relative > 2116437-zoom-to-cluster.patch

Upload that file. Although this should be split into a new issue, or reopen #1516758: 2.X: Zoom to cluster and post it there.

Cheers

Ericmaster’s picture

@acbramley I'm sorry, I thought it was going to be clear considering we were discussing zoom to cluster functionality in popup behavior, obviously I was mistaken. File is openlayers_behavior_popup.js within the plugins/behaviors directory, look around line 72. I might have a bit time during the weekend, if somebody hasn't already I'll create a patch then. Reason why I haven't created the patch yet is that I forked the behavior and completely modified it to my needs, but I'll do the modifications from a fresh copy and create the patch during the weekend.

Regarding to (re-)opening a separate issue, patch will attempt to fix what it's stated in the title of current issue, so it would make more sense to me to post it here, splitting to a new issue might be misleading, don't you agree?

acbramley’s picture

Status:Needs work» Closed (fixed)

@Ericmaster Ok cool sounds good (re patch)

Re: opening a new issue, no, this issue was closed (fixed) in #28 as it was a fix to a feature enhancement that I wrote. The patch was to revert all that code to make things work normally again. I'm just going to close this again as it's going to confuse too many people. Please open a new issue with your patch :) Thanks.

ErosMike88’s picture

From "openlayers_behavior_popup.js":

Original version:

// Check if we have any zoom settings set. If zoom to point is enabled,
// it will disable the popup behavior for points,
// and the same for clusters.
if (options.zoomToPoint || options.zoomToCluster) {
var fullExtent;
// If we have zoomToCluster enabled and the feature is a cluster,
// accumulate the fullExtent of all points in the cluster.
var isCluster = typeof feature.cluster != 'undefined' && feature.cluster.length > 1;
if (options.zoomToCluster && isCluster) {
for (var i = 0; i < feature.cluster.length; i++) {
point = feature.cluster[i];
if (fullExtent instanceof OpenLayers.Bounds) {
fullExtent.extend(point.geometry.getBounds());
} else {
fullExtent = point.geometry.getBounds();
}
}
}
// Otherwise, if zoomToPoint is enabled and it's not a cluster, set
// the fullExtent to the bounds of the point.
else if (options.zoomToPoint && !isCluster){
fullExtent = feature.geometry.getBounds();
}

Corrected version (with the correction in bold):

// Check if we have any zoom settings set. If zoom to point is enabled,
// it will disable the popup behavior for points,
// and the same for clusters.
if (options.zoomToPoint || options.zoomToCluster) {
var fullExtent;
// If we have zoomToCluster enabled and the feature is a cluster,
// accumulate the fullExtent of all points in the cluster.
var isCluster = typeof feature.cluster != 'undefined' && feature.cluster.length > 1;
if (options.zoomToCluster && isCluster) {
for (var i = 0; i < feature.cluster.length; i++) {
point = feature.cluster[i];
if (fullExtent instanceof OpenLayers.Bounds) {
fullExtent.extend(point.geometry.getBounds());
} else {
fullExtent = feature.geometry.getBounds();
}
}
}
// Otherwise, if zoomToPoint is enabled and it's not a cluster, set
// the fullExtent to the bounds of the point.
else if (options.zoomToPoint && !isCluster){
fullExtent = feature.geometry.getBounds();
}

So now every marker will go back to its original places after they become not part of a cluster! :)

acbramley’s picture