Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated Cluster - Unable to get property of '0' of undefined or null reference #2

Closed
wlerner opened this issue Dec 2, 2015 · 4 comments

Comments

@wlerner
Copy link

wlerner commented Dec 2, 2015

If the extent is changed too quickly (i.e., a user zooms in and out rapidly) when there are clusters displayed on the map, an error can sometimes be generated. There does not appear to be any code to check if the features length is undefined.

Unable to get property '0' of undefined or null reference

The error occurs at line 57 in animatedclusterlayer.js section below:

/** @private Get the cluster that contains a feature
*/
ol.layer.AnimatedCluster.prototype.getClusterForFeature = function(f, cluster)
{   for (var j=0, c; c=cluster[j]; j++)
    {   var features = cluster[j].get('features');
        //if (features.length > 1) 
        for (var k=0, f2; f2=features[k]; k++)   <== Error Here
        {   if (f===f2) 
            {   return cluster[j];
            }
        }
    }
    return false;
}

error pic 4

This error can be reproduced under Google Chrome and Internet Explorer.

@Viglino
Copy link
Owner

Viglino commented Dec 3, 2015

Right! I've added a test to verify the integrity of the cluster.
Thanks for reporting this bug.

@wlerner
Copy link
Author

wlerner commented Dec 3, 2015

The length verification fix above works wonderfully. There is another section of code where this error is now occurring.

Unable to get property '0' of undefined or null reference

The error occurs at line 101 in animatedclusterlayer.js section below:

        for (var i=0, c0; c0=a.cA[i]; i++)
        {   var f = c0.get('features')[0];     <== Error Here
            var c = this.getClusterForFeature (f, a.cB);
            if (c) a.clusters.push({ f:c0, pt:c.getGeometry().getCoordinates() });
        }

error pic 7

This error can be reproduced under Google Chrome, Firefox 42, and Internet Explorer 11.
Thanks for looking into this issue.

@Viglino
Copy link
Owner

Viglino commented Dec 4, 2015

Yep! I now test if the feature is a consistent cluster.
Thanks for taking care of my bugs!

@wlerner
Copy link
Author

wlerner commented Dec 7, 2015

You are welcome! I appreciate all of your hard work. Thank you for sharing your code and expertise with the OL3 community. The last commit solved the problem quite nicely. I will close the issue.

@wlerner wlerner closed this as completed Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants