Skip to content

Commit

Permalink
Invalidate TileSource cache on property changes (#8594)
Browse files Browse the repository at this point in the history
* Invalidate TileSource cache on property changes

* Add unit test
  • Loading branch information
philippjfr authored and bryevdv committed Jan 30, 2019
1 parent 5705846 commit 989ddb5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions bokehjs/src/lib/models/tiles/tile_renderer.ts
Expand Up @@ -52,6 +52,7 @@ export class TileRendererView extends RendererView {
connect_signals(): void {
super.connect_signals()
this.connect(this.model.change, () => this.request_render())
this.connect(this.model.tile_source.change, () => this.request_render())
}

get_extent(): Extent {
Expand Down
21 changes: 20 additions & 1 deletion bokehjs/src/lib/models/tiles/tile_source.ts
Expand Up @@ -20,7 +20,17 @@ export namespace TileSource {
initial_resolution: number
}

export interface Props extends Model.Props {}
export interface Props extends Model.Props {
url: p.Property<string>
tile_size: p.Property<number>
max_zoom: p.Property<number>
min_zoom: p.Property<number>
extra_url_vars: p.Property<{[key: string]: string}>
attribution: p.Property<string>
x_origin_offset: p.Property<number>
y_origin_offset: p.Property<number>
initial_resolution: p.Property<number>
}
}

export interface TileSource extends TileSource.Attrs {}
Expand Down Expand Up @@ -60,6 +70,11 @@ export abstract class TileSource extends Model {
this._normalize_case()
}

connect_signals(): void {
super.connect_signals()
this.connect(this.change, () => this._clear_cache())
}

string_lookup_replace(str: string, lookup: {[key: string]: string}): string {
let result_str = str
for (const key in lookup) {
Expand All @@ -85,6 +100,10 @@ export abstract class TileSource extends Model {
this.url = url
}

protected _clear_cache(): void {
this.tiles = {}
}

tile_xyz_to_key(x: number, y: number, z: number): string {
return `${x}:${y}:${z}`
}
Expand Down
9 changes: 9 additions & 0 deletions bokehjs/test/models/tiles/tile_renderer.coffee
Expand Up @@ -131,6 +131,15 @@ describe "tile sources", ->
expect(t[0]).to.be.within(3, 4)
expect(t[1]).to.be.within(3, 4)

it "should invalidate cache on property change", ->
tile_options =
url : 'http://mock/{x}/{y}/{z}.png'
tile_source = new TileSource(tile_options)
tile = {tile_coords: [0, 1, 2]}
tile_source.tiles['mock_key'] = tile
tile_source.url = 'http://mock/{x}/{y}/{z}.png'
expect(tile_source.tiles).to.be.empty

describe "tms tile source", ->
url = 'http://c.tiles.mapbox.com/v3/examples.map-szwdot65/{Z}/{X}/{Y}.png'
source = new TMSTileSource({url: url})
Expand Down

0 comments on commit 989ddb5

Please sign in to comment.