mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
Closes #242 - replace constructor properties
This commit is contained in:
parent
3690c1b2c5
commit
52f14d193b
@ -142,8 +142,7 @@ Within your application you can manually check online status and then update you
|
||||
You can check if there are any edits pending by using the EditStore library. If there are edits then you can iterate `editsStore.retrieveEditsQueue()` and convert the edits to a readable format via `offlineFeaturesManager.getReadableEdit(edit)`.
|
||||
|
||||
```js
|
||||
// Be sure to import the module "esri/graphic" in your require statement
|
||||
var editStore = new O.esri.Edit.EditStore(Graphic);
|
||||
var editStore = new O.esri.Edit.EditStore();
|
||||
if( editStore.hasPendingEdits())
|
||||
{
|
||||
var edits = editStore.retrieveEditsQueue();
|
||||
|
||||
@ -133,10 +133,15 @@ This approach is best if you have requirements for restarting or reloading your
|
||||
|
||||
**Step 2** Create a new instance of `OfflineTilesEnablerLayer`. Note, when you instantiate the `Map` leave off the `basemap` property because we are adding a customer tile layer as our basemap. `OfflineTilesEnablerLayer` has three properties in the constructor. The first is the REST endpoint of the basemap you want to use, the second is the callback and the last is an optional parameter to preset the layer as online or offline. This will help with with drawing tiles correctly during offline restarts or reloads.
|
||||
|
||||
IMPORTANT: If you are trying to use a non-CORS-enabled Feature Service you will need to explicity declare your `proxyPath`. We've set `proxyPath` to `null` here just as an illustration. You don't need to do that since its default is `null`.
|
||||
|
||||
```js
|
||||
|
||||
tileLayer = new O.esri.Tiles.OfflineTilesEnablerLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",function(evt){
|
||||
console.log("Tile Layer Loaded.");
|
||||
// All non-CORS-enabled Feature Services require a proxy.
|
||||
// You can set the property here if needed.
|
||||
tileLayer.offline.proxyPath = null;
|
||||
},_isOnline);
|
||||
|
||||
// NOTE: When instantiating the Map, do not specify the basemap property!
|
||||
|
||||
@ -69,7 +69,7 @@ Provides a number of public methods that are used by `OfflineFeaturesManager` li
|
||||
###Constructor
|
||||
Constructor | Description
|
||||
--- | ---
|
||||
`O.esri.Edit.EditStore(Graphic)` | Creates an instance of the EditStore class. This library is responsible for managing the storage, reading, writing, serialization, deserialization of geometric features. Importing `Graphic` _("esri/graphic")_ allows the library to provide more abstraction when returning serialized data.
|
||||
`O.esri.Edit.EditStore()` | Creates an instance of the EditStore class. This library is responsible for managing the storage, reading, writing, serialization, deserialization of geometric features.
|
||||
|
||||
###Public Methods
|
||||
Methods | Returns | Description
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
O.esri.Edit.EditStore = function(Graphic){
|
||||
O.esri.Edit.EditStore = function(){
|
||||
|
||||
/* private consts */
|
||||
var EDITS_QUEUE_KEY = "esriEditsQueue";
|
||||
@ -149,7 +149,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;
|
||||
};
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ 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
|
||||
|
||||
@ -48,10 +48,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() )
|
||||
@ -74,7 +80,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;
|
||||
@ -304,7 +310,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);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -259,7 +259,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;
|
||||
|
||||
@ -284,7 +284,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
|
||||
@ -299,57 +299,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});
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -46,10 +46,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() )
|
||||
@ -209,7 +215,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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -9,7 +9,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;
|
||||
@ -20,7 +20,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],
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
|
||||
g_map.on('load', test);
|
||||
*/
|
||||
g_editsStore = new O.esri.Edit.EditStore(Graphic);
|
||||
g_editsStore = new O.esri.Edit.EditStore();
|
||||
test();
|
||||
|
||||
function initTestData()
|
||||
|
||||
@ -59,6 +59,7 @@
|
||||
function test()
|
||||
{
|
||||
g_basemapLayer = g_map.getLayer( g_map.layerIds[0] );
|
||||
|
||||
g_offlineTilesEnabler = new O.esri.Tiles.OfflineTilesEnabler();
|
||||
|
||||
var jasmineEnv = jasmine.getEnv();
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
"esri/layers/TileInfo",
|
||||
"esri/SpatialReference",
|
||||
"esri/geometry/Polygon",
|
||||
"../dist/offline-tiles-advanced-min.js",
|
||||
"../dist/offline-tiles-advanced-src.js",
|
||||
"dojo/dom-construct", "dojo/domReady!"],
|
||||
function(Map,
|
||||
GraphicsLayer, Graphic, SimpleFillSymbol,
|
||||
@ -48,6 +48,7 @@
|
||||
|
||||
g_basemapLayer = new O.esri.Tiles.OfflineTileEnablerLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",function(evt){
|
||||
console.log("Tile Layer Loaded.");
|
||||
g_basemapLayer.offline.proxyPath = null;
|
||||
},true);
|
||||
|
||||
g_map = new Map("map", {
|
||||
|
||||
@ -5,7 +5,7 @@ describe("offline enabler custom layer library", function()
|
||||
var async = new AsyncSpec(this);
|
||||
|
||||
async.it("validate map", function(done)
|
||||
{ console.log("VALIDATE !!!!!")
|
||||
{
|
||||
expect(g_map).toEqual(jasmine.any(Object));
|
||||
expect(g_map.id).toEqual("map");
|
||||
done();
|
||||
@ -18,27 +18,6 @@ describe("offline enabler custom layer library", function()
|
||||
done();
|
||||
});
|
||||
|
||||
// async.it("extends the tiled layer object", function(done)
|
||||
// {
|
||||
// expect(g_basemapLayer.goOffline).toBeUndefined();
|
||||
// g_offlineTilesEnabler.extend(g_basemapLayer,function(success)
|
||||
// {
|
||||
// expect(success).toEqual(true);
|
||||
// expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer.goOnline).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer.getTileUrl).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer._getTileUrl).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer.prepareForOffline).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer._storeTile).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer.deleteAllTiles).toEqual(jasmine.any(Function));
|
||||
// expect(g_basemapLayer.offline).toEqual(jasmine.any(Object));
|
||||
// expect(g_basemapLayer.offline.store).toEqual(jasmine.any(Object));
|
||||
//
|
||||
// g_basemapLayer.offline.proxyPath = "../lib/resource-proxy/proxy.php";
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
//
|
||||
async.it("can go offline", function(done)
|
||||
{
|
||||
expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function));
|
||||
@ -236,26 +215,15 @@ describe("offline enabler custom layer library", function()
|
||||
});
|
||||
|
||||
async.it("verifies ability to parse layer info",function(done){
|
||||
require(["esri/layers/LOD",
|
||||
"esri/geometry/Point",
|
||||
"esri/geometry/Extent",
|
||||
"esri/layers/TileInfo",
|
||||
"esri/SpatialReference",
|
||||
"esri/geometry/Polygon"],function(LOD,Point,Extent,TileInfo,SpatialReference){
|
||||
|
||||
|
||||
g_basemapLayer._getTileInfoPrivate("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",function(result){
|
||||
tilesCore._parseGetTileInfo(SpatialReference,LOD,Extent,TileInfo,Point,result,function(result){
|
||||
expect(result.resultObj).toEqual(jasmine.any(Object));
|
||||
expect(result.initExtent.type).toEqual("extent");
|
||||
expect(result.fullExtent.type).toEqual("extent");
|
||||
expect(result.tileInfo.format).toEqual("JPEG");
|
||||
done();
|
||||
})
|
||||
g_basemapLayer._getTileInfoPrivate("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",function(result){
|
||||
tilesCore._parseGetTileInfo(result,function(result){
|
||||
expect(result.resultObj).toEqual(jasmine.any(Object));
|
||||
expect(result.initExtent.type).toEqual("extent");
|
||||
expect(result.fullExtent.type).toEqual("extent");
|
||||
expect(result.tileInfo.format).toEqual("JPEG");
|
||||
done();
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
async.it("get all tile polygons within extent",function(done){
|
||||
|
||||
@ -23,7 +23,9 @@ describe("offline enabler library", function()
|
||||
expect(g_basemapLayer.goOffline).toBeUndefined();
|
||||
g_offlineTilesEnabler.extend(g_basemapLayer,function(success)
|
||||
{
|
||||
expect(success).toEqual(true);
|
||||
g_basemapLayer.offline.proxyPath = null;
|
||||
|
||||
expect(success).toEqual(true);
|
||||
expect(g_basemapLayer.goOffline).toEqual(jasmine.any(Function));
|
||||
expect(g_basemapLayer.goOnline).toEqual(jasmine.any(Function));
|
||||
expect(g_basemapLayer.getTileUrl).toEqual(jasmine.any(Function));
|
||||
@ -34,7 +36,7 @@ describe("offline enabler library", function()
|
||||
expect(g_basemapLayer.offline.store).toEqual(jasmine.any(Object));
|
||||
expect(g_basemapLayer._tilesCore._storeTile).toEqual(jasmine.any(Function));
|
||||
|
||||
g_basemapLayer.offline.proxyPath = "../lib/resource-proxy/proxy.php";
|
||||
// g_basemapLayer.offline.proxyPath = "../lib/resource-proxy/proxy.php";
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user