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

.setFilter() triggers vector tile requests #2198

Closed
knutole opened this issue Feb 27, 2016 · 6 comments
Closed

.setFilter() triggers vector tile requests #2198

knutole opened this issue Feb 27, 2016 · 6 comments
Labels

Comments

@knutole
Copy link

knutole commented Feb 27, 2016

Problem

When using .setFilter(), vector tiles that are already loaded get re-requested from server.

Requesting vector tiles when setting filter seems unnecessary and is a bit of a performance killer?

jsbin

See this jsbin for a working example.

Screen dump

tile_requests

Version

Mapbox-gl.js version: 0.14.3

Relevant code:

    var systemapic_access_token = 'pk.8FhhB90ax6KkQmoK0AMePd0R6IlkxM4VAGewsXw8';

    var systemapic = {
        "version": 8,
        "sources": {
            "vector-tiles": {
                "type": "vector",
                "tiles": ["https://dev.systemapic.com/v2/tiles/layer_id-5bff2873-83f3-4aa2-96f5-2e770f76199c/{z}/{x}/{y}.pbf?access_token=" + systemapic_access_token],
            },
            "norkart-tiles" : {
                "type" : "raster",
                "tiles" : ["https://proxy-txa.systemapic.com/v2/tiles/norkart/aerial/{z}/{x}/{y}.jpeg?access_token=" + systemapic_access_token],
                "tileSize" : 256
            }
        },
        "layers": [
            {
                "id": "background",
                "type": "raster",
                "source": "norkart-tiles",
                "minzoom": 0,
                "maxzoom": 22
            },
            {
                "id": "sydney",
                "type": "fill",
                "source": "vector-tiles",
                "source-layer": "layer",
                "filter": ["==", "$type", "Polygon"],
                "paint": {
                    "fill-color": "#3887be"
                },
                "interactive" : true
            }

        ]
    };

    var map = new mapboxgl.Map({
        container: 'map', // container id
        center : [-209, -34],
        zoom : 8,
        style : systemapic
    });

    map.on('mousemove', function (e) {

        map.featuresAt(e.point, {
            radius: 5,
            layers : ['sydney']
        }, function (err, features) {
            if (err) return console.log(err);

            if (features.length) {

                // set filter, paint
                map.setFilter('sydney', ["==", "gid", features[0].properties.gid]);

            } else {

                // set filter, paint
                map.setFilter('sydney', ["==", "$type", "Polygon"]);
            }
        });
    });
@knutole
Copy link
Author

knutole commented Feb 27, 2016

Could be related to #2174.

@knutole
Copy link
Author

knutole commented Feb 29, 2016

Or it this expected behavior? I'm interested because we're trying to implement this functionality for a client, and it's a bit of a "make or break" to get this working.

Would it be possible to used cached vector tiles instead of requesting new tiles, for example?

@lucaswoj
Copy link
Contributor

Thanks for the bug report! This is not expected behavior. We'll take a look soon.

@knutole
Copy link
Author

knutole commented Mar 3, 2016

Don't mean to rush anyone, but do you have an ETA for a fix?

@ansis
Copy link
Contributor

ansis commented Mar 3, 2016

Is your browser cache disabled when your console is open? The current implementation makes new xhr request whenever it needs to reparse a tile. This should hit the browser cache pretty much always.

Whenever a change to any layer definition or layout property the entire tile is reparsed. We plan to improve this by recreating only what changed, but there is no current eta for that.

@knutole
Copy link
Author

knutole commented Mar 3, 2016

Can confirm this has to do with cache. I was serving vector tiles with no-cache. Amending cache to private, max-age=3600 fixes the problem!

Thanks a lot for the tip! Closing.

@knutole knutole closed this as completed Mar 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants