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

Checking zoom level for cluster distance too slow #28

Open
peer35 opened this issue Aug 25, 2020 · 3 comments
Open

Checking zoom level for cluster distance too slow #28

peer35 opened this issue Aug 25, 2020 · 3 comments
Assignees
Labels
bug Something isn't working kloosters

Comments

@peer35
Copy link
Member

peer35 commented Aug 25, 2020

Works at the moment but is too clunky:

            let start=parseInt(this.map.getView().getZoom());
            let end=this.map.getView().getZoom();
            this.map.on(['movestart', 'moveend'], function(e) {
                if (e.type == 'movestart') {
                    start=parseInt(e.map.getView().getZoom());
                } else if (e.type == 'moveend') {

                    end=parseInt(e.map.getView().getZoom());
                    if (start!==end) {
                        console.log(end);
                        //SharedEventBus.$emit('change-resolution', end);
                        // Update cluster distances
                        me.updateClusters(end);
                    }
                }

            });
@peer35
Copy link
Member Author

peer35 commented Aug 25, 2020

            updateClusters(zoom){
                var layers = this.map.getLayers();
                layers.forEach(function (layer) {
                    if (layer instanceof VectorLayer) { // should set a generic vector/tile type
                        const source = layer.getSource();
                        if (source instanceof Cluster) {
                            if (typeof layer.get('cluster_zoomlevel')!=='undefined') {
                                if (layer.get('cluster_zoomlevel') <= zoom) {
                                    console.log('set cluster distance to 0');
                                    source.setDistance(0);
                                } else {
                                    source.setDistance(layer.get('cluster_distance'));
                                }
                            }
                        }
                    }
                });
            },

@peer35
Copy link
Member Author

peer35 commented Aug 25, 2020

Set the cluster_zoomlevel at map level? That way we don't have to check every layer when zooming.

@peer35 peer35 added the bug Something isn't working label Aug 25, 2020
@peer35
Copy link
Member Author

peer35 commented Aug 25, 2020

            setViewOptions: function(view){
                let me=this;
                let resolution = view.getResolution();
                let clustered = true;
                if (resolution < me.$config.cluster_resolution) {
                    clustered = false;
                    me.updateClusters(false);
                }
                view.on('change:resolution', function () {
                    const zoom = view.getZoom();
                    const resolution = view.getResolution();

                    if (zoom % 1 == 0) {
                        console.log(resolution);
                        if (resolution < me.$config.cluster_resolution && clustered) {
                            clustered = false;
                            me.updateClusters(false);
                        } else if (resolution > me.$config.cluster_resolution && !clustered) {
                            clustered = true;
                            me.updateClusters(true);
                        }
                    }
                });
            },

Combination of using zoom level in combination with constrainResolution for detecting the end of the zoom action and resolution for the cutoff. This because zoom levels are calculated for the extent of the projection and so different for 3857 and 28992.
But, this works ok for 3857 and 28992, but the resolutions for 4326 are different because units are degrees, not meters.

I think there is no simple general solution for this. Either I shouldn't use it at all, or make it a special extension option for kloosters and kerken that works in 28992 and 3857.

peer35 added a commit that referenced this issue Sep 1, 2020
peer35 added a commit that referenced this issue Sep 1, 2020
peer35 added a commit that referenced this issue Sep 1, 2020
peer35 added a commit that referenced this issue Sep 1, 2020
@peer35 peer35 self-assigned this Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working kloosters
Projects
None yet
Development

No branches or pull requests

1 participant