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

Interaction confused by multiple tile layers? #95

Open
evz opened this issue Aug 9, 2011 · 4 comments
Open

Interaction confused by multiple tile layers? #95

evz opened this issue Aug 9, 2011 · 4 comments

Comments

@evz
Copy link

evz commented Aug 9, 2011

I'm attempting to create a map with 2 tile layers, one with street map level detail and a transparent overlay layer which defines some custom boundaries and which was generated using TileMill. Well, actually I took the mbtiles file and broke it out into a directory using mbutil, which it suddenly occurs to me may be the source of the issue...maybe I'll post this over there too...

Anyways, what seems to be happening is the interaction control is getting the info about which grid.json file to grab based on the bottom layer. so given this example (using Leaflet):

// This is setup on two VMs so the references to a server called 
// "tiles" is just me making an entry in /etc/hosts for dev purposes

var tilesUrl = 'http://{s}.tile.cloudmade.com/[my api key]/997/256/{z}/{x}/{y}.png',
tiles = new L.TileLayer(tilesUrl);
var locs = { 
    tilejson: '1.0.0',
    scheme: 'tms',
    tiles: ['http://tiles/wa-trans-loc/1.0.0/WA/{z}/{x}/{y}.png'], //
    grids: ['http://tiles/wa-trans-loc/1.0.0/WA/{z}/{x}/{y}.grid.json'],
    formatter: function(options,data){return data;}
};
var center = new L.LatLng(47.60793525258652, -122.36486434936522);
var options = {
    callbacks: {
        out: function(feature, context, index, evt){
        },
        over: function(feature, context, index, evt){
            console.log('over');
            console.log(feature);
        },
        click: function(feature, context, index, evt){
           console.log(context);
       }
    }
};
var map = new L.Map('map');
var loc_conn = new wax.leaf.connector(locs);
map.addLayer(tiles);
map.addLayer(loc_conn);
map.setView(center,9);
wax.leaf.interaction(map,locs,options);

What ends up happening is that the bottom layer, which in this case is the one from CloudMade, is what the interaction control is using to fetch the grid.json file. So, given this tile from CloudMade:

<img class="leaflet-tile leaflet-tile-loaded" style="width: 256px; height: 256px; left: 680px; top: 89px;" src="http://c.tile.cloudmade.com/[my-api-key]/997/256/9/82/178.png">

...the interaction control tries to fetch the grid.json file thusly: GET /wa-trans-loc/1.0.0/WA/9/82/178.grid.json?callback=grid HTTP/1.1. Which is what you'd expect, right? Except that when you look at the structure of the overlay tiles, there is no 178.grid.json file. And what's more confusing is that the tile that the overlay layer is loading for the same spot on the map is actually this one:

<img class="leaflet-tile leaflet-tile-loaded" style="width: 256px; height: 256px; left: 680px; top: 89px;" src="http://tiles/wa-trans-loc/1.0.0/WA/9/82/333.png">

The screwy thing is that if I stack the layers in the reverse order so that my overlay layer is on the bottom, it gets the grid.json file just fine. But putting it below the street map tiles kinda defeats the purpose of having an overlay in the first place.

I guess the real question I have here is: am I using this in a way that was entirely unintended? Is there an elegant workaround? Or is this really something that needs to be addressed?

@tmcw
Copy link

tmcw commented Aug 9, 2011

So the current issue is that TileMill / mbutil currently generates tiles in tms format, with a flipped Y coordinate, hence the discrepancy between 178 and 333 here. I haven't tested Leaflet interaction with multiple layers yet (given that we no longer use client-side compositing around here), but I can check it out and see if there's a way to make interaction always choose the top layer in Leaflet - something that I think is totally possible.

@evz
Copy link
Author

evz commented Aug 19, 2011

Wow. Sorry about the delayed response here (I was away from the office/interwebs for a while). I'll try to get back into this in the next few days and see if there's anything I might be able to discover. And maybe I'll actually post any findings in the correct place next time....heh.

@zzolo
Copy link

zzolo commented Apr 26, 2012

I can confirm this behavior. Though, I have not dug into the code yet.

@manelclos
Copy link

I can kind of reproduce this issue. I have exported a mbtiles archive using mb-util, then accessing it using wax + mm/leaf. The tiles are being loaded correctly (scheme: 'tms'), but grid data still uses the normal xyz, so y is wrong. Was is trying to load the json grid files in the correct layer, but with wrong y.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants