-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Indexed vector sources #1377
Indexed vector sources #1377
Changes from all commits
9b91ca7
1fa5f37
2e90988
0caefd7
cea6ca4
dbe8533
838048e
8c93f73
340c79a
0d90c5d
051fffb
507fe72
53eb537
f3bc25b
e6e7736
b8c3092
a3b3371
b7fd5d7
a94d882
8362c6d
4a854be
c5f91bd
fa0e42a
64b0916
bc54795
0a6807b
8140de4
6a1fee7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,8 @@ function TilePyramid(options) { | |
this.maxzoom = options.maxzoom; | ||
this.roundZoom = options.roundZoom; | ||
this.reparseOverscaled = options.reparseOverscaled; | ||
// esri/chelm | ||
this.index = options.index; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make sure the index is accessible on the tile pyramid |
||
|
||
this._load = options.load; | ||
this._abort = options.abort; | ||
|
@@ -271,6 +273,10 @@ TilePyramid.prototype = { | |
var zoom = coord.z; | ||
var overscaling = zoom > this.maxzoom ? Math.pow(2, zoom - this.maxzoom) : 1; | ||
tile = new Tile(wrapped, this.tileSize * overscaling); | ||
// esri/chelm | ||
if (this.index) { | ||
tile.parentId = this.indexSearch(coord.id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When a tile is added to the map, we search the pyramid's index for a "parentId". A parentId should only exist when a requested tile is not found in the tile index. The index is searched recursively until the next lowest zoom level tile is found. After explaining that I think the name "parentId" should be changed to be a bit more representative of what it is... |
||
} | ||
this._load(tile); | ||
} | ||
|
||
|
@@ -372,5 +378,54 @@ TilePyramid.prototype = { | |
} | ||
|
||
return result; | ||
}, | ||
|
||
/** | ||
* For a given tile id find its parent tile from the index | ||
* @param {string|number} id tile id | ||
* @returns {Object} tile | ||
* @private | ||
*/ | ||
indexSearch: function (id) { | ||
var tile = TileCoord.fromID(id); | ||
|
||
var ids = [id]; | ||
|
||
var parentTile = tile; | ||
while (parentTile.z !== 0) { | ||
parentTile = parentTile.parent(); | ||
ids.push(parentTile.id); | ||
} | ||
|
||
var cursor = this.index, | ||
cursorId = ids.pop(), | ||
index; | ||
|
||
var pluckId = function (coord) { | ||
return coord.id; | ||
}; | ||
|
||
while (ids.length) { | ||
id = ids.pop(); | ||
tile = TileCoord.fromID(cursorId); | ||
index = tile.children(this.maxzoom).map(pluckId).indexOf(id); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this hot code? Seems like the creation of function, a parallel array, and then another There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inefficient code for sure, can be much cleaner. A single loop would do what we need. |
||
if (cursor) { | ||
if (cursor[index] === 0) { | ||
cursorId = id; | ||
break; | ||
} else if (cursor[index] === 1) { | ||
cursorId = id; | ||
break; | ||
} else { | ||
cursorId = id; | ||
cursor = cursor[index]; | ||
} | ||
} | ||
} | ||
|
||
// don't return a parentId if we found the original tile | ||
if (ids.length === 0) return null; | ||
|
||
return cursorId; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
var util = require('../util/util'); | ||
var Evented = require('../util/evented'); | ||
var Source = require('./source'); | ||
var TileCoord = require('./tile_coord'); | ||
|
||
module.exports = VectorTileSource; | ||
|
||
|
@@ -72,9 +73,15 @@ VectorTileSource.prototype = util.inherit(Evented, { | |
overscaling: overscaling, | ||
angle: this.map.transform.angle, | ||
pitch: this.map.transform.pitch, | ||
collisionDebug: this.map.collisionDebug | ||
collisionDebug: this.map.collisionDebug, | ||
parentId: tile.parentId | ||
}; | ||
|
||
// request the tile parentID if it exists | ||
if (tile.parentId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaict this is the first change I've seen that modifies existing behavior rather than extending it with a new source type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. If a tile has a parentId the url for the tile request needs to be used in place of the url built from |
||
params.url = TileCoord.fromID(tile.parentId).url(this.tiles, this.maxzoom); | ||
} | ||
|
||
if (tile.workerID) { | ||
this.dispatcher.send('reload tile', params, this._tileLoaded.bind(this, tile), tile.workerID); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ function WorkerTile(params) { | |
this.stacks = {}; | ||
} | ||
|
||
WorkerTile.prototype.parse = function(data, layers, actor, callback) { | ||
WorkerTile.prototype.parse = function(data, layers, actor, callback, dz, xPos, yPos) { | ||
|
||
this.status = 'parsing'; | ||
|
||
|
@@ -104,16 +104,22 @@ WorkerTile.prototype.parse = function(data, layers, actor, callback) { | |
layer = data.layers[k]; | ||
if (!layer) continue; | ||
if (layer.extent) extent = layer.extent; | ||
sortLayerIntoBuckets(layer, bucketsBySourceLayer[k]); | ||
sortLayerIntoBuckets(layer, bucketsBySourceLayer[k], dz, xPos, yPos); | ||
} | ||
} else { | ||
// geojson | ||
sortLayerIntoBuckets(data, bucketsBySourceLayer); | ||
} | ||
|
||
function sortLayerIntoBuckets(layer, buckets) { | ||
function sortLayerIntoBuckets(layer, buckets, dz, xPos, yPos) { | ||
for (var i = 0; i < layer.length; i++) { | ||
var feature = layer.feature(i); | ||
var feature = layer.feature(i); | ||
|
||
// propagate clipped position in tile at the feature level | ||
feature.dz = dz; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the changes in worker_tile.js are passing on the dz, xpos, and ypos params. Ultimately these come down to Vector-tile-js and the parsing and rendering of geometries there. (separate PR). |
||
feature.xPos = xPos; | ||
feature.yPos = yPos; | ||
|
||
for (var key in buckets) { | ||
var bucket = buckets[key]; | ||
if (bucket.filter(feature)) { | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the entry point for the difference in behavior. If an index exists (as a url) on the data source "tileJSON" the index gets requested. The returned index is added to the tile pyramid.