mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
refactored getTilePolygons to TilesCore
This commit is contained in:
parent
40528f9b80
commit
69ecbc1ce6
@ -355,29 +355,7 @@ define([
|
||||
*/
|
||||
getTilePolygons : function(callback) // callback(Polygon polygon) or callback(null, error)
|
||||
{
|
||||
var store = this.offline.store;
|
||||
var tilingScheme = new TilingScheme(this);
|
||||
store.getAllTiles(function(url,img,err)
|
||||
{
|
||||
if(url && url.indexOf(layer.url) == 0)
|
||||
{
|
||||
var components = url.split("/");
|
||||
var level = parseInt(components[ components.length - 3],10);
|
||||
var col = parseInt(components[ components.length - 2],10);
|
||||
var row = parseInt(components[ components.length - 1],10);
|
||||
var cellId = [row,col];
|
||||
var polygon = tilingScheme.getCellPolygonFromCellId(cellId, level);
|
||||
//if( level == 15)
|
||||
callback(polygon);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!url)
|
||||
{
|
||||
callback(null,err);
|
||||
}
|
||||
}
|
||||
});
|
||||
this._tilesCore._getTilePolygons(this.offline.store,this.url,this,callback);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -10,8 +10,9 @@ define([
|
||||
"esri/layers/TileInfo",
|
||||
"esri/layers/LOD",
|
||||
"tiles/base64utils",
|
||||
"tiles/tilingScheme"
|
||||
],
|
||||
function(query,Point,Extent,SpatialReference,TileInfo,LOD,Base64Utils){
|
||||
function(query,Point,Extent,SpatialReference,TileInfo,LOD,Base64Utils,TilingScheme){
|
||||
"use strict";
|
||||
var TilesCore = function(){
|
||||
|
||||
@ -46,7 +47,53 @@ define([
|
||||
callback(false, e);
|
||||
};
|
||||
req.send(null);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets polygons representing all cached cell ids within a particular
|
||||
* zoom level and bounded by an extent.
|
||||
* @param store local IndexedDB
|
||||
* @param layerUrl the URL of tile layer
|
||||
* @param context a reference to the layer
|
||||
* @param callback callback(polygon, error)
|
||||
*/
|
||||
this._getTilePolygons = function(store,layerUrl,context,callback) // callback(Polygon polygon) or callback(null, error)
|
||||
{
|
||||
var components, level, col, row, cellId, polygon;
|
||||
|
||||
var tilingScheme = new TilingScheme(context);
|
||||
store.getAllTiles(function(url,img,err)
|
||||
{
|
||||
if(url && url.indexOf(layerUrl) == 0)
|
||||
{
|
||||
if(url.indexOf("_alllayers") != -1)
|
||||
{
|
||||
// V101/LAYERS/_alllayers/L01/R0C18C0B10
|
||||
components = url.split("/");
|
||||
level = parseInt(components[ components.length - 2].slice(1),10);
|
||||
col = parseInt( components[ components.length -1].substring(1,5), 16);
|
||||
row = parseInt( components[ components.length -1].substring(6,10), 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
components = url.split("/");
|
||||
level = parseInt(components[ components.length - 3],10);
|
||||
col = parseInt(components[ components.length - 2],10);
|
||||
row = parseInt(components[ components.length - 1],10);
|
||||
}
|
||||
cellId = [row,col];
|
||||
polygon = tilingScheme.getCellPolygonFromCellId(cellId, level);
|
||||
callback(polygon);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!url)
|
||||
{
|
||||
callback(null,err);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this._parseGetTileInfo = function(data,callback){
|
||||
|
||||
@ -94,7 +141,7 @@ define([
|
||||
|
||||
callback({initExtent:initialExtent,fullExtent:fullExtent,tileInfo:tileInfo,resultObj:resultObj});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return TilesCore;
|
||||
}
|
||||
|
||||
@ -154,7 +154,7 @@ define([],function()
|
||||
|
||||
/**
|
||||
* Retrieve all tiles from indexeddb
|
||||
* @param callback callbakck(url, img, err)
|
||||
* @param callback callback(url, img, err)
|
||||
*/
|
||||
this.getAllTiles = function(callback)
|
||||
{
|
||||
|
||||
@ -257,41 +257,7 @@ define([
|
||||
*/
|
||||
layer.getTilePolygons = function(callback) // callback(Polygon polygon) or callback(null, error)
|
||||
{
|
||||
var components, level, col, row, cellId, polygon;
|
||||
|
||||
var store = this.offline.store;
|
||||
var tilingScheme = new TilingScheme(this);
|
||||
store.getAllTiles(function(url,img,err)
|
||||
{
|
||||
if(url && url.indexOf(layer.url) == 0)
|
||||
{
|
||||
if(url.indexOf("_alllayers") != -1)
|
||||
{
|
||||
// V101/LAYERS/_alllayers/L01/R0C18C0B10
|
||||
components = url.split("/");
|
||||
level = parseInt(components[ components.length - 2].slice(1),10);
|
||||
col = parseInt( components[ components.length -1].substring(1,5), 16);
|
||||
row = parseInt( components[ components.length -1].substring(6,10), 16);
|
||||
}
|
||||
else
|
||||
{
|
||||
components = url.split("/");
|
||||
level = parseInt(components[ components.length - 3],10);
|
||||
col = parseInt(components[ components.length - 2],10);
|
||||
row = parseInt(components[ components.length - 1],10);
|
||||
}
|
||||
cellId = [row,col];
|
||||
polygon = tilingScheme.getCellPolygonFromCellId(cellId, level);
|
||||
callback(polygon);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!url)
|
||||
{
|
||||
callback(null,err);
|
||||
}
|
||||
}
|
||||
});
|
||||
layer._tilesCore._getTilePolygons(this.offline.store,layer.url,this,callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -242,4 +242,28 @@ describe("offline enabler custom layer library", function()
|
||||
})
|
||||
});
|
||||
|
||||
async.it("get all tile polygons within extent",function(done){
|
||||
require(["dojo/Deferred","dojo/promise/all",],function(Deferred,all){
|
||||
|
||||
var promises = [];
|
||||
|
||||
g_basemapLayer.getTilePolygons(function(result,err){
|
||||
|
||||
var deferred = new Deferred();
|
||||
if(result && result.type){
|
||||
console.log("Tile polygon: " + result);
|
||||
expect(result.type).toEqual("polygon");
|
||||
}
|
||||
deferred.resolve(result);
|
||||
promises.push(deferred);
|
||||
})
|
||||
|
||||
all(promises).then( function(results)
|
||||
{
|
||||
done();
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -211,4 +211,28 @@ describe("offline enabler library", function()
|
||||
})
|
||||
});
|
||||
|
||||
async.it("get all tile polygons within extent",function(done){
|
||||
require(["dojo/Deferred","dojo/promise/all",],function(Deferred,all){
|
||||
|
||||
var promises = [];
|
||||
|
||||
g_basemapLayer.getTilePolygons(function(result,err){
|
||||
|
||||
var deferred = new Deferred();
|
||||
if(result && result.type){
|
||||
console.log("Tile polygon: " + result);
|
||||
expect(result.type).toEqual("polygon");
|
||||
}
|
||||
deferred.resolve(result);
|
||||
promises.push(deferred);
|
||||
})
|
||||
|
||||
all(promises).then( function(results)
|
||||
{
|
||||
done();
|
||||
});
|
||||
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user