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

Reduce UTFGrid Tile Caching #3087

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/mmw/js/src/draw/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ var DrawWindow = Marionette.LayoutView.extend({
model: this.model,
resetDrawingState: resetDrawingState
}));

this.listenTo(App.map, 'change:lat, change:lng', resetDrawingState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be having a wider impact than intended, for other workflows. For example, if you geocode within the same city, the map moves only slightly, but the loaded boundary layer is removed. Was this meant to be targeted only at the free-hand draw tool?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I think this is too wide-ranging. I think it makes sense to do this for both free-draw and boundary, especially if it helped with the UtfGrid caching issue, but since it doesn't I don't think we should keep it. I'm going to close this PR.

},

resetDrawingState: function(options) {
Expand Down Expand Up @@ -690,13 +692,23 @@ var SelectBoundaryView = DrawToolBaseView.extend({

changeOutlineLayer: function(tileUrl, layerCode, shortDisplay, minZoom) {
var self = this,
ofg = self.model.get('outlineFeatureGroup');
ofg = self.model.get('outlineFeatureGroup'),
// Generate 50 random strings to append to UtfGrid requests so we
// don't use the cached verions, which may be incorrect.
// The tiler may sometimes generate incorrect tiles because of
// https://github.com/CartoDB/Windshaft/issues/310
cacheBusters = _.range(50).map(function() {
// Generate and return a random string
// https://stackoverflow.com/a/8084248
return Math.random().toString(36).substring(7);
});

// Go about the business of adding the outline and UTFgrid layers.
if (tileUrl && layerCode !== undefined) {
var ol = new L.TileLayer(tileUrl + '.png', {minZoom: minZoom || 0}),
grid = new L.UtfGrid(tileUrl + '.grid.json',
grid = new L.UtfGrid(tileUrl + '.grid.json?{s}',
{
subdomains: cacheBusters,
minZoom: minZoom,
useJsonP: false,
resolution: 4,
Expand Down