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

Idea about how to detect whether a layer is actually showing something in the current view extent #278

Open
mapcentia opened this issue Mar 12, 2019 · 5 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@mapcentia
Copy link
Collaborator

Vidi users have requested a visual indication of whether a layer is actually showing something in the current view extent. An idea is to check the bitmap tile of a layer for transparency. If it's 100% transparent a visual indicator in the layer tree will be switch on.
Could this be done using a canvas element?

@mapcentia mapcentia added enhancement New feature or request question Further information is requested labels Mar 12, 2019
@sashuk
Copy link
Owner

sashuk commented Mar 12, 2019

@mapcentia Could you please specify if this feature supposed to be working only for raster tile layers?

@mapcentia
Copy link
Collaborator Author

@mapcentia yes

@sashuk
Copy link
Owner

sashuk commented Mar 12, 2019

@mapcentia Leaflet uses canvas to draw tiles, so it can be checked if anything is drawn on it, I will check it!

@sashuk sashuk removed the question Further information is requested label Mar 12, 2019
@sashuk
Copy link
Owner

sashuk commented Mar 14, 2019

Following script answers the question is specific canvas empty?:

$('canvas').each((index, canvas) => {
    let canvasHasData = false;
    let data = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data;
    for (let key in data) {
        if (data[key] !== 0) {
            console.log('First not 0 value for ' + index + ' (' + data[key] + '), exiting');
            canvasHasData = true;
            break;
        }
    }    

    console.log('Canvas ' + index + ' has data: ' + canvasHasData);
});

Problems:

  • using the getImageData() is pretty slow

Researching further

@sashuk
Copy link
Owner

sashuk commented Mar 14, 2019

@mapcentia Whenever tile layer is loaded, its canvas is checked for data (if there is data, then the green 👁️ icon appears near the layer name). When user moves away (including the buffer), then icon becomes hidden.

The code is in separate branch https://github.com/sashuk/vidi/tree/tile-content or you can test it at https://vidi.alexshumilov.ru/app/aleksandrshumilov/public/#stamenTonerLite/4/60.293/35.8534/public.polygons

However, the solution (1) makes application very slow and (2) buffered data (which can be already hidden from user) is taken into account anyway. For now I have not found how to get the part of canvas which is actually in viewport.

Demo:
singletile

@sashuk sashuk added the question Further information is requested label Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants