danzel / Leaflet.utfgrid

A UTFGrid implementation for leaflet that is super small.
MIT License
131 stars 51 forks source link

Grid outside of layer boundaries. #21

Closed webdobe closed 10 years ago

webdobe commented 11 years ago

I have a base map layer that fits the whole map div (which has no data caked in). I have added a layer that in this case is just 1 state surrounded by nothing but the base map. When you hover outside of the state map an empty data object is being passed and throwing errors for every mouse movement. The problem happens at:

line 145ish of source. var idx = this._utfDecode(data.grid[gridY].charCodeAt(gridX)),

basically the object passed for "data" is empty I believe the code at 142 needs to be looking for a null data object and an empty.

webdobe commented 11 years ago

I fixed by doing:

if (!data || Object.keys(data).length === 0) { return { latlng: e.latlng, data: null }; }

Is this a good fix? Should I submit a patch?

danzel commented 11 years ago

Sounds like it could be on the right track, would it be possible to upload an example? I'm interested in seeing how you have this set up so you get an empty data object.

dev-ndn-zz commented 10 years ago

I am just playing around with the plugin and had a problem at the same line. I have created my maps and exported .mbtiles-files with TileMill, and there I made the bounds small than a whole map. So this is why I got errors afterwards in the browser. The suggested code has stopped those errors for me.

gamecubate commented 10 years ago

Ditto. Indeed, webdobe's code fixes all. Thanks webdobe.

danzel commented 10 years ago

Can anyone please upload an example that causes the error so I can confirm and add the fix? thanks!

danzel commented 10 years ago

Awesome, thanks. Have pushed a new version with a fix, please test it out! :)