This commit is contained in:
Andy Gup 2014-09-30 17:29:42 -06:00
parent dad9b6f30f
commit 9c1b62221a
9 changed files with 193 additions and 105 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! offline-editor - v0.0.1 - 2014-09-08
/*! offline-editor - v2.2 - 2014-09-30
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
* Apache License*/
@ -27,12 +27,13 @@ define([
{
_onlineStatus: "online",
_featureLayers: {},
_editStore: new O.esri.Edit.EditStore(Graphic),
_editStore: new O.esri.Edit.EditStore(),
ONLINE: "online", // all edits will directly go to the server
OFFLINE: "offline", // edits will be enqueued
RECONNECTING: "reconnecting", // sending stored edits to the server
attachmentsStore: null, // indexedDB for storing attachments
proxyPath: null, // by default we use CORS and therefore proxyPath is null
// manager emits event when...
events: {
@ -713,7 +714,11 @@ define([
{
dfd.reject(err);
};
var proxy = esriConfig.defaults.io.proxyUrl || "";
// IMPORTANT!
// Proxy path can be set to null if feature service is CORS enabled
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
var proxy = this.proxyPath || esriConfig.defaults.io.proxyUrl || "";
if(proxy !== ""){
proxy += "?";
}
@ -1027,7 +1032,7 @@ else{
"use strict";
O.esri.Edit.EditStore = function(Graphic){
O.esri.Edit.EditStore = function(){
/* private consts */
var EDITS_QUEUE_KEY = "esriEditsQueue";
@ -1178,7 +1183,12 @@ O.esri.Edit.EditStore = function(Graphic){
this._deserialize = function(json)
{
var graphic = new Graphic(JSON.parse(json));
var graphic;
require(["esri/graphic"],function(Graphic){
graphic = new Graphic(JSON.parse(json));
});
return graphic;
};

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! offline-editor - v0.0.1 - 2014-09-08
/*! offline-editor - v2.2 - 2014-09-30
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
@ -51,10 +51,16 @@ define([
isOnline = state; console.log("STATE IS: " + state)
}
/**
* IMPORTANT! proxyPath is set to null by default since we assume Feature Service is CORS-enabled.
* All AGOL Feature Services are CORS-enabled.
*
* @type {{online: boolean, store: O.esri.Tiles.TilesStore, proxyPath: null}}
*/
this.offline = {
online: isOnline,
store: new O.esri.Tiles.TilesStore(),
proxyPath: "../lib/resource-proxy/proxy.php"
proxyPath: null
};
if( /*false &&*/ this.offline.store.isSupported() )
@ -77,7 +83,7 @@ define([
alert("There was a problem retrieving tiled map info in OfflineTilesEnablerLayer.");
}
this._tilesCore._parseGetTileInfo(SpatialReference,LOD,Extent,TileInfo,Point,result,function(tileResult){
this._tilesCore._parseGetTileInfo(result,function(tileResult){
this.layerInfos = tileResult.resultObj.layers;
this.minScale = tileResult.resultObj.minScale;
this.maxScale = tileResult.resultObj.maxScale;
@ -307,7 +313,7 @@ define([
*/
getTilePolygons : function(callback) // callback(Polygon polygon) or callback(null, error)
{
this._tilesCore._getTilePolygons(Polygon,this.offline.store,this.url,this,callback);
this._tilesCore._getTilePolygons(this.offline.store,this.url,this,callback);
},
/**
@ -1042,7 +1048,7 @@ O.esri.Tiles.TilesCore = function(){
* @param context a reference to the layer
* @param callback callback(polygon, error)
*/
this._getTilePolygons = function(Polygon,store,layerUrl,context,callback) // callback(Polygon polygon) or callback(null, error)
this._getTilePolygons = function(store,layerUrl,context,callback) // callback(Polygon polygon) or callback(null, error)
{
var components, level, col, row, cellId, polygon;
@ -1067,7 +1073,7 @@ O.esri.Tiles.TilesCore = function(){
row = parseInt(components[ components.length - 1],10);
}
cellId = [row,col];
polygon = tilingScheme.getCellPolygonFromCellId(Polygon,cellId, level);
polygon = tilingScheme.getCellPolygonFromCellId(cellId, level);
callback(polygon);
}
else
@ -1082,57 +1088,64 @@ O.esri.Tiles.TilesCore = function(){
/**
* Gets all the important bits out of the map services description page
* @param SpatialReference "esri/SpatialReference"
* @param LOD "esri/layers/LOD"
* @param data The http response via f=pjson
* @param callback callback({initExtent,fullExtent,tileInfo,resultObj});
* @private
*/
this._parseGetTileInfo = function(SpatialReference,LOD,Extent,TileInfo,Point,data,callback){
this._parseGetTileInfo = function(data,callback){
var fixedResponse = data.replace(/\\'/g, "'");
var resultObj = JSON.parse(fixedResponse);
var spatialRef = new SpatialReference({wkid:resultObj.spatialReference.wkid});
var lods = [];
require([
"esri/SpatialReference",
"esri/layers/LOD",
"esri/geometry/Extent",
"esri/layers/TileInfo",
"esri/geometry/Point"],function(SpatialReference,LOD,Extent,TileInfo,Point){
var lodsObj = JSON.parse(data,function(key,value){
if(((typeof key == 'number') || (key % 1 == 0)) && (typeof value === "object")){
var l = new LOD();
l.level = value.level;
l.resolution = value.resolution;
l.scale = value.scale;
var spatialRef = new SpatialReference({wkid:resultObj.spatialReference.wkid});
if(value.hasOwnProperty("level")) lods.push(l);
return value;
}
else{
return value;
}
});
var lods = [];
var initialExtent = new Extent(
parseFloat(resultObj.initialExtent.xmin),
parseFloat(resultObj.initialExtent.ymin),
parseFloat(resultObj.initialExtent.xmax),
parseFloat(resultObj.initialExtent.ymax),
spatialRef
);
var lodsObj = JSON.parse(data,function(key,value){
if(((typeof key == 'number') || (key % 1 == 0)) && (typeof value === "object")){
var l = new LOD();
l.level = value.level;
l.resolution = value.resolution;
l.scale = value.scale;
var fullExtent = new Extent(
parseFloat(resultObj.fullExtent.xmin),
parseFloat(resultObj.fullExtent.ymin),
parseFloat(resultObj.fullExtent.xmax),
parseFloat(resultObj.fullExtent.ymax),
spatialRef
);
if(value.hasOwnProperty("level")) lods.push(l);
return value;
}
else{
return value;
}
});
var tileInfo = new TileInfo(resultObj.tileInfo);
var origin = new Point(tileInfo.origin.x,tileInfo.origin.y,spatialRef)
tileInfo.origin = origin;
tileInfo.lods = lods;
var initialExtent = new Extent(
parseFloat(resultObj.initialExtent.xmin),
parseFloat(resultObj.initialExtent.ymin),
parseFloat(resultObj.initialExtent.xmax),
parseFloat(resultObj.initialExtent.ymax),
spatialRef
);
callback({initExtent:initialExtent,fullExtent:fullExtent,tileInfo:tileInfo,resultObj:resultObj});
var fullExtent = new Extent(
parseFloat(resultObj.fullExtent.xmin),
parseFloat(resultObj.fullExtent.ymin),
parseFloat(resultObj.fullExtent.xmax),
parseFloat(resultObj.fullExtent.ymax),
spatialRef
);
var tileInfo = new TileInfo(resultObj.tileInfo);
var origin = new Point(tileInfo.origin.x,tileInfo.origin.y,spatialRef)
tileInfo.origin = origin;
tileInfo.lods = lods;
callback({initExtent:initialExtent,fullExtent:fullExtent,tileInfo:tileInfo,resultObj:resultObj});
})
}
};
@ -1410,7 +1423,7 @@ O.esri.Tiles.TilingScheme.prototype = {
return [col, row];
},
getCellPolygonFromCellId: function (Polygon,cellId, level) {
getCellPolygonFromCellId: function (cellId, level) {
var col1 = cellId[0];
var row1 = cellId[1];
var col2 = col1 + 1;
@ -1421,7 +1434,13 @@ O.esri.Tiles.TilingScheme.prototype = {
var x2 = this.tileInfo.origin.x + (col2 * this.tileInfo.cols * this.tileInfo.lods[level].resolution);
var y2 = this.tileInfo.origin.y - (row2 * this.tileInfo.rows * this.tileInfo.lods[level].resolution);
var polygon = new Polygon(this.tileInfo.spatialReference);
var polygon;
var spatialReference = this.tileInfo.spatialReference;
require(["esri/geometry/Polygon"],function(Polygon){
polygon = new Polygon(spatialReference);
})
polygon.addRing([
[x1, y1], // clockwise
[x2, y1],

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! offline-editor - v0.0.1 - 2014-09-08
/*! offline-editor - v2.2 - 2014-09-30
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
* Apache License*/
define([
@ -49,10 +49,16 @@ define([
isOnline = state; console.log("STATE IS: " + state)
}
/**
* IMPORTANT! proxyPath is set to null by default since we assume Feature Service is CORS-enabled.
* All AGOL Feature Services are CORS-enabled.
*
* @type {{online: boolean, store: O.esri.Tiles.TilesStore, proxyPath: null}}
*/
layer.offline = {
online: isOnline,
store: new O.esri.Tiles.TilesStore(),
proxyPath: "../lib/resource-proxy/proxy.php"
proxyPath: null
};
if( /*false &&*/ layer.offline.store.isSupported() )
@ -212,7 +218,7 @@ define([
*/
layer.getTilePolygons = function(callback) // callback(Polygon polygon) or callback(null, error)
{
layer._tilesCore._getTilePolygons(Polygon,this.offline.store,layer.url,this,callback);
layer._tilesCore._getTilePolygons(this.offline.store,layer.url,this,callback);
};
/**
@ -905,7 +911,7 @@ O.esri.Tiles.TilesCore = function(){
* @param context a reference to the layer
* @param callback callback(polygon, error)
*/
this._getTilePolygons = function(Polygon,store,layerUrl,context,callback) // callback(Polygon polygon) or callback(null, error)
this._getTilePolygons = function(store,layerUrl,context,callback) // callback(Polygon polygon) or callback(null, error)
{
var components, level, col, row, cellId, polygon;
@ -930,7 +936,7 @@ O.esri.Tiles.TilesCore = function(){
row = parseInt(components[ components.length - 1],10);
}
cellId = [row,col];
polygon = tilingScheme.getCellPolygonFromCellId(Polygon,cellId, level);
polygon = tilingScheme.getCellPolygonFromCellId(cellId, level);
callback(polygon);
}
else
@ -945,57 +951,64 @@ O.esri.Tiles.TilesCore = function(){
/**
* Gets all the important bits out of the map services description page
* @param SpatialReference "esri/SpatialReference"
* @param LOD "esri/layers/LOD"
* @param data The http response via f=pjson
* @param callback callback({initExtent,fullExtent,tileInfo,resultObj});
* @private
*/
this._parseGetTileInfo = function(SpatialReference,LOD,Extent,TileInfo,Point,data,callback){
this._parseGetTileInfo = function(data,callback){
var fixedResponse = data.replace(/\\'/g, "'");
var resultObj = JSON.parse(fixedResponse);
var spatialRef = new SpatialReference({wkid:resultObj.spatialReference.wkid});
var lods = [];
require([
"esri/SpatialReference",
"esri/layers/LOD",
"esri/geometry/Extent",
"esri/layers/TileInfo",
"esri/geometry/Point"],function(SpatialReference,LOD,Extent,TileInfo,Point){
var lodsObj = JSON.parse(data,function(key,value){
if(((typeof key == 'number') || (key % 1 == 0)) && (typeof value === "object")){
var l = new LOD();
l.level = value.level;
l.resolution = value.resolution;
l.scale = value.scale;
var spatialRef = new SpatialReference({wkid:resultObj.spatialReference.wkid});
if(value.hasOwnProperty("level")) lods.push(l);
return value;
}
else{
return value;
}
});
var lods = [];
var initialExtent = new Extent(
parseFloat(resultObj.initialExtent.xmin),
parseFloat(resultObj.initialExtent.ymin),
parseFloat(resultObj.initialExtent.xmax),
parseFloat(resultObj.initialExtent.ymax),
spatialRef
);
var lodsObj = JSON.parse(data,function(key,value){
if(((typeof key == 'number') || (key % 1 == 0)) && (typeof value === "object")){
var l = new LOD();
l.level = value.level;
l.resolution = value.resolution;
l.scale = value.scale;
var fullExtent = new Extent(
parseFloat(resultObj.fullExtent.xmin),
parseFloat(resultObj.fullExtent.ymin),
parseFloat(resultObj.fullExtent.xmax),
parseFloat(resultObj.fullExtent.ymax),
spatialRef
);
if(value.hasOwnProperty("level")) lods.push(l);
return value;
}
else{
return value;
}
});
var tileInfo = new TileInfo(resultObj.tileInfo);
var origin = new Point(tileInfo.origin.x,tileInfo.origin.y,spatialRef)
tileInfo.origin = origin;
tileInfo.lods = lods;
var initialExtent = new Extent(
parseFloat(resultObj.initialExtent.xmin),
parseFloat(resultObj.initialExtent.ymin),
parseFloat(resultObj.initialExtent.xmax),
parseFloat(resultObj.initialExtent.ymax),
spatialRef
);
callback({initExtent:initialExtent,fullExtent:fullExtent,tileInfo:tileInfo,resultObj:resultObj});
var fullExtent = new Extent(
parseFloat(resultObj.fullExtent.xmin),
parseFloat(resultObj.fullExtent.ymin),
parseFloat(resultObj.fullExtent.xmax),
parseFloat(resultObj.fullExtent.ymax),
spatialRef
);
var tileInfo = new TileInfo(resultObj.tileInfo);
var origin = new Point(tileInfo.origin.x,tileInfo.origin.y,spatialRef)
tileInfo.origin = origin;
tileInfo.lods = lods;
callback({initExtent:initialExtent,fullExtent:fullExtent,tileInfo:tileInfo,resultObj:resultObj});
})
}
};
@ -1273,7 +1286,7 @@ O.esri.Tiles.TilingScheme.prototype = {
return [col, row];
},
getCellPolygonFromCellId: function (Polygon,cellId, level) {
getCellPolygonFromCellId: function (cellId, level) {
var col1 = cellId[0];
var row1 = cellId[1];
var col2 = col1 + 1;
@ -1284,7 +1297,13 @@ O.esri.Tiles.TilingScheme.prototype = {
var x2 = this.tileInfo.origin.x + (col2 * this.tileInfo.cols * this.tileInfo.lods[level].resolution);
var y2 = this.tileInfo.origin.y - (row2 * this.tileInfo.rows * this.tileInfo.lods[level].resolution);
var polygon = new Polygon(this.tileInfo.spatialReference);
var polygon;
var spatialReference = this.tileInfo.spatialReference;
require(["esri/geometry/Polygon"],function(Polygon){
polygon = new Polygon(spatialReference);
})
polygon.addRing([
[x1, y1], // clockwise
[x2, y1],

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
/*! offline-editor - v0.0.1 - 2014-09-08
/*! offline-editor - v2.2 - 2014-09-30
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
* Apache License*/
/**
@ -48,6 +48,7 @@ define([
//
_maxDBSize: 75, // User configurable maximum size in MBs.
_isDBWriteable: true, // Manually allow or stop writing to the database.
_isDBValid: false, // Does the browser support IndexedDB or IndexedDBShim
_autoCenter: null, // Auto center the map
_fileEntriesLength: 0, // Number of files in zip
_inMemTilesObject: null, // Stores unzipped files from tpk
@ -98,8 +99,10 @@ define([
var tileid = "void:/" + level + "/" + row + "/" + col;
if(this.map == null) this.map = this.getMap();
if(this._autoCenter == null) this._autoCenter = new O.esri.TPK.autoCenterMap(this.map,this.RECENTER_DELAY);
this._autoCenter.init();
if(this._autoCenter == null) {
this._autoCenter = new O.esri.TPK.autoCenterMap(this.map,this.RECENTER_DELAY);
this._autoCenter.init();
}
this._getInMemTiles(url,layersDir, level, row, col,tileid,function (result,tileid,url) {
var img = query("img[src=" + tileid + "]")[0];
@ -183,10 +186,46 @@ define([
* Use this in conjunction with getDBSize() on a map pan or zoom event listener.
* @param value
*/
isDBWriteable: function(/* Boolean */ value){
setDBWriteable: function(/* Boolean */ value){
this._isDBWriteable = value;
},
/**
* Validates whether or not the browser supports this library
* @returns {boolean}
*/
isDBValid: function(){
this._validate();
return this._isDBValid;
},
/**
* Reads a tile into tile database. Works with offlineTilesEnabler.js and OfflineTilesEnablerLayer.js
* saveToFile() functionality.
* IMPORTANT! The tile must confirm to an object using the pattern shown in _storeTile().
* @param file
* @param callback callback( boolean, error)
*/
loadFromURL: function (tile, callback) // callback(success,msg)
{
if (this.isDBValid()) {
this.store.store(tile, function (success,err) {
//Check the result
if (success) {
console.log("loadFromURL() success.");
callback(true, "");
}
else {
console.log("loadFromURL() Failed.");
callback(false, err);
}
});
}
else {
callback(false, "not supported");
}
},
/**
* Runs specific validation tasks. Reserved for future use.
* Currently only throws console errors. Does not stop execution of the library!
@ -218,7 +257,8 @@ define([
this.emit(this.DATABASE_ERROR_EVENT,{msg:this.DB_FULL_ERROR,err : err});
}
this.emit(this.VALIDATION_EVENT,{msg:this.DB_VALIDATED,err : null})
console.log("DB size: " + mb + " MBs, Tile count: " + size.tileCount + ", Error: " + err)
console.log("DB size: " + mb + " MBs, Tile count: " + size.tileCount + ", Error: " + err);
this._isDBValid = true;
}.bind(this))
}
}.bind(this));

View File

@ -1,6 +1,6 @@
{
"name": "offline-editor",
"version": "0.0.1",
"version": "2.2",
"description": "Lighweight set of libraries for working offline with map tiles and ArcGIS feature services",
"author": "Andy Gup <agup@esri.com> (http://blog.andygup.net)",
"license": "Apache 2",