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

Shaking raster map after easeTo\flyTo #7849

Closed
aliir74 opened this issue Jan 30, 2019 · 3 comments
Closed

Shaking raster map after easeTo\flyTo #7849

aliir74 opened this issue Jan 30, 2019 · 3 comments

Comments

@aliir74
Copy link

aliir74 commented Jan 30, 2019

Hi all.
I use raster tiles and want to keep the user in integer zoom level for prevent from blurry tiles.
on moveend event I call map.easeTo to nearest integer zoom level but after the end of the animation, my map and marker start shaking.
See this video for seeing this shaking:
https://vimeo.com/314318425

mapbox-gl-js version:
0.52.0
browser:
Google Chrome

Steps to Trigger Behavior

  1. Source raster tiles
  2. Use easeTo for keeping zoom level integer
map.on('moveend', _u.debounce(function() {
            map.easeTo({
                zoom: Math.round(map.getZoom()),
                speed: 0.3
            })
        }, 1000));

Link to Demonstration

https://docs.mapbox.com/mapbox-gl-js/api/#map#flyto

Expected Behavior

Change zoom to integer zoom level and fix map without shaking.

Actual Behavior

Easeto desire zoom level but with shaking after the end of easing

@asheemmamoowala
Copy link
Contributor

@aliir74 The moveend event is called after an easeTo even when the zoom doesn't actually change. This is what is causing the continuous map shake in your case. It can be easily addressed with a guard for a integer zoom, with something like:

        let currZoom = map.getZoom();
            if (Math.round(currZoom) !== currZoom) {

#7426 addresses a different form of raster shaking, and can be tested in the 0.53 beta

@aliir74
Copy link
Author

aliir74 commented Feb 3, 2019

Thanks, @asheemmamoowala. I added your code and use 0.53 beta and this work fine and map didn't shake anymore. But my pin is shaking yet.

I use this code for adding the marker to map:

var geojson = {
    type: 'FeatureCollection',
    features: [{
        type: 'Feature',
        geometry: {
            type: 'Point',
            coordinates: [{{ lon }}, {{ lat }}]
        }
    }]
};

function marker_load() {

    geojson.features.forEach(function (marker) {
        var el = document.createElement('div');
        el.className = 'marker';
        new mapboxgl.Marker(el)
            .setLngLat(marker.geometry.coordinates)
            .addTo(map);
    });
}

and call marker_load() after the creatation of mapboxgl.Map object.
and the css:

.marker {
    background-image: url('https://raah.ir/static/locator.png');
    position: absolute;
    background-size: cover;
    width: 67px;
    height: 165px;
    cursor: pointer;
}

@ivjia
Copy link

ivjia commented Aug 11, 2020

anyone can help? I still suffer this issue

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

3 participants