mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
commit
0c512c6d6b
14
CHANGELOG.md
14
CHANGELOG.md
@ -1,5 +1,19 @@
|
||||
# offline-editor-js - Changelog
|
||||
|
||||
## Version 2.4 - Nov 26, 2014
|
||||
- Closes #274 phantom symbols not working correctly
|
||||
- Updated offlineFeaturesManager.js
|
||||
- Updated API docs to reflect new functionality.
|
||||
- Updated appcache-features.html sample to incorporate new functionality.
|
||||
- Updated modular-popup CSS media queries
|
||||
|
||||
New functionality:
|
||||
|
||||
- Added setPhantomLayerGraphics() - for use with offline browser restarts. Allows you to restore the phantom graphics layer. This layer is used to highlight any points that have been modified while offline.
|
||||
- Added getPhantomLayerGraphics() - for use with offline browser restarts. Allows you to get a JSON copy of the current phantom graphics layers so that you can save it to a local database such as localStorage.
|
||||
|
||||
Breaking changes: none
|
||||
|
||||
## Version 2.3.1.2 - Oct 21, 2014
|
||||
- Closes #267 can't host markdown on gh-pages
|
||||
|
||||
|
||||
2
dist/offline-edit-min.js
vendored
2
dist/offline-edit-min.js
vendored
File diff suppressed because one or more lines are too long
41
dist/offline-edit-src.js
vendored
41
dist/offline-edit-src.js
vendored
@ -1,4 +1,4 @@
|
||||
/*! offline-editor-js - v2.3.1 - 2014-10-14
|
||||
/*! offline-editor-js - v2.4 - 2014-11-26
|
||||
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
|
||||
* Apache License*/
|
||||
|
||||
@ -444,7 +444,44 @@ define([
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the phantom layer with a new features.
|
||||
* @param graphicsArray an array of Graphics
|
||||
*/
|
||||
layer.setPhantomLayerGraphics = function(graphicsArray){
|
||||
var length = graphicsArray.length;
|
||||
|
||||
if(length > 0){
|
||||
for(var i=0; i < length; i++){
|
||||
var graphic = new Graphic(graphicsArray[i]);
|
||||
this._phantomLayer.add(graphic);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the array of graphics from the phantom graphics layer.
|
||||
* This layer identifies features that have been modified
|
||||
* while offline.
|
||||
* @returns {array}
|
||||
*/
|
||||
layer.getPhantomLayerGraphics = function(callback){
|
||||
//return layer._phantomLayer.graphics;
|
||||
var graphics = layer._phantomLayer.graphics;
|
||||
var length = layer._phantomLayer.graphics.length;
|
||||
var jsonArray = [];
|
||||
for(var i=0; i < length; i++){
|
||||
var jsonGraphic = graphics[i].toJson();
|
||||
jsonArray.push(jsonGraphic);
|
||||
if(i == (length - 1)) {
|
||||
var graphicsJSON = JSON.stringify(jsonArray);
|
||||
callback(graphicsJSON);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a featureDefinition
|
||||
|
||||
2
dist/offline-tiles-advanced-src.js
vendored
2
dist/offline-tiles-advanced-src.js
vendored
@ -1,4 +1,4 @@
|
||||
/*! offline-editor-js - v2.3.1 - 2014-10-14
|
||||
/*! offline-editor-js - v2.4 - 2014-11-26
|
||||
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
|
||||
* Apache License*/
|
||||
define([
|
||||
|
||||
2
dist/offline-tiles-basic-src.js
vendored
2
dist/offline-tiles-basic-src.js
vendored
@ -1,4 +1,4 @@
|
||||
/*! offline-editor-js - v2.3.1 - 2014-10-14
|
||||
/*! offline-editor-js - v2.4 - 2014-11-26
|
||||
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
|
||||
* Apache License*/
|
||||
define([
|
||||
|
||||
2
dist/offline-tpk-src.js
vendored
2
dist/offline-tpk-src.js
vendored
@ -1,4 +1,4 @@
|
||||
/*! offline-editor-js - v2.3.1 - 2014-10-14
|
||||
/*! offline-editor-js - v2.4 - 2014-11-26
|
||||
* Copyright (c) 2014 Environmental Systems Research Institute, Inc.
|
||||
* Apache License*/
|
||||
/**
|
||||
|
||||
@ -26,6 +26,9 @@ Property | Value | Description
|
||||
`RECONNECTING` | "reconnecting" | Sending stored edits to the server
|
||||
|
||||
###Methods
|
||||
|
||||
The offline-editor-js library provides the following functionality.
|
||||
|
||||
Methods | Returns | Description
|
||||
--- | --- | ---
|
||||
`extend(layer)`|nothing|Overrides a feature layer, by replacing the `applyEdits()` method of the layer. You can use the FeatureLayer as always, but it's behaviour will be different according to the online status of the manager.
|
||||
@ -56,15 +59,34 @@ Event | Value | Description
|
||||
`events.ATTACHMENT_ENQUEUED` | "attachment-enqueued" | An attachment is in the queue to be sent to the server.
|
||||
`events.ATTACHMENTS_SENT` | "attachments-sent" | When any attachment is actually sent to the server.
|
||||
|
||||
###FeatureLayer Overrides
|
||||
###FeatureLayer Extends
|
||||
|
||||
This library extends a FeatureLayer and adds the following additional functionality. Example usage:
|
||||
|
||||
|
||||
```js
|
||||
|
||||
// Extend the FeatureLayer
|
||||
var offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManager();
|
||||
offlineFeaturesManager.extent(myCustomFeatureLayer);
|
||||
|
||||
// Access additional functionality
|
||||
myCustomFeatureLayer.getPhantomGraphicsLayer(function(json){...});
|
||||
|
||||
```
|
||||
|
||||
|
||||
Methods | Returns | Description
|
||||
--- | --- | ---
|
||||
`applyEdits(` `adds, updates, deletes,` `callback, errback)` | `deferred`| applyEdits() method is replaced by this library. It's behaviour depends upon online state of the manager. You need to pass the same arguments as to the original applyEdits() method and it returns a deferred object, that will be resolved in the same way as the original, as well as the callbacks will be called under the same conditions. This method looks the same as the original to calling code, the only difference is internal.
|
||||
`convertGraphicLayerToJSON(` `features, updateEndEvent, callback)` | `callback( featureJSON, layerDefJSON)` | Used with offline browser restarts. In order to reconstitute the feature layer and map you'll need to store the featureJSON and layerDefJSON in local storage and then it read back upon an offline restart. The `updateEndEvent` is the Feature Layer's `update-end` event. The appcache-features.html sample demonstrates this pattern.
|
||||
`getFeatureDefinition(` `featureLayer, featuresArr` `geometryType, callback)` | Object | Used with offline browser restarts. Pass it a FeatureLayer instance, an array of features and specify the Esri geometry type. It will return a FeatureLayer Definition object that can be used to reconstitute a Feature Layer from scratch. The appcache-features.html sample demonstrates this pattern. Go here for more info on the ArcGIS REST API [layerDefinition](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000004v000000), and [Layer](http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Layer/02r30000004q000000/).
|
||||
`setPhantomLayerGraphics( graphicsArray) ` | nothing | Used with offline browser restarts. Adds the graphics in the `graphicsArray` to the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
||||
`getPhantomLayerGraphics( callback) ` | `callback( graphicsLayerJSON)` | Used with offline browser restarts. Returns a JSON representation of the internal phantom graphics layer. This layer is designed to indicate to the user any graphic that has been modified while offline. The appcache-features.html sample demonstrates this pattern.
|
||||
|
||||
##O.esri.Edit.EditStore
|
||||
|
||||
Provides a number of public methods that are used by `OfflineFeaturesManager` library. They provide a low-level storage mechanism using indexedDb browser functions. Instiantiate this library using a `new` statement.
|
||||
Provides a number of public methods that are used by `OfflineFeaturesManager` library for storing edits in the browser. Instiantiate this library using a `new` statement.
|
||||
|
||||
###Constructor
|
||||
Constructor | Description
|
||||
@ -81,5 +103,3 @@ Methods | Returns | Description
|
||||
`pendingEditsCount()` | int | The total number of edits that are queued in the local cache.
|
||||
`getEditsStoreSizeBytes()` | Number | Returns the total size of all pending edits in bytes.
|
||||
`getLocalStorageSizeBytes()` | Number | Returns the total size in bytes of all items for local storage cached using the current domain name.
|
||||
|
||||
|
||||
|
||||
@ -441,7 +441,44 @@ define([
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the phantom layer with a new features.
|
||||
* @param graphicsArray an array of Graphics
|
||||
*/
|
||||
layer.setPhantomLayerGraphics = function(graphicsArray){
|
||||
var length = graphicsArray.length;
|
||||
|
||||
if(length > 0){
|
||||
for(var i=0; i < length; i++){
|
||||
var graphic = new Graphic(graphicsArray[i]);
|
||||
this._phantomLayer.add(graphic);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the array of graphics from the phantom graphics layer.
|
||||
* This layer identifies features that have been modified
|
||||
* while offline.
|
||||
* @returns {array}
|
||||
*/
|
||||
layer.getPhantomLayerGraphics = function(callback){
|
||||
//return layer._phantomLayer.graphics;
|
||||
var graphics = layer._phantomLayer.graphics;
|
||||
var length = layer._phantomLayer.graphics.length;
|
||||
var jsonArray = [];
|
||||
for(var i=0; i < length; i++){
|
||||
var jsonGraphic = graphics[i].toJson();
|
||||
jsonArray.push(jsonGraphic);
|
||||
if(i == (length - 1)) {
|
||||
var graphicsJSON = JSON.stringify(jsonArray);
|
||||
callback(graphicsJSON);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a featureDefinition
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "offline-editor-js",
|
||||
"version": "2.3.1",
|
||||
"version": "2.4",
|
||||
"description": "Lightweight 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",
|
||||
|
||||
@ -50,10 +50,10 @@ module.exports = function(grunt) {
|
||||
"//esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css",
|
||||
"//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js",
|
||||
"//esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js",
|
||||
"https://code.jquery.com/jquery-2.1.1.min.js",
|
||||
"//code.jquery.com/jquery-2.1.1.min.js",
|
||||
"",
|
||||
"# Custom feature service",
|
||||
"http://services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0?f=json",
|
||||
"//services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0?f=json",
|
||||
"#",
|
||||
"# required local html",
|
||||
"# /xyz/style.css",
|
||||
|
||||
@ -1,20 +1,22 @@
|
||||
CACHE MANIFEST
|
||||
# This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator
|
||||
# Time: Fri Oct 10 2014 16:02:50 GMT-0600 (MDT)
|
||||
# Time: Wed Nov 26 2014 08:47:17 GMT-0700 (MST)
|
||||
|
||||
CACHE:
|
||||
# manifest-generator, version: 2.3
|
||||
# manifest-generator, version: 2.4
|
||||
#
|
||||
# Home Page
|
||||
appcache-features.html
|
||||
#
|
||||
# ArcGIS API for JavaScript files
|
||||
# http://js.arcgis.com/o/agup_hack4co/appcacheFeatures2/dojo/dojo.js
|
||||
# http://js.arcgis.com/o/agup_hack4co/appcacheFeatures2/dojo/selector/acme.js
|
||||
../samples/jsolib/dojo.js
|
||||
../samples/jsolib/selector/acme.js
|
||||
../samples/jsolib/nls/dojo_en.js
|
||||
../samples/jsolib/resources/blank.gif
|
||||
#
|
||||
#http://js.arcgis.com/3.11/esri/dijit/images/popup-sprite.png
|
||||
http://js.arcgis.com/3.11/esri/dijit/images/attribute_inspector_sprite.png
|
||||
http://js.arcgis.com/3.11/dojo/resources/blank.gif
|
||||
#http://js.arcgis.com/3.11/dojo/resources/blank.gif
|
||||
http://js.arcgis.com/3.11/esri/dijit/images/ajax-loader.gif
|
||||
http://js.arcgis.com/3.11/esri/images/map/logo-sm.png
|
||||
http://js.arcgis.com/3.11/esri/images/map/logo-med.png
|
||||
@ -31,11 +33,11 @@ http://js.arcgis.com/3.11/esri/nls/jsapi_en-us.js
|
||||
//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css
|
||||
//esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css
|
||||
//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js
|
||||
http://esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js
|
||||
https://code.jquery.com/jquery-2.1.1.min.js
|
||||
//esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js
|
||||
//code.jquery.com/jquery-2.1.1.min.js
|
||||
|
||||
# Custom feature service
|
||||
http://services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0?f=json
|
||||
//services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0?f=json
|
||||
#
|
||||
# required local html
|
||||
# /xyz/style.css
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
|
||||
<style>
|
||||
#mapDiv {
|
||||
min-height: 500px;
|
||||
min-height: 400px;
|
||||
max-height: 1000px;
|
||||
}
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
.span-pending {color: blue; padding-left: 1em;}
|
||||
|
||||
.floatRight { float: right;}
|
||||
.container { padding: 20px;}
|
||||
.container { padding: 20px; width: 100%;}
|
||||
</style>
|
||||
|
||||
<!--<script>-->
|
||||
@ -140,23 +140,24 @@
|
||||
"esri/Color",
|
||||
"esri/tasks/query",
|
||||
"dojo/on",
|
||||
"esri/graphic",
|
||||
"esri/graphic","esri/geometry/Extent", "esri/SpatialReference",
|
||||
"widgets/modal/popup",
|
||||
"//esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js",
|
||||
"../dist/offline-tiles-advanced-min.js",
|
||||
"../dist/offline-edit-min.js",
|
||||
"../dist/offline-tiles-advanced-src.js",
|
||||
"../dist/offline-edit-src.js",
|
||||
"dojo/domReady!"],
|
||||
function(Map,FeatureLayer,AppCacheManager,
|
||||
SimpleRenderer,SimpleMarkerSymbol,Color,Query,
|
||||
on,Graphic,ModalPopup,BootstrapMap) {
|
||||
on,Graphic,Extent,SpatialReference,ModalPopup,BootstrapMap) {
|
||||
|
||||
initAppCacheManager();
|
||||
|
||||
var map = null;
|
||||
var _isOnline = true;
|
||||
var defaultSymbol;
|
||||
|
||||
// Variables for editing handling
|
||||
var currentFeature, busStopFeatureLayer, offlineFeaturesManager;
|
||||
var currentFeature, busStopFeatureLayer = null, offlineFeaturesManager;
|
||||
var pendingEdits = document.getElementById("span-pending-edits");
|
||||
var imgOfflineIndicator = document.getElementById("state-span");
|
||||
var btnState = document.getElementById("btn-state");
|
||||
@ -180,29 +181,8 @@
|
||||
// Variables for modal popup
|
||||
var popup,closeBtn,saveBtn,deleteBtn,stopMainID,stopID,stopRoutes,stopNames;
|
||||
|
||||
// Modify symbol size based on screen size.
|
||||
// Bigger screens get smaller symbols. Smaller screens get larger symbols.
|
||||
var width = window.innerWidth
|
||||
|| document.documentElement.clientWidth
|
||||
|| document.body.clientWidth;
|
||||
|
||||
var height = window.innerHeight
|
||||
|| document.documentElement.clientHeight
|
||||
|| document.body.clientHeight;
|
||||
|
||||
if (height > 768 || width > 1024) {
|
||||
defaultSymbol= new SimpleMarkerSymbol().setStyle(
|
||||
SimpleMarkerSymbol.STYLE_DIAMOND).setColor(
|
||||
new Color([255,0,0,0.5])).setSize(20);
|
||||
}
|
||||
else{
|
||||
defaultSymbol= new SimpleMarkerSymbol().setStyle(
|
||||
SimpleMarkerSymbol.STYLE_DIAMOND).setColor(
|
||||
new Color([255,0,0,0.5])).setSize(35);
|
||||
}
|
||||
|
||||
var editsStore = new O.esri.Edit.EditStore();
|
||||
|
||||
mediaQueries();
|
||||
initModalPopup();
|
||||
|
||||
/**
|
||||
@ -228,6 +208,27 @@
|
||||
stopNames = document.getElementById("stop-names");
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify symbol size to devices. Make them easier to touch on.
|
||||
* Feel free to tweak this based on your requirements
|
||||
*/
|
||||
function mediaQueries(){
|
||||
var widthQuery = window.matchMedia("(max-width: 768px)");
|
||||
var orientation = window.matchMedia("(orientation:portrait)");
|
||||
|
||||
if(widthQuery.matches && orientation.matches){
|
||||
defaultSymbol= new SimpleMarkerSymbol().setStyle(
|
||||
SimpleMarkerSymbol.STYLE_DIAMOND).setColor(
|
||||
new Color([255,0,0,0.5])).setSize(35);
|
||||
}
|
||||
else{
|
||||
defaultSymbol= new SimpleMarkerSymbol().setStyle(
|
||||
SimpleMarkerSymbol.STYLE_DIAMOND).setColor(
|
||||
new Color([255,0,0,0.5])).setSize(20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function startMap(){
|
||||
|
||||
//Make sure map shows up after a browser refresh
|
||||
@ -240,7 +241,7 @@
|
||||
|
||||
tileLayer.offline.proxyPath = null;
|
||||
|
||||
var map = BootstrapMap.create("mapDiv",{
|
||||
map = BootstrapMap.create("mapDiv",{
|
||||
center: [-104.99,39.75], // long, lat
|
||||
zoom: 17,
|
||||
sliderStyle: "small"
|
||||
@ -275,6 +276,8 @@
|
||||
// Just be aware of the localStorage limitations.
|
||||
busStopFeatureLayer.convertGraphicLayerToJSON(features,evt,function(features,layerDef){
|
||||
|
||||
updateLocalStorage();
|
||||
|
||||
if(typeof(Storage) !== "undefined") {
|
||||
localStorage.offlineLayerDef = layerDef;
|
||||
localStorage.offlineFeature = features;
|
||||
@ -287,10 +290,12 @@
|
||||
|
||||
map.on("zoom-end",function(evt){
|
||||
_currentExtent = evt.extent;
|
||||
updateLocalStorage();
|
||||
});
|
||||
|
||||
map.on("pan-end",function(evt){
|
||||
_currentExtent = evt.extent;
|
||||
updateLocalStorage();
|
||||
});
|
||||
|
||||
map.on("load",function(evt){
|
||||
@ -299,8 +304,19 @@
|
||||
updateOfflineUsage();
|
||||
updateStatus();
|
||||
|
||||
//**************************************************
|
||||
//
|
||||
// This is where we detect an offline condition
|
||||
// within the lifecycle of the "mapping" application.
|
||||
// If we are offline then run our offline
|
||||
// specific code for reconstituting our map.
|
||||
//
|
||||
//**************************************************
|
||||
|
||||
if(_isOnline == false){
|
||||
|
||||
// Set the map to the
|
||||
|
||||
var featureLayer = JSON.parse(localStorage.offlineLayerDef);
|
||||
var featuresArray = JSON.parse(localStorage.offlineFeature);
|
||||
var geometryType = "esriGeometryPoint";
|
||||
@ -309,6 +325,7 @@
|
||||
|
||||
busStopFeatureLayer.getFeatureDefinition(featureLayer,featuresArray,geometryType,function(featureDef){
|
||||
|
||||
// Use the feature layer returns from getFeatureDefinition() to reconstitute the layer
|
||||
busStopFeatureLayer = new FeatureLayer(featureDef,{
|
||||
mode: FeatureLayer.MODE_SNAPSHOT,
|
||||
outFields: ["OBJECTID","BSID","ROUTES","STOPNAME"]
|
||||
@ -324,6 +341,21 @@
|
||||
|
||||
setFeatureLayerClickHandler();
|
||||
setModalPopupClickListeners();
|
||||
updatePhantomGraphicsLayer();
|
||||
|
||||
// Restore our map to its last extent before the browser restarted!
|
||||
var e = JSON.parse(localStorage.offlineExtent);
|
||||
var extent = new Extent({
|
||||
"xmin": e.xmin,
|
||||
"ymin": e.ymin,
|
||||
"xmax": e.xmax,
|
||||
"xmin": e.xmin,
|
||||
"spatialReference":{"wkid": e.spatialReference}
|
||||
})
|
||||
var zoom = parseInt(localStorage.offlineZoom);
|
||||
map.setExtent(extent);
|
||||
map.setZoom(zoom);
|
||||
|
||||
mapListen.remove();
|
||||
})
|
||||
map.addLayer(busStopFeatureLayer);
|
||||
@ -349,9 +381,9 @@
|
||||
// Refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/en/javascript/jshelp/ags_proxy.html
|
||||
offlineFeaturesManager.proxyPath = null;
|
||||
|
||||
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED, updateStatus);
|
||||
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_ENQUEUED, editsEnqueued);
|
||||
offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT, updateStatus);
|
||||
offlineFeaturesManager.on(offlineFeaturesManager.events.ALL_EDITS_SENT, updateStatus);
|
||||
offlineFeaturesManager.on(offlineFeaturesManager.events.ALL_EDITS_SENT, allEditsSent);
|
||||
|
||||
offlineFeaturesManager.extend(busStopFeatureLayer);
|
||||
console.log("offlineFeaturesManager initialized.");
|
||||
@ -359,17 +391,27 @@
|
||||
Offline.check();
|
||||
Offline.on('up', goOnline);
|
||||
Offline.on('down', goOffline);
|
||||
|
||||
// If the app is online then set offlineFeaturesManager to its online state
|
||||
// This will force the library to check for pending edits and attempt to
|
||||
// resend them to the Feature Service.
|
||||
if(_isOnline == true){
|
||||
offlineFeaturesManager.goOnline();
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatus(){
|
||||
if( editsStore.hasPendingEdits())
|
||||
{
|
||||
var edits = editsStore.retrieveEditsQueue();
|
||||
pendingEdits.innerHTML = edits.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingEdits.innerHTML = "0";
|
||||
// Keep latest extent and zoom level available in case of an offline browser restart
|
||||
function updateLocalStorage(){
|
||||
|
||||
var zoom = map.getZoom();
|
||||
var extent = JSON.stringify(map.extent);
|
||||
|
||||
if(typeof(Storage) !== "undefined") {
|
||||
localStorage.offlineZoom = zoom;
|
||||
localStorage.offlineExtent = extent;
|
||||
console.log("Done updating zoom and extent to localStorage.")
|
||||
} else {
|
||||
alert("The offline library is not supported on this browser.")
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,10 +446,18 @@
|
||||
|
||||
saveBtn.onclick = function(evt){
|
||||
|
||||
// Best practice is to uncomment these for production use.
|
||||
//forceInternalOfflineCheck();
|
||||
|
||||
popup.graphic.attributes.ROUTES = stopRoutes.value;
|
||||
popup.graphic.attributes.STOPNAME = stopNames.value;
|
||||
|
||||
busStopFeatureLayer.applyEdits(null,[popup.graphic],null,function(result){
|
||||
updateFeatureLayerJSON(
|
||||
busStopFeatureLayer.graphics,
|
||||
popup.graphic.attributes.OBJECTID,
|
||||
stopRoutes.value,
|
||||
stopNames.value);
|
||||
console.log("Successfully saved changes to: " + popup.graphic.attributes.STOPNAME);
|
||||
hideModalPopup();
|
||||
},
|
||||
@ -417,7 +467,16 @@
|
||||
}
|
||||
|
||||
deleteBtn.onclick = function(evt){
|
||||
|
||||
// Best practice is to uncomment these for production use
|
||||
//forceInternalOfflineCheck();
|
||||
|
||||
busStopFeatureLayer.applyEdits(null,null,[popup.graphic],function(result){
|
||||
updateFeatureLayerJSON(
|
||||
busStopFeatureLayer.graphics,
|
||||
popup.graphic.attributes.OBJECTID,
|
||||
stopRoutes.value,
|
||||
stopNames.value);
|
||||
console.log("Successfully deleted: " + popup.graphic.attributes.STOPNAME);
|
||||
hideModalPopup();
|
||||
},
|
||||
@ -436,6 +495,34 @@
|
||||
popup.hide();
|
||||
}
|
||||
|
||||
//Temporary test - this should be added to offlineFeaturesManager
|
||||
//Provide a callback of the stringified JSON.
|
||||
//Upon restart allows feature layer to show latest edits.
|
||||
//Still need to wire this up to phantom symbols somehow.
|
||||
//Maybe serialize Phantom graphic layer as well and reconstitute it on restart?
|
||||
function updateFeatureLayerJSON(features,id,routes,stopnames){
|
||||
var length = features.length;
|
||||
|
||||
var f = JSON.parse(localStorage.offlineFeature);
|
||||
var arrLength = f.length;
|
||||
|
||||
for(var a = 0; a < arrLength; a++){
|
||||
if(f[a].attributes.OBJECTID == id){
|
||||
f[a].attributes.ROUTES = routes;
|
||||
f[a].attributes.STOPNAME = stopnames;
|
||||
var fJson = JSON.stringify(f);
|
||||
if(typeof(Storage) !== "undefined") {
|
||||
localStorage.offlineFeature = fJson;
|
||||
console.log("Done pushing layerDef and features to localStorage.");
|
||||
} else {
|
||||
alert("convertFeatureLayerToJSON: Unable to update Local Storage.");
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* TILE MANAGEMENT CODE
|
||||
@ -512,6 +599,9 @@
|
||||
* ************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Forces offlineFeaturesManager online
|
||||
*/
|
||||
function goOnline(){
|
||||
console.log("Going online...");
|
||||
|
||||
@ -536,6 +626,9 @@
|
||||
if(typeof tileLayer != "undefined") tileLayer.goOnline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces offlineFeaturesManager offline
|
||||
*/
|
||||
function goOffline(){
|
||||
console.log("Going offline...");
|
||||
btnOnlineOffline.innerHTML = "2. Go Online";
|
||||
@ -546,6 +639,9 @@
|
||||
if(typeof tileLayer != "undefined") tileLayer.goOffline();
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles offlineFeaturesManager online/offline
|
||||
*/
|
||||
function goOnlineOffline(){
|
||||
if(offlineFeaturesManager.getOnlineStatus() == offlineFeaturesManager.ONLINE){
|
||||
goOffline();
|
||||
@ -570,6 +666,19 @@
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces a check of the Offline.js state
|
||||
*/
|
||||
function forceInternalOfflineCheck(){
|
||||
Offline.check();
|
||||
if(Offline.state == "up"){
|
||||
goOnline();
|
||||
}
|
||||
if(Offline.state == "down"){
|
||||
goOffline();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts an http request to verify if app is online or offline.
|
||||
* Use this in conjunction with the offline checker library: offline.min.js
|
||||
@ -598,6 +707,65 @@
|
||||
req.send(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* ***********************************************
|
||||
* OFFLINE FEATURE MANAGER - EVENT MANAGEMENT CODE
|
||||
* ***********************************************å
|
||||
*/
|
||||
|
||||
function editsEnqueued(){
|
||||
if( editsStore.hasPendingEdits())
|
||||
{
|
||||
var edits = editsStore.retrieveEditsQueue();
|
||||
pendingEdits.innerHTML = edits.length;
|
||||
|
||||
//Make sure we store phantom layer graphics so that we have them if the browser is restarted
|
||||
if(busStopFeatureLayer != null && typeof busStopFeatureLayer.getPhantomLayerGraphics !== "undefined") {
|
||||
var graphics = busStopFeatureLayer.getPhantomLayerGraphics(function(result){
|
||||
localStorage.offlinePhantomGraphics = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingEdits.innerHTML = "0";
|
||||
}
|
||||
}
|
||||
|
||||
function allEditsSent(){
|
||||
if( editsStore.hasPendingEdits())
|
||||
{
|
||||
var edits = editsStore.retrieveEditsQueue();
|
||||
pendingEdits.innerHTML = edits.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingEdits.innerHTML = "0";
|
||||
// Clear out the phantom layer
|
||||
localStorage.setItem("offlinePhantomGraphics","");
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatus(){
|
||||
if( editsStore.hasPendingEdits())
|
||||
{
|
||||
var edits = editsStore.retrieveEditsQueue();
|
||||
pendingEdits.innerHTML = edits.length;
|
||||
}
|
||||
else
|
||||
{
|
||||
pendingEdits.innerHTML = "0";
|
||||
}
|
||||
}
|
||||
|
||||
function updatePhantomGraphicsLayer(){
|
||||
var phantomLocalGraphics = localStorage.offlinePhantomGraphics;
|
||||
if(phantomLocalGraphics){
|
||||
var graphics = JSON.parse(phantomLocalGraphics);
|
||||
busStopFeatureLayer.setPhantomLayerGraphics(graphics);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ************************************
|
||||
* APPCACHE MANAGEMENT CODE
|
||||
@ -624,7 +792,7 @@
|
||||
|
||||
function cacheErrorHandler(evt){
|
||||
console.log("CACHE ERROR: " + JSON.stringify(evt));
|
||||
alert("There was a problem loading the cache. Try reloading the app. ")
|
||||
//alert("There was a problem loading the cache. ");
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -5,11 +5,11 @@
|
||||
"https://www.npmjs.org/doc/cli/npm-init.html"
|
||||
],
|
||||
"name": "manifest-generator",
|
||||
"manifestName": "appcache-tiles.appcache",
|
||||
"appHomePage": "appcache-tiles.html",
|
||||
"manifestName": "appcache-features.appcache",
|
||||
"appHomePage": "appcache-features.html",
|
||||
"optimizedApiURL": "../samples/jsolib",
|
||||
"arcGISBaseURL": "http://js.arcgis.com/3.11",
|
||||
"version": "2.3",
|
||||
"version": "2.4",
|
||||
"private": true,
|
||||
"description": "manifest generator project",
|
||||
"repository": {
|
||||
|
||||
@ -29,14 +29,14 @@
|
||||
opacity: 0.5;
|
||||
background-color: black;
|
||||
z-index: 99;
|
||||
display: table;
|
||||
overflow: visible;
|
||||
}
|
||||
.mod-popup-input {
|
||||
border-bottom: solid #ffffff 1px;
|
||||
width: 80%;
|
||||
display: table-cell;
|
||||
vertical-align: middle;
|
||||
padding: 12px;
|
||||
padding-left: 12px;
|
||||
}
|
||||
.mod-popup-label {
|
||||
padding: 12px;
|
||||
@ -145,6 +145,12 @@
|
||||
.mod-popup-button-cancel:active {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-stop-input {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-stop-input-disabled {
|
||||
font-size: small;
|
||||
}
|
||||
}
|
||||
@media (max-width: 450px) {
|
||||
.mod-popup-button {
|
||||
@ -159,4 +165,34 @@
|
||||
.mod-popup-button-cancel:active {
|
||||
font-size: x-small;
|
||||
}
|
||||
.mod-popup-stop-input {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-stop-input-disabled {
|
||||
font-size: small;
|
||||
}
|
||||
}
|
||||
@media (max-height: 500px) {
|
||||
|
||||
.mod-popup-button {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-button:active{
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-button-cancel {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-button-cancel:active {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-stop-input {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-stop-input-disabled {
|
||||
font-size: small;
|
||||
}
|
||||
.mod-popup-modal-background {
|
||||
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ define([
|
||||
},
|
||||
|
||||
_handleCacheErrors:function(evt){
|
||||
this.emit(this.CACHE_EVENT,evt);
|
||||
this.emit(this.CACHE_ERROR,evt);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user