diff --git a/CHANGELOG.md b/CHANGELOG.md index 623e633d..2c44391f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # offline-editor-js - Changelog +## Version 2.3 - Oct 13, 2014 +- Closes #74 - Build sample with nice UX for editing +- Closes #257 - Build getting started pages for AGOL, editing and TPK. All samples show basic functionality and are responsive. Also integrated a new launch page for the API and How To Use docs. +- Closes #258 - Convert modal popup to widget +- The following samples were updated to be responsive: + - appcache-features.html + - appcache-tiles.html + - tpk-layer.html + +New functionality: + +- Closes #256 - Add getMaxZoom and getMinZoom to offlineTilesEnabler +- Added getMinMaxLOD() to offlineTilesEnabler and OfflineTilesEnablerLayer + +Breaking Changes - None. + + ## Version 2.2.1 - Oct 1, 2014 Added a Getting Started for Tiles tutorial. diff --git a/README.md b/README.md index 211162c3..d1e169ee 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ offline-editor-js Offline-editor-js is a set of JavaScript libraries for using the ArcGIS API for JavaScript offline. It offers both lightweight editing and tile management capabilities while offline or intermittently offline. It's a work-in-progress so if you have suggestions open an issue or if you want to make a pull request we welcome your proposed modifications. -Online samples and tutorials are available here: [http://esri.github.io/offline-editor-js/demo/](http://esri.github.io/offline-editor-js/demo/) +Online samples and getting started tutorials are available here: **[http://esri.github.io/offline-editor-js/demo/](http://esri.github.io/offline-editor-js/demo/)** *IMPORTANT:* If you need a fully integrated robust offline solution then you should be using our ArcGIS Runtime SDKs for .NET, WPF, Java, iOS, Android and Qt. This repo contains the following libraries: - `/dist`: - * `offline-edit-min.js` - _(replaces v1.x of OfflineFeaturesManager.js)_ stores adds, updates and deletes of features as well as limited attachment support while offline. Resync's edits with server once connection is reestablished. - * `offline-tiles-basic-min.js` - _(replaces v1.x of offlineTilesEnabler.js)_ caches map tiles for partial offline use cases. Use this library with ArcGIS Online Web maps as well as with tiled map services. This repo will not work with browser restarts or reloads while offline. - * `offline-tiles-advanced-min.js` - _(replaces v1.x of OfflineTilesEnablerLayer.js)_ Extends any ArcGIS Tiled Map Service that has a requirement for offline browser reload and/or restart. This library should be used in conjunction with an HTML5 application cache coding pattern. - * `offline-tpk-min.js` - _(replaces v1.x of TPKLayer.js)_ parses a TPK file and displays it as a tiled map layer. + * `offline-edit-min.js` - stores adds, updates and deletes of features as well as limited attachment support while offline. Resync's edits with server once connection is reestablished. + * `offline-tiles-basic-min.js` - caches map tiles for partial offline use cases. Use this library with ArcGIS Online Web maps as well as with tiled map services. This repo will not work with browser restarts or reloads while offline. + * `offline-tiles-advanced-min.js` - Extends any ArcGIS Tiled Map Service that has a requirement for offline browser reload and/or restart. This library should be used in conjunction with an HTML5 application cache coding pattern. + * `offline-tpk-min.js` - parses a TPK file and displays it as a tiled map layer. - `/utils`: contains various helper library modules. These modules are all AMD compliant. - `/samples`: samples that show how to use the different offline libraries capabilities. @@ -33,31 +33,9 @@ Using an [application manifest](https://developer.mozilla.org/en-US/docs/HTML/Us __Attachment Support__: Attachments are supported with some limitations. See documentation [here](./doc/attachments.md) -#API Doc +#API and How To Use Docs -##Offline Editing of Geographic Features -Extends and overrides an ArcGIS Feature Layer. This library allows you to extend esri.layers.FeatureLayer with offline capabilities and to manage the resync process. - -* __Click [here](doc/offlinefeaturesmanager.md) to see the full API doc for `offline-edit-min.js`__ - - -##Offline Mapping Tiles -Extends and overrides a tiled map service. Provides the ability to customize the extent used to cut the tiles. See the detailed description of basemap.prepareForOffline() in the "How To Use" section to learn different options. - -* __Click [here](doc/offlinetilesenabler.md) to see the full API doc for `offline-tiles-basic-min.js and offline-tiles-advanced-min.js`__ - -##TPKLayer - -You can display TPK files with this library. TPK's are binary tile package files. Extends TileMapServiceLayer. Go [here](http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000017w000000) for more information on how to create a TPK file. - -* __Click [here](doc/tpklayer.md) to see the full API doc for `offline-tpk-min.js`__ - -##How to use - -* [Learn more about using the `tile` library](doc/howtousetiles.md) -* [Learn more about using the `edit` library](doc/howtouseeditlibrary.md) -* [Learn more about using the `tpk` library](doc/howtousetpklibrary.md) -* [Learn more about using an application cache with this library](doc/howtouseappcache.md) +Go __[here](demo/api-doc.html)__ to get links to the API docs and How to use docs. ## Migrating from v1 to v2 @@ -76,18 +54,6 @@ If you are migrating your v1 code to v2 then go [here](doc/migratefromv1tov2.md) 1. From the root directory run `npm install` 2. Run `Grunt build`. If there are no errors, the minimized _(min)_ and source _(src)_ versions of the libraries will be output to `\dist` - -##Samples - -* `appcache-features.html` - shows how to work with the application manifest, tiles and features. This sample works with browser reloads and restarts. -* `appcache-tiles.html` - shows how to work with the application manifest and map tiles. This sample works with browser reloads and restarts. -* `attachments-editor.html` - demonstrates how to work with this library using feature attachments. -* `draw-pointlinepoly-offline.html` shows working with points, lines and polygons locally. -* `tpklayer.html` - shows how to work with TPK files. -* `tiles-indexed-db.html` - shows how to work with storing tiles locally. -* `Gruntfile.js` - a node.js app and its associated `package.json` file to help with creating an application manifest file. - - ##Dependencies * ArcGIS API for JavaScript (v3.8+) diff --git a/demo/api-doc.html b/demo/api-doc.html new file mode 100644 index 00000000..a22b559a --- /dev/null +++ b/demo/api-doc.html @@ -0,0 +1,167 @@ + + + + + + + + + Offline-editor-js + + + + + + + + + + + + + + + + + + + + + + + +
+
+

API Docs

+

Documentation for the offline-editor-js JavaScript libraries.

+
+
+ +
+ +
+
+ +
+
+

Offline Tiles - Basic

+

The offline-tiles-basic-min.js library is for use with ArcGIS.com web maps and partial/intermittently offline use cases. + You won't be able to restart or reload your app when using this library offline. +

+
+ +
+ +
+
+

Offline Tiles - Advanced

+

The offline-tiles-advanced-min.js library is for use with tiled map services in partial or fully offline use cases. + If you have a requirement to reload or restart your app while offline you should use this library. +

+
+ +
+ +
+
+

Offline Features

+

The offline-edit-min.js library is for working with ArcGIS JS API points, lines and polygons in partial or fully offline use cases. +

+
+ +
+ +
+
+

Offline TPK

+

The offline-tpk-min.js library is for working with TPK files in partial or fully offline use cases. + TPK files are binary tile image packages. They can be used stand-alone or alongside tiled base maps. +

+
+
+ +
+
+ +
+
+
+ + + + + + + + + + \ No newline at end of file diff --git a/demo/getstarted-agol.html b/demo/getstarted-agol.html new file mode 100644 index 00000000..5d802cf2 --- /dev/null +++ b/demo/getstarted-agol.html @@ -0,0 +1,862 @@ + + + + + + + + + Offline-editor-js + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Getting Started with ArcGIS.com

+

Basic steps for working with ArcGIS.com base maps for offline.

+ +
+
+ +
+ +
+
+ + + +
+
+

Step 1: Fill in the basics

+

Add the basic library references. Then test to make sure map loads.

+
+
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline ArcGIS.com</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+        body {
+            background-color: #ffffff;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+        .floatRight {float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container">
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "esri/arcgis/utils",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tiles-basic-src.js",
+        "dojo/domReady!"],
+        function(Map,on,arcgisUtils,BootstrapMap) {
+
+            var map;
+
+            // Load the map
+            arcgisUtils.createMap("bbc1a04a3eca4430be144d7a08b43a17","mapDiv").then(function(response){
+                var map = response.map;
+
+                map = response.map;
+
+                // Initialize BootstrapMap to make the map responsive
+                BootstrapMap.create(map);
+
+            });
+        });
+</script>
+
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+
+

Step 2: Extend basemap using the offline library

+

This initializes the OfflineTilesEnabler library and tells it which tiled map service layer to use for offline. Test to make sure map loads.

+
+ +
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline ArcGIS.com</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        html, body, #map {
+            height: 100%;
+            width: 100%;
+            margin: 0;
+            padding: 0;
+        }
+        body {
+            background-color: #000000;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+        .floatRight {float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="row">
+    <div class="col-xs-12">
+        <div id="mapDiv"></div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "esri/arcgis/utils",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tiles-basic-src.js",
+        "dojo/domReady!"],
+        function(Map,on,arcgisUtils,BootstrapMap) {
+
+            var map, basemapLayer;
+            var offlineTilesEnabler = new O.esri.Tiles.OfflineTilesEnabler();
+
+            showMap();
+
+
+            function showMap(){
+                // Load the map
+                arcgisUtils.createMap("bbc1a04a3eca4430be144d7a08b43a17","mapDiv").then(function(response){
+                    map = response.map;
+
+                    // Initialize BootstrapMap to make the map responsive
+                    BootstrapMap.create(map);
+
+                    // Get the ArcGIS.com basemap that we want to use offline.
+                    // And then extend it for offline use.
+                    if(map.loaded)
+                    {
+                        basemapLayer = map.getLayer( map.layerIds[0] );
+                        initializeOfflineTiles();
+
+                    }
+                    else
+                    {
+                        map.on("load",function()
+                        {
+                            basemapLayer = map.getLayer( map.layerIds[0] );
+                            initializeOfflineTiles();
+                        });
+                    }
+
+                });
+            }
+
+            function initializeOfflineTiles(){
+                offlineTilesEnabler.extend(basemapLayer,function(success) {
+                    if (success) {
+                        console.log("ArcGIS.com map extended for offline!")
+                    }
+                })
+            }
+        });
+</script>
+
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+ +
+ +
+

Step 3: Configure tiles download.

+

Enable the ability to download tiles as well the ability to toggle online and offline.

+
+ + + +
+ + +
+
+
+                            
+
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline ArcGIS.com</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+        body {
+            background-color: #ffffff;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+
+        .floatRight {float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container">
+    <div class="row">
+        <div class="col-xs-10">
+            <div class="form form-group btn-group" data-toggle="buttons">
+                <button class="btn btn-success" id="btn-get-tiles">1. Download Tiles</button>
+                <button class="btn btn-success" disabled id="btn-online-offline">2. Go Offline</button>
+                <button class="btn btn-success" disabled id="btn-pan-left">3. Pan left</button>
+            </div>
+        </div>
+        <div class="col-xs-2">
+            <!-- this indicates whether app is offline (down) or online (up) -->
+            <button id="btn-state" class="btn btn-success btn-large floatRight">
+                <span id="state-span" class="glyphicon glyphicon-link"> Up</span>
+            </button>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "esri/arcgis/utils",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tiles-basic-src.js",
+        "dojo/domReady!"],
+        function(Map,on,arcgisUtils,BootstrapMap) {
+
+            var map, basemapLayer;
+            var offlineTilesEnabler = new O.esri.Tiles.OfflineTilesEnabler();
+
+            // Check if browser state is online or offline
+            Offline.check();
+            Offline.on('up down', updateState );
+
+            // For cancelling the download of tiles
+            var _wantToCancel;
+            var _downloadState = "downloaded";
+
+            // Set up min and max boundaries for retrieving tiles
+            var minZoomAdjust = -1, maxZoomAdjust = 1, mMinZoom, mMaxZoom;
+
+            // Set up button click listeners.
+            var btnGetTiles = document.getElementById("btn-get-tiles");
+            var btnOnlineOffline = document.getElementById("btn-online-offline");
+            var btnPanLeft = document.getElementById("btn-pan-left");
+
+            var imgOfflineIndicator = document.getElementById("state-span");
+            var btnState = document.getElementById("btn-state");
+
+            on(btnGetTiles,"click",downloadTiles);
+            on(btnOnlineOffline,"click",goOnlineOffline);
+            on(btnPanLeft,"click",panLeft);
+
+            showMap();
+
+
+            function showMap(){
+                // Load the map
+                arcgisUtils.createMap("bbc1a04a3eca4430be144d7a08b43a17","mapDiv").then(function(response){
+                    map = response.map;
+
+                    // Initialize BootstrapMap to make the map responsive
+                    BootstrapMap.create(map);
+
+                    // Get the ArcGIS.com basemap that we want to use offline.
+                    // And then extend it for offline use.
+                    if(map.loaded)
+                    {
+                        basemapLayer = map.getLayer( map.layerIds[0] );
+                        initializeOfflineTiles();
+
+                    }
+                    else
+                    {
+                        map.on("load",function()
+                        {
+                            basemapLayer = map.getLayer( map.layerIds[0] );
+                            initializeOfflineTiles();
+                        });
+                    }
+
+                });
+            }
+
+            function initializeOfflineTiles(){
+                offlineTilesEnabler.extend(basemapLayer,function(success) {
+                    if (success) {
+                        console.log("ArcGIS.com map extended for offline!")
+                    }
+                })
+            }
+
+            function downloadTiles(){
+
+                if(_downloadState == "downloading"){
+                    _wantToCancel = true;
+                }
+                else{
+                    _wantToCancel = false;
+
+                    // First delete any existing tiles from database
+                    basemapLayer.deleteAllTiles(function(success,err){
+                        var zoom = basemapLayer.getMinMaxLOD(minZoomAdjust,maxZoomAdjust);
+
+                        // Now download tiles
+                        basemapLayer.prepareForOffline(zoom.min, zoom.max, map.extent, function(progress){
+                            console.log("downloading tiles...");
+
+                            if(progress.hasOwnProperty("countNow")){
+                                var percent = Math.floor(progress.countNow / progress.countMax * 100);
+                                btnGetTiles.innerHTML = 'Saving to phone ' + percent + "% - Tap to Cancel";
+                            }
+
+                            if( progress.finishedDownloading )
+                            {
+                                btnGetTiles.innerHTML = "Saving to phone 100% - Tap to Cancel";
+
+                                if( progress.cancelRequested )
+                                {
+                                    alert("Tile download was cancelled");
+                                    _downloadState = "cancelled";
+                                }
+                                else
+                                {
+                                    alert("Tile download complete");
+                                    _downloadState = "downloaded";
+                                    btnOnlineOffline.disabled = false;
+                                }
+
+                                btnGetTiles.innerHTML = '1. Download Tiles';
+                            }
+                            return _wantToCancel; //determines if a cancel request has been issued
+                        });
+
+                        _downloadState = "downloading";
+
+                    });
+                }
+            }
+
+            // Force the tileLayer between online and offline
+            function goOnlineOffline(){
+
+                btnPanLeft.disabled = false;
+
+                if(btnOnlineOffline.innerHTML == "2. Go Offline"){
+                    toggleStateUp(false);
+                    console.log("Map is offline");
+                }
+                else{
+                    toggleStateUp(true);
+                    console.log("Map is online");
+                }
+            }
+
+            function toggleStateUp(state){
+                if(state){
+                    btnOnlineOffline.innerHTML = "2. Go Offline";
+                    basemapLayer.goOnline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-link";
+                    imgOfflineIndicator.innerHTML = " Up";
+                    btnState.className = "btn btn-success btn-large floatRight";
+                }
+                else{
+                    btnOnlineOffline.innerHTML = "2. Go Online";
+                    basemapLayer.goOffline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-thumbs-down";
+                    imgOfflineIndicator.innerHTML = " Down";
+                    btnState.className = "btn btn-danger btn-large floatRight";
+                }
+            }
+
+            // Set the ArcGIS.com map online or offline.
+            // When set offline it will look for tiles in the tiles database
+            function updateState(){
+                if(Offline.state === 'up'){
+                    if(typeof basemapLayer != "undefined") basemapLayer.goOnline();
+                    toggleStateUp(true);
+                }
+                else{
+                    if(typeof basemapLayer != "undefined") basemapLayer.goOffline();
+                    toggleStateUp(false);
+                }
+            }
+
+            // Pan left when "offline" to view only tiles that have been stored locally
+            function panLeft(){
+                map.panLeft();
+            }
+        });
+</script>
+
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+
+</body>
+</html>
+
+                            
+                        
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+ +
+
+
+
+ + + +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/getstarted-editing.html b/demo/getstarted-editing.html new file mode 100644 index 00000000..14e0f857 --- /dev/null +++ b/demo/getstarted-editing.html @@ -0,0 +1,1190 @@ + + + + + + + + + Get Started Editing + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Getting Started with Editing

+

Basic steps for working with Editing geographic features for offline.

+ +
+
+ +
+ +
+
+ + + +
+
+

Step 1: Fill in the basics

+

Add library references and build basic layout. Then test to make sure map loads.

+
+
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Features</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"">
+    <link rel="stylesheet" href="widgets/css/modal-popup.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        #img-offline-indicator {
+            padding: 8px;
+            position: relative; float: right;
+        }
+
+        /* Override mod-popup default */
+        .mod-popup-stop-input {color: black;}
+        .span-pending {color: blue; padding-left: 1em;}
+        .voffset20px { margin-top: 20px; }
+        .floatRight { float: right}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set how we pull in custom AMD modules
+        var path = location.pathname.replace(/[^\/]+$/, '');
+        var dojoConfig =
+        {
+            debug: true,
+            packages:[
+                {
+                    name: "widgets",
+                    location: path + "widgets/"
+                }]
+        }
+
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container voffset20px">
+    <div class="row">
+        <div class="col-xs-8">
+            <button class="btn btn-success" id="btn-online-offline">Go Offline</button>
+            <span class="span-pending">Pending Edits <span id="span-pending-edits" class="badge">0</span></span>
+        </div>
+        <div class="col-xs-4">
+            <button id="btn-state" class="btn btn-success btn-large floatRight">
+                <span id="state-span" class="glyphicon glyphicon-link"> Up</span>
+            </button>
+        </div>
+    </div>
+    <div class="row voffset20px">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+<!-- Stub for modal popup -->
+<div id="modal-popup"></div>
+
+<script>
+
+require([
+        "esri/map","esri/tasks/query",
+        "dojo/on","dojo/parser", "esri/renderers/SimpleRenderer",
+        "esri/symbols/SimpleMarkerSymbol","esri/Color",
+        "widgets/popup","esri/layers/FeatureLayer",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-edit-src.js",
+        "dojo/domReady!"],
+        function(Map,Query,on,parser,SimpleRenderer,SimpleMarkerSymbol,
+            Color,ModalPopup,FeatureLayer,BootstrapMap){
+
+            var map, popup, editsStore;
+            var defaultSymbol;
+            var offlineFeaturesManager;
+            var btnOnlineOffline, btnState, pendingEdits;
+            var imgOfflineIndicator;
+            var closeBtn,saveBtn,deleteBtn,stopMainID,stopID,stopRoutes,stopNames;
+
+            initMap();
+
+            function initMap(){
+
+                map = BootstrapMap.create("mapDiv",{
+                    basemap: "topo",
+                    center: [-104.99,39.75], // longitude, latitude
+                    zoom: 15
+                });
+            }
+        }
+);
+
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+
+

Step 2: Configure modal popup

+

This initializes and configures the modal popup. Test to make sure map loads and popup displays.

+
+ +
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Features</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"">
+    <link rel="stylesheet" href="../samples/widgets/modal/css/modal-popup.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        #img-offline-indicator {
+            padding: 8px;
+            position: relative; float: right;
+        }
+
+        /* Override mod-popup default */
+        .mod-popup-stop-input {color: black;}
+        .span-pending {color: blue; padding-left: 1em;}
+        .voffset20px { margin-top: 20px; }
+        .floatRight { float: right}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set how we pull in custom AMD modules
+        var path = location.pathname.replace(/[^\/]+$/, '');
+        var dojoConfig =
+        {
+            debug: true,
+            packages:[
+                {
+                    name: "widgets",
+                    location: path + "../samples/widgets/"
+                }]
+        }
+
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container voffset20px">
+    <div class="row">
+        <div class="col-xs-8">
+            <button class="btn btn-success" id="btn-online-offline">Go Offline</button>
+            <span class="span-pending">Pending Edits <span id="span-pending-edits" class="badge">0</span></span>
+        </div>
+        <div class="col-xs-4">
+            <button id="btn-state" class="btn btn-success btn-large floatRight">
+                <span id="state-span" class="glyphicon glyphicon-link"> Up</span>
+            </button>
+        </div>
+    </div>
+    <div class="row voffset20px">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+<!-- Stub for modal popup -->
+<div id="modal-popup"></div>
+
+<script>
+
+require([
+        "esri/map","esri/tasks/query",
+        "dojo/on","dojo/parser", "esri/renderers/SimpleRenderer",
+        "esri/symbols/SimpleMarkerSymbol","esri/Color",
+        "widgets/modal/popup","esri/layers/FeatureLayer",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-edit-src.js",
+        "dojo/domReady!"],
+        function(Map,Query,on,parser,SimpleRenderer,SimpleMarkerSymbol,
+             Color,ModalPopup,FeatureLayer,BootstrapMap) {
+
+            var map, popup, editsStore;
+            var defaultSymbol;
+            var offlineFeaturesManager;
+            var btnOnlineOffline, btnState, pendingEdits;
+            var imgOfflineIndicator;
+            var closeBtn,saveBtn,deleteBtn,stopMainID,stopID,stopRoutes,stopNames;
+
+            initVars();
+            initMap();
+
+            function initMap(){
+
+                map = BootstrapMap.create("mapDiv",{
+                    basemap: "topo",
+                    center: [-104.99,39.75], // longitude, latitude
+                    zoom: 15
+                });
+
+                map.on("load",function(evt){
+                    console.log("Map is loaded. Loading popup...")
+                    window.setTimeout(function(){
+                        popup.show();
+                    },2000);
+                });
+            }
+
+
+            function initVars(){
+
+                editsStore = new O.esri.Edit.EditStore();
+                popup = new ModalPopup({animation: true, animationDuration: 1},"modal-popup");
+                popup.startup();
+
+                parser.parse();
+
+                // Check if browser state is online or offline
+                Offline.check();
+                Offline.on('up down', updateState );
+
+
+                btnOnlineOffline = document.getElementById("btn-online-offline");
+                imgOfflineIndicator = document.getElementById("state-span");
+                btnState = document.getElementById("btn-state");
+                pendingEdits = document.getElementById("span-pending-edits");
+
+                // 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);
+                }
+
+                // Variables for modal popup
+                closeBtn = document.getElementById("mod-popup-close-btn");
+                saveBtn = document.getElementById("mod-popup-save-btn");
+                deleteBtn = document.getElementById("mod-popup-delete-btn");
+                stopMainID = document.getElementById("stop-main-id");
+                stopID = document.getElementById("stop-id");
+                stopRoutes = document.getElementById("stop-routes");
+                stopNames = document.getElementById("stop-names");
+
+            }
+
+            function setModalPopupClickListeners(){
+                closeBtn.onclick = function(evt){
+                    hideModalPopup();
+                }
+
+                saveBtn.onclick = function(evt) {
+                    //TO-DO
+                }
+
+            }
+
+            function showModalPopup(graphic){
+                popup.graphic = graphic; // assign graphic to modPopup as a property.
+                popup.show();
+            }
+
+            function hideModalPopup(){
+                popup.hide();
+            }
+
+            // Force feature service offline
+            function goOnlineOffline(){
+
+                if(btnOnlineOffline.innerHTML == "Go Offline"){
+                    toggleStateUp(false);
+                    console.log("Map is offline");
+                }
+                else{
+                    toggleStateUp(true);
+                    console.log("Map is online");
+                }
+            }
+
+            // Set the UX to online or offline state
+            function toggleStateUp(state){
+                if(state){
+                    btnOnlineOffline.innerHTML = "Go Offline";
+                    offlineFeaturesManager.goOnline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-link";
+                    imgOfflineIndicator.innerHTML = " Up";
+                    btnState.className = "btn btn-success btn-large floatRight";
+                }
+                else{
+                    btnOnlineOffline.innerHTML = "Go Online";
+                    offlineFeaturesManager.goOffline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-thumbs-down";
+                    imgOfflineIndicator.innerHTML = " Down";
+                    btnState.className = "btn btn-danger btn-large floatRight";
+                }
+            }
+
+            // Automatically set the feature service online or offline.
+            function updateState(){
+                if(Offline.state === 'up'){
+                    toggleStateUp(true);
+                }
+                else{
+                    toggleStateUp(false);
+                }
+            }
+        }
+);
+
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+ +
+ +
+

Step 3: Configure offline editing.

+

Enable the ability to store features (points, lines and polygons) while offline, and resync features when internet is restored.

+
+ + + +
+ + +
+
+
+                            
+
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Features</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"">
+    <link rel="stylesheet" href="../samples/widgets/modal/css/modal-popup.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        #img-offline-indicator {
+            padding: 8px;
+            position: relative; float: right;
+        }
+
+        /* Override mod-popup default */
+        .mod-popup-stop-input {color: black;}
+        .span-pending {color: blue; padding-left: 1em;}
+        .voffset20px { margin-top: 20px; }
+        .floatRight { float: right}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set how we pull in custom AMD modules
+        var path = location.pathname.replace(/[^\/]+$/, '');
+        var dojoConfig =
+        {
+            debug: true,
+            packages:[
+                {
+                    name: "widgets",
+                    location: path + "../samples/widgets/"
+                }]
+        }
+
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container voffset20px">
+    <div class="row">
+        <div class="col-xs-8">
+            <button class="btn btn-success" id="btn-online-offline">Go Offline</button>
+            <span class="span-pending">Pending Edits <span id="span-pending-edits" class="badge">0</span></span>
+        </div>
+        <div class="col-xs-4">
+            <button id="btn-state" class="btn btn-success btn-large floatRight">
+                <span id="state-span" class="glyphicon glyphicon-link"> Up</span>
+            </button>
+        </div>
+    </div>
+    <div class="row voffset20px">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+<!-- Stub for modal popup -->
+<div id="modal-popup"></div>
+
+<script>
+
+require([
+        "esri/map","esri/tasks/query",
+        "dojo/on","dojo/parser", "esri/renderers/SimpleRenderer",
+        "esri/symbols/SimpleMarkerSymbol","esri/Color",
+        "widgets/modal/popup","esri/layers/FeatureLayer",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-edit-src.js",
+        "dojo/domReady!"],
+        function(Map,Query,on,parser,SimpleRenderer,SimpleMarkerSymbol,
+             Color,ModalPopup,FeatureLayer,BootstrapMap) {
+
+            var map, popup, editsStore;
+            var defaultSymbol;
+            var offlineFeaturesManager;
+            var btnOnlineOffline, btnState, pendingEdits;
+            var imgOfflineIndicator;
+            var closeBtn,saveBtn,deleteBtn,stopMainID,stopID,stopRoutes,stopNames;
+
+            initVars();
+            initMap();
+
+            function initMap(){
+
+                map = BootstrapMap.create("mapDiv",{
+                    basemap: "topo",
+                    center: [-104.99,39.75], // longitude, latitude
+                    zoom: 15
+                });
+
+
+                busStopFeatureLayer = new FeatureLayer("http://services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0", {
+                    mode: FeatureLayer.MODE_SNAPSHOT,
+                    outFields: ["OBJECTID","BSID","ROUTES","STOPNAME"]
+                });
+
+                //Set the graphics to red boxes to make it easy to click on them
+                //on a mobile device.
+                busStopFeatureLayer.setRenderer(new SimpleRenderer(defaultSymbol));
+                busStopFeatureLayer.on("update-end",function(evt){
+
+                    // Now we can enable the button click listener
+                    on(btnOnlineOffline,"click",goOnlineOffline);
+
+                    initOfflineFeaturesMgr();
+                    setFeatureLayerClickHandler();
+                    setModalPopupClickListeners();
+                });
+
+                map.addLayer(busStopFeatureLayer);
+            }
+
+
+            function initVars(){
+
+                editsStore = new O.esri.Edit.EditStore();
+                popup = new ModalPopup({animation: true, animationDuration: 1},"modal-popup");
+                popup.startup();
+
+                parser.parse();
+
+                // Check if browser state is online or offline
+                Offline.check();
+                Offline.on('up down', updateState );
+
+
+                btnOnlineOffline = document.getElementById("btn-online-offline");
+                imgOfflineIndicator = document.getElementById("state-span");
+                btnState = document.getElementById("btn-state");
+                pendingEdits = document.getElementById("span-pending-edits");
+
+                // 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);
+                }
+
+                // Variables for modal popup
+                closeBtn = document.getElementById("mod-popup-close-btn");
+                saveBtn = document.getElementById("mod-popup-save-btn");
+                deleteBtn = document.getElementById("mod-popup-delete-btn");
+                stopMainID = document.getElementById("stop-main-id");
+                stopID = document.getElementById("stop-id");
+                stopRoutes = document.getElementById("stop-routes");
+                stopNames = document.getElementById("stop-names");
+
+            }
+
+            /**
+             * ************************************
+             * OFFLINE FEATURE SERVICE HANDLER CODE
+             * ************************************
+             */
+
+            function initOfflineFeaturesMgr(){
+                offlineFeaturesManager = new O.esri.Edit.OfflineFeaturesManager();
+
+                // IMPORTANT!!!
+                // A proxy page may be required to upload attachments.
+                // If you are using a CORS enabled server you may be able to set the proxyPath to null.
+                // 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, updatePendingEditStatus);
+                offlineFeaturesManager.on(offlineFeaturesManager.events.EDITS_SENT, updatePendingEditStatus);
+                offlineFeaturesManager.on(offlineFeaturesManager.events.ALL_EDITS_SENT, updatePendingEditStatus);
+
+                offlineFeaturesManager.extend(busStopFeatureLayer);
+                console.log("offlineFeaturesManager initialized.");
+
+                Offline.check();
+                Offline.on('up down', updateState);
+            }
+
+            // Display modal popup when someone clicks on a feature
+            // and load the fields with data from the feature service.
+            function setFeatureLayerClickHandler(){
+                busStopFeatureLayer.on("click", function(evt) {
+                    currentFeature = evt.graphic
+
+                    var query = new Query();
+                    query.objectIds = [evt.graphic.attributes.OBJECTID];
+                    busStopFeatureLayer.selectFeatures(query,FeatureLayer.SELECTION_NEW,
+                            function(evt){
+                                console.log("Success: " + JSON.stringify(evt[0].attributes));
+                                showModalPopup(evt[0]);
+                                var atts = evt[0].attributes
+                                stopID.value = atts.OBJECTID;
+                                stopMainID.value = atts.BSID;
+                                stopNames.value = atts.STOPNAME;
+                                stopRoutes.value = atts.ROUTES;
+                            },function(err){
+                                console.log("ERROR " + JSON.stringify(err));
+                            });
+                }.bind(this));
+            }
+
+            function updatePendingEditStatus(){
+                if( editsStore.hasPendingEdits())
+                {
+                    var edits = editsStore.retrieveEditsQueue();
+                    pendingEdits.innerHTML = edits.length;
+                }
+                else
+                {
+                    pendingEdits.innerHTML = 0;
+                }
+            }
+
+            /**
+             * ************************************
+             * MODAL POPUP HANDLER CODE
+             * ************************************
+             */
+
+            function setModalPopupClickListeners(){
+                closeBtn.onclick = function(evt){
+                    hideModalPopup();
+                }
+
+                saveBtn.onclick = function(evt){
+
+                    popup.graphic.attributes.ROUTES = stopRoutes.value;
+                    popup.graphic.attributes.STOPNAME = stopNames.value;
+
+                    busStopFeatureLayer.applyEdits(null,[popup.graphic],null,function(result){
+                                console.log("Successfully saved changes to: " +
+                                    popup.graphic.attributes.STOPNAME);
+                                hideModalPopup();
+                            },
+                            function(err){
+                                alert("There was a problem while trying to save: " +
+                                    popup.graphic.attributes.STOPNAME);
+                            })
+                }
+
+                deleteBtn.onclick = function(evt){
+                    busStopFeatureLayer.applyEdits(null,null,[popup.graphic],function(result){
+                                console.log("Successfully deleted: " + popup.graphic.attributes.STOPNAME);
+                                hideModalPopup();
+                            },
+                            function(err){
+                                alert("There was a problem while trying to delete: " +
+                                    popup.graphic.attributes.STOPNAME);
+                            })
+                }
+
+            }
+
+            function showModalPopup(graphic){
+                popup.graphic = graphic; // assign graphic to modPopup as a property.
+                popup.show();
+            }
+
+            function hideModalPopup(){
+                popup.hide();
+            }
+
+            /**
+             * ************************************
+             * GO OFFLINE/ONLINE HANDLER CODE
+             * ************************************
+             */
+
+            // Force feature service offline
+            function goOnlineOffline(){
+
+                if(btnOnlineOffline.innerHTML == "Go Offline"){
+                    toggleStateUp(false);
+                    console.log("Map is offline");
+                }
+                else{
+                    toggleStateUp(true);
+                    console.log("Map is online");
+                }
+            }
+
+            // Set the UX to online or offline state
+            function toggleStateUp(state){
+                if(state){
+                    btnOnlineOffline.innerHTML = "Go Offline";
+                    offlineFeaturesManager.goOnline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-link";
+                    imgOfflineIndicator.innerHTML = " Up";
+                    btnState.className = "btn btn-success btn-large floatRight";
+                }
+                else{
+                    btnOnlineOffline.innerHTML = "Go Online";
+                    offlineFeaturesManager.goOffline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-thumbs-down";
+                    imgOfflineIndicator.innerHTML = " Down";
+                    btnState.className = "btn btn-danger btn-large floatRight";
+                }
+            }
+
+            // Automatically set the feature service online or offline.
+            function updateState(){
+                if(Offline.state === 'up'){
+                    toggleStateUp(true);
+                }
+                else{
+                    toggleStateUp(false);
+                }
+            }
+        }
+);
+
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                            
+                        
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+ +
+
+
+ + Pending Edits 0 +
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/getstarted-tiles.html b/demo/getstarted-tiles.html new file mode 100644 index 00000000..5ba871b6 --- /dev/null +++ b/demo/getstarted-tiles.html @@ -0,0 +1,785 @@ + + + + + + + + + Offline-editor-js + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Getting Started with Tiles

+

Basic steps for working with tiled base map services for offline.

+ +
+
+ +
+ +
+
+ + + +
+
+

Step 1: Fill in the basics

+

Add the basic library references. Then test to make sure map loads.

+
+
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Tiles</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        body {
+            background-color: #ffffff;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+
+        .floatRight {float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+<div class="row">
+    <div class="col-xs-12">
+        <div id="mapDiv"></div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require(["esri/map","dojo/on","//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js","../dist/offline-tiles-advanced-min.js", "dojo/domReady!"],
+        function(Map,on,Bootstrapmap) {
+
+        // Initialize our map to be responsive
+        var map = Bootstrapmap.create("mapDiv",{
+            basemap: "topo",
+            center: [-122.45, 37.75], // longitude, latitude
+            zoom: 15
+        });
+
+    });
+</script>
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+
+

Step 2: Configure tiled basemap to work offline

+

This initializes the offline-editor-js library. Test to make sure map loads.

+
+ +
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Tiles</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        body {
+            background-color: #ffffff;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+
+       .floatRight {float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+<div class="row">
+    <div class="col-xs-12">
+        <div id="mapDiv"></div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require(["esri/map","dojo/on","//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js","../dist/offline-tiles-advanced-min.js", "dojo/domReady!"],
+        function(Map,on,Bootstrapmap) {
+
+        // Check if browser state is online or offline
+        Offline.check();
+        Offline.on('up down', updateState );
+
+        // Initialize our map to be responsive
+        var map = Bootstrapmap.create("mapDiv",{
+            //basemap: "topo", // comment out this basemap!
+            center: [-122.45, 37.75], // longitude, latitude
+            zoom: 15
+        });
+
+        // Now we initialize a topo tiled basemap service to be offline-enabled.
+        var tileLayer = O.esri.Tiles.OfflineTileEnablerLayer(
+                "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
+                function(evt){
+                    console.log("Offline tile lib enabled. App is: " + Offline.state);
+                },
+                true);
+
+        // Add our offline tile layer to the map instead of using the default basemap!
+        map.addLayer(tileLayer);
+
+        // Set the tileLayer online or offline.
+        // When set to offline, the map will look for tiles in the local tiles database
+        function updateState(){
+            if(Offline.state === 'up'){
+                if(typeof tileLayer != "undefined") tileLayer.goOnline();
+            }
+            else{
+                if(typeof tileLayer != "undefined") tileLayer.goOffline();
+            }
+        }
+
+    });
+</script>
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+ +
+ +
+

Step 3: Configure tiles download.

+

Enable the ability to download tiles as well the ability to toggle online and offline.

+
+ + + +
+ + +
+
+
+                            
+
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline Tiles</title>
+
+    <!-- Bootstrap core CSS -->
+    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
+
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 500px;
+            max-height: 1000px;
+        }
+
+        body {
+            background-color: #ffffff;
+            overflow: hidden;
+            font-family: "Trebuchet MS";
+        }
+
+        .floatRight { float: right;}
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to offline.js which detects online/offline conditions -->
+    <script src="../vendor/offline/offline.min.js"></script>
+    <script>
+        // Set the online/offline detection options.
+        // More info at: http://github.hubspot.com/offline/docs/welcome/
+        Offline.options = {
+            checks: {
+                image: {
+                    url: function() {
+                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
+                                (Math.floor(Math.random() * 1000000000));
+                    }
+                },
+                active: 'image'
+            }
+        }
+    </script>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<!-- Our buttons and online/offline indicator -->
+<div class="container">
+    <div class="row">
+        <div class="col-xs-10">
+            <div class="form form-group btn-group" data-toggle="buttons">
+                <button class="btn btn-success" id="btn-get-tiles">1. Download Tiles</button>
+                <button class="btn btn-success" disabled id="btn-online-offline">2. Go Offline</button>
+                <button class="btn btn-success" disabled id="btn-pan-left">3. Pan left</button>
+            </div>
+        </div>
+        <div class="col-xs-2">
+            <!-- this indicates whether app is offline (down) or online (up) -->
+            <button id="btn-state" class="btn btn-success btn-large floatRight">
+                <span id="state-span" class="glyphicon glyphicon-link"> Up</span>
+            </button>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tiles library within the require statement!
+    require(["esri/map","dojo/on","//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tiles-advanced-min.js", "dojo/domReady!"],
+        function(Map,on,Bootstrapmap){
+
+            var map,basemapLayer;
+
+            // Check if browser state is online or offline
+            Offline.check();
+            Offline.on('up down', updateState );
+
+            // For cancelling the download of tiles
+            var _wantToCancel = false;
+            var _downloadState = "downloaded";
+
+            // Set up min and max boundaries for retrieving tiles
+            var minZoomAdjust = -1, maxZoomAdjust = 1;
+
+            // Set up button click listeners.
+            var btnGetTiles = document.getElementById("btn-get-tiles");
+            var btnOnlineOffline = document.getElementById("btn-online-offline");
+            var btnPanLeft = document.getElementById("btn-pan-left");
+
+            on(btnGetTiles,"click",downloadTiles);
+            on(btnOnlineOffline,"click",goOnlineOffline);
+            on(btnPanLeft,"click",panLeft);
+
+            var imgOfflineIndicator = document.getElementById("state-span");
+            var btnState = document.getElementById("btn-state");
+
+            showMap();
+
+            function showMap(){
+
+                // Initialize our map to be responsive
+                map = Bootstrapmap.create("mapDiv",{
+                    //basemap: "topo", // comment out this basemap!
+                    center: [-122.45, 37.75], // longitude, latitude
+                    zoom: 15
+                });
+
+                // Now we initialize the basemap to be offline-enabled. This is out new basemap.
+                basemapLayer = O.esri.Tiles.OfflineTileEnablerLayer(
+                        "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
+                        function(evt){
+                            console.log("Offline tile lib enabled. App is: " + Offline.state);
+                        },
+                        true);
+
+                // Add our offline tile layer to the map instead of using the default basemap!
+                map.addLayer(basemapLayer);
+            }
+
+            function downloadTiles(){
+
+                if(_downloadState == "downloading"){
+                    _wantToCancel = true;
+                }
+                else{
+                    _wantToCancel = false;
+
+                    // First delete any existing tiles from database
+                    basemapLayer.deleteAllTiles(function(success,err){
+                        var zoom = basemapLayer.getMinMaxLOD(minZoomAdjust,maxZoomAdjust);
+
+                        // Now download tiles
+                        basemapLayer.prepareForOffline(zoom.min, zoom.max, map.extent, function(progress){
+                            console.log("downloading tiles...");
+
+                            if(progress.hasOwnProperty("countNow")){
+                                var percent = Math.floor(progress.countNow / progress.countMax * 100);
+                                btnGetTiles.innerHTML = 'Saving to phone ' + percent + "% - Tap to Cancel";
+                            }
+
+                            if( progress.finishedDownloading )
+                            {
+                                btnGetTiles.innerHTML = "Saving to phone 100% - Tap to Cancel";
+
+                                if( progress.cancelRequested )
+                                {
+                                    alert("Tile download was cancelled");
+                                    _downloadState = "cancelled";
+                                }
+                                else
+                                {
+                                    alert("Tile download complete");
+                                    _downloadState = "downloaded";
+                                    btnOnlineOffline.disabled = false;
+                                }
+
+                                btnGetTiles.innerHTML = '1. Download Tiles';
+                            }
+                            return _wantToCancel; //determines if a cancel request has been issued
+                        });
+
+                        _downloadState = "downloading";
+
+                    });
+                }
+            }
+
+            // Force the tileLayer between online and offline
+            function goOnlineOffline(){
+
+                btnPanLeft.disabled = false;
+
+                if(btnOnlineOffline.innerHTML == "2. Go Offline"){
+                    toggleStateUp(false);
+                    console.log("Map is offline");
+                }
+                else{
+                    toggleStateUp(true);
+                    console.log("Map is online");
+                }
+            }
+
+            function toggleStateUp(state){
+                if(state){
+                    btnOnlineOffline.innerHTML = "2. Go Offline";
+                    basemapLayer.goOnline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-link";
+                    imgOfflineIndicator.innerHTML = " Up";
+                    btnState.className = "btn btn-success btn-large floatRight";
+                }
+                else{
+                    btnOnlineOffline.innerHTML = "2. Go Online";
+                    basemapLayer.goOffline();
+                    imgOfflineIndicator.className = "glyphicon glyphicon-thumbs-down";
+                    imgOfflineIndicator.innerHTML = " Down";
+                    btnState.className = "btn btn-danger btn-large floatRight";
+                }
+            }
+
+            // Set the ArcGIS.com map online or offline.
+            // When set offline it will look for tiles in the tiles database
+            function updateState(){
+                if(Offline.state === 'up'){
+                    if(typeof basemapLayer != "undefined") basemapLayer.goOnline();
+                    toggleStateUp(true);
+                }
+                else{
+                    if(typeof basemapLayer != "undefined") basemapLayer.goOffline();
+                    toggleStateUp(false);
+                }
+            }
+
+            // Pan left when "offline" to view only tiles that have been stored locally
+            function panLeft(){
+                map.panLeft();
+            }
+
+    });
+</script>
+
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                            
+                        
+
NOTE: Replace paths with your references. Or build your app in the /demo directory
+
+ +
+
+
+
+ + + +
+
+
+ + +
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/getstarted-tpk.html b/demo/getstarted-tpk.html new file mode 100644 index 00000000..c86507fe --- /dev/null +++ b/demo/getstarted-tpk.html @@ -0,0 +1,574 @@ + + + + + + + + + Offline-editor-js + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Getting Started with TPKs

+

Basic steps for working with TPK packages for offline.

+ +
+
+ +
+ +
+
+ + + +
+
+

Step 1: Fill in the basics

+

Add the basic library references and CSS. Then test to make sure application loads. + There won't be a map to display just yet, you'll only see the header bar.

+
+
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline TPK</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css"">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 300px;
+            max-height: 1000px;
+        }
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container">
+    <div class="row">
+        <div class="col-lg-12">
+            <div class="form form-group input-group">
+                <input id="url-input" type="text" class="form-control"
+                            value="../samples/tpks/Beirut.zip">
+            <span class="input-group-btn">
+                <button id="url-btn" class="btn btn-success" type="button">Go!</button>
+            </span>
+            </div>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tpk library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tpk-src.js", "dojo/domReady!"],
+            function(Map,on,BootstrapMap) {
+
+                var map, tpkLayer;
+
+                var url = document.getElementById("url-input");
+                var urlInputBtn = document.getElementById("url-btn");
+
+            }
+    );
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references.
+
+
+

Step 2: Retrieve TPK.

+

Download and unzip the TPK. You should get an alert when TPK is fully downloaded.

+

NOTE: If you have a TPK file you will have to change its type to .zip for the browser to recognize it.

+
+ +
+                        
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline TPK</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 300px;
+            max-height: 1000px;
+        }
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container">
+    <div class="row">
+        <div class="col-lg-12">
+            <div class="form form-group input-group">
+                <input id="url-input" type="text" class="form-control"
+                       value="../samples/tpks/Beirut.zip">
+            <span class="input-group-btn">
+                <button id="url-btn" class="btn btn-success" type="button">Go!</button>
+            </span>
+            </div>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tpk library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tpk-src.js", "dojo/domReady!"],
+            function(Map,on,BootstrapMap) {
+
+                var map, tpkLayer;
+
+                var url = document.getElementById("url-input");
+                var urlInputBtn = document.getElementById("url-btn");
+                urlInputBtn.onclick = function(){
+                    getTPK();
+                };
+
+                // Retrieve the TPK file via an HTTP request
+                function getTPK(){
+                    urlInputBtn.innerHTML = "Get file via url";
+
+                    var xhrRequest = new XMLHttpRequest();
+                    xhrRequest.open("GET", url.value, true);
+                    xhrRequest.responseType = "blob";
+                    xhrRequest.onprogress = function(evt){
+                        var percent = (parseFloat(evt.loaded / evt.totalSize) * 100).toFixed(0);
+                        urlInputBtn.innerHTML = "Get file via url " + percent + "%";
+                        console.log("Begin downloading remote tpk file...")
+                    }
+
+                    xhrRequest.error = function(err){console.log("ERROR")}
+
+                    xhrRequest.onload = function(oEvent) {
+                        if(this.status == 200) {
+                            console.log("Remote tpk download finished.")
+                            zipParser(this.response);
+                        }
+                        else{
+                            alert("There was a problem loading the file. " + this.status + ": " + this.statusText )
+                        }
+                    };
+
+                    xhrRequest.send();
+                }
+
+                // Parse the zip file contents into a zip.Entries object
+                function zipParser(blob){
+
+                    O.esri.zip.createReader(new O.esri.zip.BlobReader(blob), function (zipReader) {
+                        zipReader.getEntries(function (entries) {
+                            if(entries) alert("TPK downloaded and unzipped!");
+                            zipReader.close(function(evt){
+                                console.log("Done reading zip file.")
+                            })
+                        }, function (err) {
+                            alert("There was a problem reading the file!: " + err);
+                        })
+                    })
+                }
+
+            }
+    );
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                        
+                    
+
NOTE: Replace paths with your references.
+ +
+ +
+

Step 3: Display TPK tiles.

+

In this step we hand the zip file entries over to TPKLayer to inflate the map.

+
+ + + +
+ + +
+
+
+                            
+
+<!DOCTYPE html>
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
+    <title>Offline TPK</title>
+    <link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" media="screen">
+    <link rel="stylesheet" href="http://js.arcgis.com/3.11/esri/css/esri.css">
+    <link rel="stylesheet" type="text/css" href="http://esri.github.io/bootstrap-map-js/src/css/bootstrapmap.css">
+    <style>
+        #mapDiv {
+            min-height: 300px;
+            max-height: 1000px;
+        }
+        .container { padding: 20px;}
+    </style>
+
+    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
+    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
+
+    <script src="http://js.arcgis.com/3.11/"></script>
+</head>
+
+<body>
+
+<div class="container">
+    <div class="row">
+        <div class="col-lg-12">
+            <div class="form form-group input-group">
+                <input id="url-input" type="text" class="form-control"
+                       value="../samples/tpks/Beirut.zip">
+            <span class="input-group-btn">
+                <button id="url-btn" class="btn btn-success" type="button">Go!</button>
+            </span>
+            </div>
+        </div>
+    </div>
+    <div class="row">
+        <div class="col-xs-12">
+            <div id="mapDiv"></div>
+        </div>
+    </div>
+</div>
+
+<script>
+
+    // Make sure to reference the tpk library within the require statement!
+    require([
+        "esri/map",
+        "dojo/on",
+        "//esri.github.com/bootstrap-map-js/src/js/bootstrapmap.js",
+        "../dist/offline-tpk-src.js", "dojo/domReady!"],
+            function(Map,on,BootstrapMap) {
+
+                var map, tpkLayer;
+
+                var url = document.getElementById("url-input");
+                var urlInputBtn = document.getElementById("url-btn");
+                urlInputBtn.onclick = function(){
+                    getTPK();
+                };
+
+                // Retrieve the TPK file via an HTTP request
+                function getTPK(){
+                    urlInputBtn.innerHTML = "Get file via url";
+
+                    var xhrRequest = new XMLHttpRequest();
+                    xhrRequest.open("GET", url.value, true);
+                    xhrRequest.responseType = "blob";
+                    xhrRequest.onprogress = function(evt){
+                        var percent = (parseFloat(evt.loaded / evt.totalSize) * 100).toFixed(0);
+                        urlInputBtn.innerHTML = "Get file via url " + percent + "%";
+                        console.log("Begin downloading remote tpk file...")
+                    }
+
+                    xhrRequest.error = function(err){console.log("ERROR")}
+
+                    xhrRequest.onload = function(oEvent) {
+                        if(this.status == 200) {
+                            console.log("Remote tpk download finished.")
+                            zipParser(this.response);
+                        }
+                        else{
+                            alert("There was a problem loading the file. " + this.status + ": " + this.statusText )
+                        }
+                    };
+
+                    xhrRequest.send();
+                }
+
+                // Parse the zip file contents into a zip.Entries object
+                function zipParser(blob){
+
+                    O.esri.zip.createReader(new O.esri.zip.BlobReader(blob), function (zipReader) {
+                        zipReader.getEntries(function (entries) {
+                            initMap(entries);
+                            //if(entries)alert("TPK downloaded and unzipped!");
+                            zipReader.close(function(evt){
+                                console.log("Done reading zip file.")
+                            })
+                        }, function (err) {
+                            alert("There was a problem reading the file!: " + err);
+                        })
+                    })
+                }
+
+                // Initialize the Map and the TPKLayer
+                function initMap(entries){
+
+                    map = BootstrapMap.create("mapDiv",{});
+
+                    tpkLayer = new O.esri.TPK.TPKLayer();
+                    tpkLayer.on("progress", function (evt) {
+                        console.log("TPK loading...");
+                    })
+                    tpkLayer.extend(entries);
+
+                    map.addLayer(tpkLayer);
+                }
+
+            }
+    );
+</script>
+<!-- Bootstrap core JavaScript
+================================================== -->
+<!-- Placed at the end of the document so the pages load faster -->
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
+</body>
+</html>
+
+                            
+                        
+
NOTE: Replace paths with your references. This sample may look different than our live sample.
+
+ +
+
+
+
+ + + + +
+
+
+
+
+
+
+
+ +
+ +
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/getstarted.html b/demo/getstarted.html index 43427959..90c57436 100644 --- a/demo/getstarted.html +++ b/demo/getstarted.html @@ -47,6 +47,8 @@ padding: 8px; position: relative; float: right; } + + .blue-link {color: blue !important;} @@ -56,662 +58,60 @@ Fork me on GitHub - +
-

Getting Started

-

Basic steps for working with web map tiles while offline.

+

Getting Started Samples

+

Basic responsive samples on how to work with the ArcGIS API for JavaScript while offline.

- -
-
- - - -
-
-

Step 1: Fork or clone offline-editor-js

-

Here are the important directories to know:

-
    -
  • \dist - concatenated library source and minified library files.
  • -
  • \samples - examples that demonstrate the library's functionality.
  • -
  • \vendor - contains IndexedDBShim and offline.js libraries
  • -
-
- -
-
-

Step 2: Fill in the basics

-

Add the basic library references. Then test to make sure map loads.

-
-
-                        
-<!DOCTYPE html>
-<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
-    <title>Simple Map</title>
-    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
-    <style>
-        html, body, #map {
-            height: 100%;
-            width: 100%;
-            margin: 0;
-            padding: 0;
-        }
-        body {
-            background-color: #000000;
-            overflow: hidden;
-            font-family: "Trebuchet MS";
-        }
-    </style>
-
-    <!-- Include a reference to offline.js which detects online/offline conditions -->
-    <script src="../vendor/offline/offline.min.js"></script>
-    <script>
-        // Set the online/offline detection options.
-        // More info at: http://github.hubspot.com/offline/docs/welcome/
-        Offline.options = {
-            checks: {
-                image: {
-                    url: function() {
-                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
-                            (Math.floor(Math.random() * 1000000000));
-                    }
-                },
-                active: 'image'
-            }
-        }
-    </script>
-
-    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
-    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
-
-    <script src="http://js.arcgis.com/3.10/"></script>
-</head>
-
-<body>
-    <div id="map"></div>
-
-    <script>
-        var map;
-
-        // Make sure to reference the tiles library within the require statement!
-        require(["esri/map","../dist/offline-tiles-advanced-min.js", "dojo/domReady!"], function(Map) {
-            map = new Map("map", {
-                basemap: "topo",
-                center: [-122.45, 37.75], // longitude, latitude
-                zoom: 13
-            });
-        });
-    </script>
-</body>
-</html>
-
-                        
-                    
-
NOTE: Replace paths with your references.
-
-
-

Step 3: Configure tiled basemap to work offline

-

This initializes the offline-editor-js library. Test to make sure map loads.

-
- -
-                        
-<!DOCTYPE html>
-<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
-    <title>Simple Map</title>
-    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
-    <style>
-        html, body, #map {
-            height: 100%;
-            width: 100%;
-            margin: 0;
-            padding: 0;
-        }
-        body {
-            background-color: #000000;
-            overflow: hidden;
-            font-family: "Trebuchet MS";
-        }
-    </style>
-
-    <!-- Include a reference to offline.js which detects online/offline conditions -->
-    <script src="../vendor/offline/offline.min.js"></script>
-    <script>
-        // Set the online/offline detection options.
-        // More info at: http://github.hubspot.com/offline/docs/welcome/
-        Offline.options = {
-            checks: {
-                image: {
-                    url: function() {
-                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
-                            (Math.floor(Math.random() * 1000000000));
-                    }
-                },
-                active: 'image'
-            }
-        }
-    </script>
-
-    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
-    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
-
-    <script src="http://js.arcgis.com/3.10/"></script>
-</head>
-
-<body>
-    <div id="map"></div>
-
-    <script>
-        var map;
-
-        // Make sure to reference the offline tiles library within the require statement!
-        require(["esri/map","../dist/offline-tiles-advanced-min.js", "dojo/domReady!"], function(Map) {
-
-            // Check if browser state is online or offline
-            Offline.check();
-            Offline.on('up down', updateState );
-
-            // Initialize Esri.Map
-            map = new Map("map", {
-                //basemap: "topo", // comment out this basemap!
-                center: [-122.45, 37.75], // longitude, latitude
-                zoom: 13
-            });
-
-            // Now we initialize a topo tiled basemap service to be offline-enabled.
-            tileLayer = O.esri.Tiles.OfflineTileEnablerLayer(
-                            "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
-                            function(evt){
-                                console.log("Offline tile lib enabled. App is: " + Offline.state);
-                            },
-                            true);
-
-            // Add our offline tile layer to the map instead of using the default basemap!
-            map.addLayer(tileLayer);
-
-            // Set the tileLayer online or offline.
-            // When set to offline, the map will look for tiles in the tiles database
-            function updateState(){
-                if(Offline.state === 'up'){
-                    if(typeof tileLayer != "undefined") tileLayer.goOnline();
-                }
-                else{
-                    if(typeof tileLayer != "undefined") tileLayer.goOffline();
-                }
-            }
-
-        });
-    </script>
-</body>
-</html>
-
-                        
-                    
-
NOTE: Replace paths with your references.
- -
- -
-

Step 4: Configure tiles download.

-

Enable the ability to download tiles as well the ability to toggle online and offline.

-
- - - -
- - -
-
-
-                            
-
-<!DOCTYPE html>
-<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
-    <title>Simple Map</title>
-    <link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
-    <style>
-        html, body, #map {
-            height: 100%;
-            width: 100%;
-            margin: 0;
-            padding: 0;
-        }
-        body {
-            background-color: #000000;
-            overflow: hidden;
-            font-family: "Trebuchet MS";
-        }
-    </style>
-
-    <!-- Include a reference to offline.js which detects online/offline conditions -->
-    <script src="../vendor/offline/offline.min.js"></script>
-    <script>
-        // Set the online/offline detection options.
-        // More info at: http://github.hubspot.com/offline/docs/welcome/
-        Offline.options = {
-            checks: {
-                image: {
-                    url: function() {
-                        return 'http://esri.github.io/offline-editor-js/tiny-image.png?_=' +
-                            (Math.floor(Math.random() * 1000000000));
-                    }
-                },
-                active: 'image'
-            }
-        }
-    </script>
-
-    <!-- Include a reference to IndexedDBShim for library to work on Safari 7.x -->
-    <script src="../vendor/IndexedDBShim/dist/IndexedDBShim.js"></script>
-
-    <script src="http://js.arcgis.com/3.10/"></script>
-</head>
-
-<body>
-
-    <!-- Create two buttons -->
-    <button class="basic-btn" id="btn-get-tiles">1. Download Tiles</button>
-    <button class="basic-btn" id="btn-online-offline">2. Go Offline</button>
-    <button class="basic-btn" id="btn-pan-left">3. Pan left</button>
-
-    <div id="map"></div>
-
-    <script>
-        var map;
-
-        // Make sure to reference the offline tiles library within the require statement!
-        require(["esri/map","dojo/on","../dist/offline-tiles-advanced-min.js", "dojo/domReady!"],
-        function(Map,on){
-
-            // Check if browser state is online or offline
-            Offline.check();
-            Offline.on('up down', updateState );
-
-            // For cancelling the download of tiles
-            var _wantToCancel;
-
-            // Set up min and max boundaries for retrieving tiles
-            var minZoomAdjust = -1, maxZoomAdjust = 1, mMinZoom, mMaxZoom;
-
-            // Set up button click listeners.
-            var btnGetTiles = document.getElementById("btn-get-tiles");
-            var btnOnlineOffline = document.getElementById("btn-online-offline");
-            var btnPanLeft = document.getElementById("btn-pan-left");
-
-            on(btnGetTiles,"click",downloadTiles);
-            on(btnOnlineOffline,"click",goOnlineOffline);
-            on(btnPanLeft,"click",panLeft);
-
-            // Initialize Esri.Map
-            map = new Map("map", {
-                //basemap: "topo", // comment out this basemap!
-                center: [-122.45, 37.75], // longitude, latitude
-                zoom: 13
-            });
-
-            // Now we initialize a topo tiled basemap service to be offline-enabled.
-            tileLayer = O.esri.Tiles.OfflineTileEnablerLayer(
-                            "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer",
-                            function(evt){
-                                console.log("Offline tile lib enabled. App is: " + Offline.state);
-                            },
-                            true);
-
-            // Set the min and max zoom levels for when retrieving tiles
-            // This helps manage the amount of database space used.
-            map.on("load",function(evt){
-                tileLayer.getMaxZoom(function(result){
-                    mMaxZoom = result;
-                });
-                tileLayer.getMinZoom(function(result){
-                    mMinZoom = result;
-                });
-            })
-
-            // Add our offline tile layer to the map instead of using the default basemap!
-            map.addLayer(tileLayer);
 
-            function downloadTiles(){
-
-                // First we need to empty the database.
-                tileLayer.deleteAllTiles(function(success,err){
-
-                    var zoom = getMinMaxZoom();
-                    var extent = tileLayer.getExtentBuffer(0,map.extent);
-
-                    // Begin downloading tiles
-                    tileLayer.prepareForOffline(zoom.min, zoom.max, extent, function(progress){
-                        console.log("downloading tiles...");
-                        if(progress.hasOwnProperty("countNow")){
-                            var percent = Math.floor(progress.countNow / progress.countMax * 100);
-                            btnGetTiles.innerHTML = 'Saving to phone ' + percent + "% - Tap to Cancel";
-                        }
-
-                        if( progress.finishedDownloading )
-                        {
-                            btnGetTiles.innerHTML = "Saving to phone 100% - Tap to Cancel";
-
-                            if( progress.cancelRequested )
-                            {
-                                alert("Tile download was cancelled");
-                            }
-                            else
-                            {
-                                alert("Tile download complete");
-                            }
-
-                            btnGetTiles.innerHTML = '1. Download Tiles';
-                        }
-                        return _wantToCancel; //determines if a cancel request has been issued
-                    });
-                });
-            }
-
-            // Force the tileLayer between online and offline
-            function goOnlineOffline(){
-                if(btnOnlineOffline.innerHTML == "2. Go Offline"){
-                    btnOnlineOffline.innerHTML = "2. Go Online";
-                    tileLayer.goOffline();
-                    document.body.style.backgroundColor = "red";
-                    console.log("tileLayer is offline");
-                }
-                else{
-                    btnOnlineOffline.innerHTML = "2. Go Offline";
-                    tileLayer.goOnline();
-                    document.body.style.backgroundColor = "black";
-                    console.log("tileLayer is online");
-                }
-            }
-
-
-            // Set the tileLayer online or offline.
-            // When set to offline, the map will look for tiles in the tiles database
-            function updateState(){
-                if(Offline.state === 'up'){
-                    if(typeof tileLayer != "undefined") tileLayer.goOnline();
-                }
-                else{
-                    if(typeof tileLayer != "undefined") tileLayer.goOffline();
-                }
-            }
-
-            // Utility function to validate min and max zoom settings of the map
-            function getMinMaxZoom(){
-
-                var zoom = {};
-                var min = tileLayer.getLevel() + minZoomAdjust;
-                var max = tileLayer.getLevel() + maxZoomAdjust;
-                zoom.max = Math.min(mMaxZoom, max);  //prevent errors by setting the tile layer floor
-                zoom.min = Math.max(mMinZoom, min);   //prevent errors by setting the tile layer ceiling
-
-                return zoom;
-            }
-
-            function panLeft(){
-                map.panLeft();
-            }
-
-        });
-    </script>
-</body>
-</html>
-
-                            
-                        
-
NOTE: Replace paths with your references.
-
- -
-
-
-
- - - -
- -
-
-
-
-
-
-
+ -
-
-
-
+
+
+
+

Fork or clone offline-editor-js

+
+
+

Here are the important directories to know:

+
    +
  • \dist - minified library files and concatenated source (for debugging).
  • +
  • \samples - more examples that demonstrate the library's functionality.
  • +
  • \vendor - contains IndexedDBShim and offline.js helper libraries
  • +
+
+ +
+
+
-
-
-
-
-
+
- - + - - - - - - diff --git a/demo/header.html b/demo/header.html new file mode 100644 index 00000000..6c3b445a --- /dev/null +++ b/demo/header.html @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/demo/index.html b/demo/index.html index aa0358c8..a53e392b 100644 --- a/demo/index.html +++ b/demo/index.html @@ -19,6 +19,9 @@ + @@ -27,18 +30,7 @@ Fork me on GitHub - +
@@ -67,27 +59,34 @@

TPK


+
+
+

Get Started

+

Go here to try out basic step-by-step samples.

+
+
+

Examples

-

Use the following applications as building blocks.

+

Check out the following full-featured applications.

-
+

Tiles Only

Gives you an overview of the functionality related to storing and managing multiple layers of tiles.

-
+

Feature Editing

This app shows how add, update and delete geographic features while offline and auto-resync when internet is reestablished.

-
+
@@ -95,22 +94,22 @@

Attachments

Demonstrates working with geographic feature attachments such as images and associating them with a feature while offline.

-
-
+
+

TPK Only

Shows how to integrate .tpk files into your mapping app. Tile packages are a set of tile images from a map compressed into a single binary file.

-
+

AppCache Features and Tiles

This mobile feature editing demo is configured to maintain your edits and tiles after offline browser reloads and restarts.

-
+
@@ -173,12 +172,17 @@

Supported Browsers

+ + - \ No newline at end of file diff --git a/demo/widgets/modal/css/modal-popup.css b/demo/widgets/modal/css/modal-popup.css new file mode 100644 index 00000000..3703a826 --- /dev/null +++ b/demo/widgets/modal/css/modal-popup.css @@ -0,0 +1,162 @@ +.mod-popup-div { + opacity: 0; + height: 0; + width: 0; + z-index: 98; + font-size: x-large; + position: absolute; + top: 0px; + left: -1000px; +} +.mod-popup-body { + position: relative; + top: 10%; + left: 10%; + z-index: 100; + height: 80%; + width: 80%; + border-radius: 10px; + background-color: black; + display: table; + opacity: 0.7; +} +.mod-popup-modal-background { + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + opacity: 0.5; + background-color: black; + z-index: 99; + display: table; +} +.mod-popup-input { + border-bottom: solid #ffffff 1px; + width: 80%; + display: table-cell; + vertical-align: middle; + padding: 12px; +} +.mod-popup-label { + padding: 12px; + width: 20%; + display: table-cell; + vertical-align: middle; + background-color: dimgrey; +} +.mod-popup-label-top-left { + padding: 12px; + width: 20%; + display: table-cell; + vertical-align: middle; + background-color: dimgray; + border-top-left-radius: 10px; +} +.mod-popup-table-row { + color: white; + border-radius: 10px; + display: table-row; +} +.mod-popup-stop-input { + border-radius: 5px; + font-size: x-large; + width: 90%; + height: 75%; + padding: 5px; +} +.mod-popup-stop-input-disabled { + color: white; + border-radius: 5px; + font-size: x-large; + background-color: dimgray; + opacity: 1.0; /* For safari display bug */ + padding: 5px; + width: 90%; + height: 75%; +} +.mod-popup-button { + position: relative; + float: left; + color: #ffffff; + font-size: x-large; + border-radius: 10px; + width: 45%; + padding: 8px; + background-color: #000000; + border: solid #ffffff 2px; +} +.mod-popup-button:active { + position: relative; + float: left; + color: #000000; + font-size: x-large; + border-radius: 10px; + width: 45%; + padding: 8px; + background-color: lightyellow; + border: solid #ffffff 2px; +} +.mod-popup-button-cancel { + position: relative; + float: left; + color: lightgray; + font-size: x-large; + border-radius: 10px; + width: 100%; + padding: 8px; + background-color: #000000; + border: solid lightgray 1px; +} +.mod-popup-button-cancel:active { + position: relative; + float: left; + color: #000000; + font-size: x-large; + border-radius: 10px; + width: 100%; + padding: 8px; + background-color: lightyellow; + border: solid lightgray 1px; +} +.mod-popup-button-div { + padding: 12px; + display: table-cell; + vertical-align: middle; + background-color: #000000; +} +.mod-popup-button-div-bottom-left { + padding: 12px; + display: table-cell; + vertical-align: middle; + background-color: #000000; + border-bottom-left-radius: 8px; +} +@media (max-width: 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; + } +} +@media (max-width: 450px) { + .mod-popup-button { + font-size: x-small; + } + .mod-popup-button:active{ + font-size: x-small; + } + .mod-popup-button-cancel { + font-size: x-small; + } + .mod-popup-button-cancel:active { + font-size: x-small; + } +} \ No newline at end of file diff --git a/demo/widgets/modal/popup.js b/demo/widgets/modal/popup.js new file mode 100644 index 00000000..00dfd3d4 --- /dev/null +++ b/demo/widgets/modal/popup.js @@ -0,0 +1,71 @@ +/** + * Modal Popup Widget + * This widget provides a basic framework for building modal popups + * for mobile GIS web applications. + * @author @agup + */ +define([ + "dojo/_base/declare", "dojo/parser", "dojo/ready", + "dijit/_WidgetBase", "dijit/_TemplatedMixin","dojo/query", + "dojo/text!./template/popup.html","dojo/NodeList-manipulate" +], function(declare, parser, ready, _WidgetBase, _TemplatedMixin,query,template){ + + return declare("ModalPopup", [_WidgetBase, _TemplatedMixin], { + + options: { + animation: false, + animationDuration: 1 + }, + + templateString: template, + + constructor: function (options, srcRefNode) { + // mix in settings and defaults + declare.safeMixin(this.options, options); + + // widget node + this.domNode = srcRefNode; + + // Set properties + this.set("animation", this.options.animation); + this.set("animationDuration", this.options.animationDuration); + }, + + show: function () { + + if(this.animation){ + // You can design any animation you want! + this.domNode.style.opacity = 1; + this.domNode.style.left = 0; + this.domNode.style.top = 0; + this.domNode.style.width = "100%"; + this.domNode.style.height = "100%"; + this.domNode.style.transition = "all " + this.animationDuration + "s linear 0s"; + } + else{ + this.domNode.style.position = "static"; + } + }, + + hide: function () { + + if(this.animation){ + // You can design any animation you want! + this.domNode.style.height = 0; + this.domNode.style.width = 0; + this.domNode.style.opacity = 0; + this.domNode.style.top = "0px"; + this.domNode.style.left = -1000 + "px"; + this.domNode.style.transition = "all " + this.animationDuration + "s ease-in-out 0s"; + } + else{ + this.domNode.style.position = "absolute"; + } + }, + + // connections/subscriptions will be cleaned up during the destroy() lifecycle phase + destroy: function () { + this.inherited(arguments); + } + }); +}); diff --git a/demo/widgets/modal/template/popup.html b/demo/widgets/modal/template/popup.html new file mode 100644 index 00000000..eeed14c9 --- /dev/null +++ b/demo/widgets/modal/template/popup.html @@ -0,0 +1,46 @@ +
+ +
+
+
ID
+
+ +
+
+
+
Bustop ID
+
+ +
+
+
+
Routes
+
+ +
+
+
+
Stopnames
+
+ +
+
+
+
+ +
+
+ + +
+
+
+ +
\ No newline at end of file diff --git a/dist/offline-edit-src.js b/dist/offline-edit-src.js index 462fb430..b36598b8 100644 --- a/dist/offline-edit-src.js +++ b/dist/offline-edit-src.js @@ -1,4 +1,4 @@ -/*! offline-editor - v2.2 - 2014-09-30 +/*! offline-editor-js - v2.3 - 2014-10-13 * Copyright (c) 2014 Environmental Systems Research Institute, Inc. * Apache License*/ diff --git a/dist/offline-tiles-advanced-min.js b/dist/offline-tiles-advanced-min.js index 40d034f5..c404e61c 100644 --- a/dist/offline-tiles-advanced-min.js +++ b/dist/offline-tiles-advanced-min.js @@ -1 +1 @@ -define(["dojo/query","dojo/request","dojo/_base/declare","esri/layers/LOD","esri/geometry/Point","esri/geometry/Extent","esri/layers/TileInfo","esri/SpatialReference","esri/geometry/Polygon","esri/layers/TiledMapServiceLayer"],function(a,b,c,d,e,f,g,h,i,j){"use strict";return c("O.esri.Tiles.OfflineTileEnablerLayer",[j],{tileInfo:null,_imageType:"",_level:null,_minZoom:null,_maxZoom:null,_tilesCore:null,constructor:function(a,b,c){this._isLocalStorage()===!1&&(alert("OfflineTiles Library not supported on this browser."),b(!1)),this._tilesCore=new O.esri.Tiles.TilesCore,Array.prototype.sortNumber=function(){return this.sort(function(a,b){return a-b})},this._self=this,this._lastTileUrl="",this._imageType="",this._getTileUrl=this.getTileUrl;var d=!0;return("undefined"!=typeof c||null!=c)&&(d=c),this.offline={online:d,store:new O.esri.Tiles.TilesStore,proxyPath:null},this.offline.store.isSupported()?void this.offline.store.init(function(c){c&&this._getTileInfoPrivate(a,function(a){void 0==localStorage.__offlineTileInfo&&0!=a&&(localStorage.__offlineTileInfo=a),0==this.offline.online&&0==a&&void 0!=localStorage.__offlineTileInfo?a=localStorage.__offlineTileInfo:0==this.offline.online&&0==a&&void 0==localStorage.__offlineTileInfo&&alert("There was a problem retrieving tiled map info in OfflineTilesEnablerLayer."),this._tilesCore._parseGetTileInfo(a,function(a){this.layerInfos=a.resultObj.layers,this.minScale=a.resultObj.minScale,this.maxScale=a.resultObj.maxScale,this.tileInfo=a.tileInfo,this._imageType=this.tileInfo.format.toLowerCase(),this.fullExtent=a.fullExtent,this.spatialReference=this.tileInfo.spatialReference,this.initialExtent=a.initExtent,this.loaded=!0,this.onLoad(this),b(!0)}.bind(this._self))}.bind(this._self))}.bind(this._self)):b(!1,"indexedDB not supported")},getTileUrl:function(b,c,d){this._level=b;var e=this.url+"/tile/"+b+"/"+c+"/"+d;if(this.offline.online)return this._lastTileUrl=e,e;e=e.split("?")[0];var f="void:/"+b+"/"+c+"/"+d,g=null;return this._tilesCore._getTiles(g,this._imageType,e,f,this.offline.store,a),f},getBasemapLayer:function(a){var b=a.layerIds[0];return a.getLayer(b)},getLevelEstimation:function(a,b,c){var d=new O.esri.Tiles.TilingScheme(this),e=d.getAllCellIdsInExtent(a,b),f={level:b,tileCount:e.length,sizeBytes:e.length*c};return f},getLevel:function(){return this._level},getMaxZoom:function(a){if(null==this._maxZoom)for(var b=this.tileInfo.lods,c=this.tileInfo.lods.length,d=[],e=0;c>e;e++)d.push(b[e].level),e==c-1&&(d.sortNumber(),this._maxZoom=d[e],a(d[e]));else a(this._maxZoom)},getMinZoom:function(a){if(null==this._minZoom)for(var b=this.tileInfo.lods,c=this.tileInfo.lods.length,d=[],e=0;c>e;e++)d.push(b[e].level),e==c-1&&(d.sortNumber(),this._minZoom=d[0],a(d[0]));else a(this._minZoom)},prepareForOffline:function(a,b,c,d){this._tilesCore._createCellsForOffline(this,a,b,c,function(a){this._doNextTile(0,a,d)}.bind(this))},goOffline:function(){this.offline.online=!1},goOnline:function(){this.offline.online=!0,this.refresh()},isOnline:function(){return this.offline.online},deleteAllTiles:function(a){var b=this.offline.store;b.deleteAll(a)},getOfflineUsage:function(a){var b=this.offline.store;b.usedSpace(a)},getTilePolygons:function(a){this._tilesCore._getTilePolygons(this.offline.store,this.url,this,a)},saveToFile:function(a,b){this._tilesCore._saveToFile(a,this.offline.store,b)},loadFromFile:function(a,b){this._tilesCore._loadFromFile(a,this.offline.store,b)},estimateTileSize:function(a){this._tilesCore._estimateTileSize(b,this._lastTileUrl,this.offline.proxyPath,a)},getExtentBuffer:function(a,b){return b.xmin-=a,b.ymin-=a,b.xmax+=a,b.ymax+=a,b},getTileUrlsByExtent:function(a,b){var c=new O.esri.Tiles.TilingScheme(this),d=c.getAllCellIdsInExtent(a,b),e=[];return d.forEach(function(a){e.push(this.url+"/"+b+"/"+a[1]+"/"+a[0])}.bind(this)),e},_doNextTile:function(a,b,c){var d=b[a],e=this._getTileUrl(d.level,d.row,d.col);this._tilesCore._storeTile(e,this.offline.proxyPath,this.offline.store,function(e,f){e||(f={cell:d,msg:f});var g=c({countNow:a,countMax:b.length,cell:d,error:f,finishedDownloading:!1});g||a===b.length-1?c({finishedDownloading:!0,cancelRequested:g}):this._doNextTile(a+1,b,c)}.bind(this))},_isLocalStorage:function(){var a="test";try{return localStorage.setItem(a,a),localStorage.removeItem(a),!0}catch(b){return!1}},_getTileInfoPrivate:function(a,b){var c=new XMLHttpRequest,a=null!=this.offline.proxyPath?this.offline.proxyPath+"?"+a+"?f=pjson":a+"?f=pjson";c.open("GET",a,!0),c.onload=function(){b(200===c.status&&""!==c.responseText?this.response:!1)},c.onerror=function(a){b(!1)},c.send(null)}})}),"undefined"!=typeof O?O.esri.Tiles={}:(O={},O.esri={Tiles:{}}),O.esri.Tiles.Base64Utils={},O.esri.Tiles.Base64Utils.outputTypes={Base64:0,Hex:1,String:2,Raw:3},O.esri.Tiles.Base64Utils.addWords=function(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c},O.esri.Tiles.Base64Utils.stringToWord=function(a){for(var b=8,c=(1<e;e+=b)d[e>>5]|=(a.charCodeAt(e/b)&c)<e;e+=b)d.push(String.fromCharCode(a[e>>5]>>>e%32&c));return d.join("")},O.esri.Tiles.Base64Utils.wordToHex=function(a){for(var b="0123456789abcdef",c=[],d=0,e=4*a.length;e>d;d++)c.push(b.charAt(a[d>>2]>>d%4*8+4&15)+b.charAt(a[d>>2]>>d%4*8&15));return c.join("")},O.esri.Tiles.Base64Utils.wordToBase64=function(a){for(var b="=",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=[],e=0,f=4*a.length;f>e;e+=3)for(var g=(a[e>>2]>>8*(e%4)&255)<<16|(a[e+1>>2]>>8*((e+1)%4)&255)<<8|a[e+2>>2]>>8*((e+2)%4)&255,h=0;4>h;h++)d.push(8*e+6*h>32*a.length?b:c.charAt(g>>6*(3-h)&63));return d.join("")},O.esri.Tiles.saveAs=function(a){"use strict";var b=a.document,c=function(){return a.URL||a.webkitURL||a},d=a.URL||a.webkitURL||a,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f=!a.externalHost&&"download"in e,g=a.webkitRequestFileSystem,h=a.requestFileSystem||g||a.mozRequestFileSystem,i=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},j="application/octet-stream",k=0,l=[],m=function(){for(var a=l.length;a--;){var b=l[a];"string"==typeof b?d.revokeObjectURL(b):b.remove()}l.length=0},n=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){i(f)}}},o=function(d,i){var m,o,p,q=this,r=d.type,s=!1,t=function(){var a=c().createObjectURL(d);return l.push(a),a},u=function(){n(q,"writestart progress write writeend".split(" "))},v=function(){(s||!m)&&(m=t(d)),o?o.location.href=m:window.open(m,"_blank"),q.readyState=q.DONE,u()},w=function(a){return function(){return q.readyState!==q.DONE?a.apply(this,arguments):void 0}},x={create:!0,exclusive:!1};if(q.readyState=q.INIT,i||(i="download"),f){m=t(d),b=a.document,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),e.href=m,e.download=i;var y=b.createEvent("MouseEvents");return y.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),e.dispatchEvent(y),q.readyState=q.DONE,void u()}return a.chrome&&r&&r!==j&&(p=d.slice||d.webkitSlice,d=p.call(d,0,d.size,j),s=!0),g&&"download"!==i&&(i+=".download"),(r===j||g)&&(o=a),h?(k+=d.size,void h(a.TEMPORARY,k,w(function(a){a.root.getDirectory("saved",x,w(function(a){var b=function(){a.getFile(i,x,w(function(a){a.createWriter(w(function(b){b.onwriteend=function(b){o.location.href=a.toURL(),l.push(a),q.readyState=q.DONE,n(q,"writeend",b)},b.onerror=function(){var a=b.error;a.code!==a.ABORT_ERR&&v()},"writestart progress write abort".split(" ").forEach(function(a){b["on"+a]=q["on"+a]}),b.write(d),q.abort=function(){b.abort(),q.readyState=q.DONE},q.readyState=q.WRITING}),v)}),v)};a.getFile(i,{create:!1},w(function(a){a.remove(),b()}),w(function(a){a.code===a.NOT_FOUND_ERR?b():v()}))}),v)}),v)):void v()},p=o.prototype,q=function(a,b){return new o(a,b)};return p.abort=function(){var a=this;a.readyState=a.DONE,n(a,"abort")},p.readyState=p.INIT=0,p.WRITING=1,p.DONE=2,p.error=p.onwritestart=p.onprogress=p.onwrite=p.onabort=p.onerror=p.onwriteend=null,a.addEventListener("unload",m,!1),q}(this.self||this.window||this.content),O.esri.Tiles.TilesCore=function(){this._getTiles=function(a,b,c,d,e,f){e.retrieve(c,function(c,e){a=f("img[src="+d+"]")[0];var g;return c?(a.style.borderColor="blue",g="data:image/"+b+";base64,"+e.img):(a.style.borderColor="green",g="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTA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f8LwPx0fl9f2OQy20IwJm6vb0dTgX2+/3wej8vcCoA/VDb3XYIwLmeoyVJzGaz6LpuOKJHRFxeXkbEP5cDj+mX9e8FAThD4/H44HJfURSRpmk0TROPj48Hn3l4eIimaSJN06O3A4NJwDMxm82ibdtXo4D5fB6r1Sp+//4dz8/Pw5H+6ekpdrtdJEkS8/n8S/9f713ie3vaceo9x557QAB451Sgfyin34HKshweunk5HzAej2MymXz5+f9nbjJyI9L39Wu5XP55+XQZ39uxR4Z3u90wSXjqEV0wAjhjx47oaZq63Me/ZhIQBAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEAAbAJQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEAvqe/BwCeKjUweoA8pQAAAABJRU5ErkJggg=="),a.style.visibility="visible",a.src=g,""})},this._storeTile=function(a,b,c,d){a=a.split("?")[0];var e=b?b+"?"+a:a,f=new XMLHttpRequest;f.open("GET",e,!0),f.overrideMimeType("text/plain; charset=x-user-defined"),f.onload=function(){if(200===f.status&&""!==f.responseText){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(this.responseText)),g={url:a,img:b};c.store(g,d)}else d(!1,f.status+" "+f.statusText+": "+f.response+" when downloading "+e)},f.onerror=function(a){d(!1,a)},f.send(null)},this._createCellsForOffline=function(a,b,c,d,e){for(var f=new O.esri.Tiles.TilingScheme(a),g=[],h=b;c>=h;h++){var i=f.getAllCellIdsInExtent(d,h);if(i.forEach(function(a){g.push({level:h,row:a[1],col:a[0]})}),g.length>5e3&&h!==c)break}e(g)},this._saveToFile=function(a,b,c){var d=[];d.push("url,img"),b.getAllTiles(function(b,e,f){if("end"===f){var g=new Blob([d.join("\r\n")],{type:"text/plain;charset=utf-8"}),h=O.esri.Tiles.saveAs(g,a);if(h.readyState===h.DONE)return h.error?c(!1,"Error saving file "+a):c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a);h.onerror=function(){c(!1,"Error saving file "+a)},h.onwriteend=function(){c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a)}}else d.push(b+","+e)})},this._estimateTileSize=function(a,b,c,d){if(b){var e=c?c+"?"+b:b;a.get(e,{handleAs:"text/plain; charset=x-user-defined",headers:{"X-Requested-With":""},timeout:2e3}).then(function(a){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(a));d(b.length+e.length,null)},function(a){d(null,a)})}else d(0/0)},this._loadFromFile=function(a,b,c){if(window.File&&window.FileReader&&window.FileList&&window.Blob){var d=new FileReader;d.onload=function(d){var e,f,g=d.target.result,h=g.split("\r\n"),i=0;if("url,img"!==h[0])return c(!1,"File "+a.name+" doesn't contain tiles that can be loaded");for(var j=1;j=c;c++)for(d=i;j>=d;d++)k.push([c,d]);return k}}; \ No newline at end of file +define(["dojo/query","dojo/request","dojo/_base/declare","esri/layers/LOD","esri/geometry/Point","esri/geometry/Extent","esri/layers/TileInfo","esri/SpatialReference","esri/geometry/Polygon","esri/layers/TiledMapServiceLayer"],function(a,b,c,d,e,f,g,h,i,j){"use strict";return c("O.esri.Tiles.OfflineTileEnablerLayer",[j],{tileInfo:null,_imageType:"",_level:null,_minZoom:null,_maxZoom:null,_tilesCore:null,constructor:function(a,b,c){this._isLocalStorage()===!1&&(alert("OfflineTiles Library not supported on this browser."),b(!1)),this._tilesCore=new O.esri.Tiles.TilesCore,Array.prototype.sortNumber=function(){return this.sort(function(a,b){return a-b})},this._self=this,this._lastTileUrl="",this._imageType="",this._getTileUrl=this.getTileUrl;var d=!0;return("undefined"!=typeof c||null!=c)&&(d=c),this.offline={online:d,store:new O.esri.Tiles.TilesStore,proxyPath:null},this.offline.store.isSupported()?void this.offline.store.init(function(c){c&&this._getTileInfoPrivate(a,function(a){void 0==localStorage.__offlineTileInfo&&0!=a&&(localStorage.__offlineTileInfo=a),0==this.offline.online&&0==a&&void 0!=localStorage.__offlineTileInfo?a=localStorage.__offlineTileInfo:0==this.offline.online&&0==a&&void 0==localStorage.__offlineTileInfo&&alert("There was a problem retrieving tiled map info in OfflineTilesEnablerLayer."),this._tilesCore._parseGetTileInfo(a,function(a){this.layerInfos=a.resultObj.layers,this.minScale=a.resultObj.minScale,this.maxScale=a.resultObj.maxScale,this.tileInfo=a.tileInfo,this._imageType=this.tileInfo.format.toLowerCase(),this.fullExtent=a.fullExtent,this.spatialReference=this.tileInfo.spatialReference,this.initialExtent=a.initExtent,this.loaded=!0,this.onLoad(this),b(!0)}.bind(this._self))}.bind(this._self))}.bind(this._self)):b(!1,"indexedDB not supported")},getTileUrl:function(b,c,d){this._level=b;var e=this.url+"/tile/"+b+"/"+c+"/"+d;if(this.offline.online)return this._lastTileUrl=e,e;e=e.split("?")[0];var f="void:/"+b+"/"+c+"/"+d,g=null;return this._tilesCore._getTiles(g,this._imageType,e,f,this.offline.store,a),f},getBasemapLayer:function(a){var b=a.layerIds[0];return a.getLayer(b)},getLevelEstimation:function(a,b,c){var d=new O.esri.Tiles.TilingScheme(this),e=d.getAllCellIdsInExtent(a,b),f={level:b,tileCount:e.length,sizeBytes:e.length*c};return f},getLevel:function(){return this._level},getMaxZoom:function(a){null==this._maxZoom&&(this._maxZoom=this.tileInfo.lods[this.tileInfo.lods.length-1].level),a(this._maxZoom)},getMinZoom:function(a){null==this._minZoom&&(this._minZoom=this.tileInfo.lods[0].level),a(this._minZoom)},getMinMaxLOD:function(a,b){var c={},d=this.getMap(),e=d.getLevel()+a,f=d.getLevel()+b;return null!=this._maxZoom&&null!=this._minZoom?(c.max=Math.min(this._maxZoom,f),c.min=Math.max(this._minZoom,e)):(this.getMinZoom(function(a){c.min=Math.max(a,e)}),this.getMaxZoom(function(a){c.max=Math.min(a,f)})),c},prepareForOffline:function(a,b,c,d){this._tilesCore._createCellsForOffline(this,a,b,c,function(a){this._doNextTile(0,a,d)}.bind(this))},goOffline:function(){this.offline.online=!1},goOnline:function(){this.offline.online=!0,this.refresh()},isOnline:function(){return this.offline.online},deleteAllTiles:function(a){var b=this.offline.store;b.deleteAll(a)},getOfflineUsage:function(a){var b=this.offline.store;b.usedSpace(a)},getTilePolygons:function(a){this._tilesCore._getTilePolygons(this.offline.store,this.url,this,a)},saveToFile:function(a,b){this._tilesCore._saveToFile(a,this.offline.store,b)},loadFromFile:function(a,b){this._tilesCore._loadFromFile(a,this.offline.store,b)},estimateTileSize:function(a){this._tilesCore._estimateTileSize(b,this._lastTileUrl,this.offline.proxyPath,a)},getExtentBuffer:function(a,b){return b.xmin-=a,b.ymin-=a,b.xmax+=a,b.ymax+=a,b},getTileUrlsByExtent:function(a,b){var c=new O.esri.Tiles.TilingScheme(this),d=c.getAllCellIdsInExtent(a,b),e=[];return d.forEach(function(a){e.push(this.url+"/"+b+"/"+a[1]+"/"+a[0])}.bind(this)),e},_doNextTile:function(a,b,c){var d=b[a],e=this._getTileUrl(d.level,d.row,d.col);this._tilesCore._storeTile(e,this.offline.proxyPath,this.offline.store,function(e,f){e||(f={cell:d,msg:f});var g=c({countNow:a,countMax:b.length,cell:d,error:f,finishedDownloading:!1});g||a===b.length-1?c({finishedDownloading:!0,cancelRequested:g}):this._doNextTile(a+1,b,c)}.bind(this))},_isLocalStorage:function(){var a="test";try{return localStorage.setItem(a,a),localStorage.removeItem(a),!0}catch(b){return!1}},_getTileInfoPrivate:function(a,b){var c=new XMLHttpRequest,a=null!=this.offline.proxyPath?this.offline.proxyPath+"?"+a+"?f=pjson":a+"?f=pjson";c.open("GET",a,!0),c.onload=function(){b(200===c.status&&""!==c.responseText?this.response:!1)},c.onerror=function(a){b(!1)},c.send(null)}})}),"undefined"!=typeof O?O.esri.Tiles={}:(O={},O.esri={Tiles:{}}),O.esri.Tiles.Base64Utils={},O.esri.Tiles.Base64Utils.outputTypes={Base64:0,Hex:1,String:2,Raw:3},O.esri.Tiles.Base64Utils.addWords=function(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c},O.esri.Tiles.Base64Utils.stringToWord=function(a){for(var b=8,c=(1<e;e+=b)d[e>>5]|=(a.charCodeAt(e/b)&c)<e;e+=b)d.push(String.fromCharCode(a[e>>5]>>>e%32&c));return d.join("")},O.esri.Tiles.Base64Utils.wordToHex=function(a){for(var b="0123456789abcdef",c=[],d=0,e=4*a.length;e>d;d++)c.push(b.charAt(a[d>>2]>>d%4*8+4&15)+b.charAt(a[d>>2]>>d%4*8&15));return c.join("")},O.esri.Tiles.Base64Utils.wordToBase64=function(a){for(var b="=",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=[],e=0,f=4*a.length;f>e;e+=3)for(var g=(a[e>>2]>>8*(e%4)&255)<<16|(a[e+1>>2]>>8*((e+1)%4)&255)<<8|a[e+2>>2]>>8*((e+2)%4)&255,h=0;4>h;h++)d.push(8*e+6*h>32*a.length?b:c.charAt(g>>6*(3-h)&63));return d.join("")},O.esri.Tiles.saveAs=function(a){"use strict";var b=a.document,c=function(){return a.URL||a.webkitURL||a},d=a.URL||a.webkitURL||a,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f=!a.externalHost&&"download"in e,g=a.webkitRequestFileSystem,h=a.requestFileSystem||g||a.mozRequestFileSystem,i=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},j="application/octet-stream",k=0,l=[],m=function(){for(var a=l.length;a--;){var b=l[a];"string"==typeof b?d.revokeObjectURL(b):b.remove()}l.length=0},n=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){i(f)}}},o=function(d,i){var m,o,p,q=this,r=d.type,s=!1,t=function(){var a=c().createObjectURL(d);return l.push(a),a},u=function(){n(q,"writestart progress write writeend".split(" "))},v=function(){(s||!m)&&(m=t(d)),o?o.location.href=m:window.open(m,"_blank"),q.readyState=q.DONE,u()},w=function(a){return function(){return q.readyState!==q.DONE?a.apply(this,arguments):void 0}},x={create:!0,exclusive:!1};if(q.readyState=q.INIT,i||(i="download"),f){m=t(d),b=a.document,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),e.href=m,e.download=i;var y=b.createEvent("MouseEvents");return y.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),e.dispatchEvent(y),q.readyState=q.DONE,void u()}return a.chrome&&r&&r!==j&&(p=d.slice||d.webkitSlice,d=p.call(d,0,d.size,j),s=!0),g&&"download"!==i&&(i+=".download"),(r===j||g)&&(o=a),h?(k+=d.size,void h(a.TEMPORARY,k,w(function(a){a.root.getDirectory("saved",x,w(function(a){var b=function(){a.getFile(i,x,w(function(a){a.createWriter(w(function(b){b.onwriteend=function(b){o.location.href=a.toURL(),l.push(a),q.readyState=q.DONE,n(q,"writeend",b)},b.onerror=function(){var a=b.error;a.code!==a.ABORT_ERR&&v()},"writestart progress write abort".split(" ").forEach(function(a){b["on"+a]=q["on"+a]}),b.write(d),q.abort=function(){b.abort(),q.readyState=q.DONE},q.readyState=q.WRITING}),v)}),v)};a.getFile(i,{create:!1},w(function(a){a.remove(),b()}),w(function(a){a.code===a.NOT_FOUND_ERR?b():v()}))}),v)}),v)):void v()},p=o.prototype,q=function(a,b){return new o(a,b)};return p.abort=function(){var a=this;a.readyState=a.DONE,n(a,"abort")},p.readyState=p.INIT=0,p.WRITING=1,p.DONE=2,p.error=p.onwritestart=p.onprogress=p.onwrite=p.onabort=p.onerror=p.onwriteend=null,a.addEventListener("unload",m,!1),q}(this.self||this.window||this.content),O.esri.Tiles.TilesCore=function(){this._getTiles=function(a,b,c,d,e,f){e.retrieve(c,function(c,e){a=f("img[src="+d+"]")[0];var g;return c?(a.style.borderColor="blue",g="data:image/"+b+";base64,"+e.img):(a.style.borderColor="green",g="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG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QAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEAvqe/BwCeKjUweoA8pQAAAABJRU5ErkJggg=="),a.style.visibility="visible",a.src=g,""})},this._storeTile=function(a,b,c,d){a=a.split("?")[0];var e=b?b+"?"+a:a,f=new XMLHttpRequest;f.open("GET",e,!0),f.overrideMimeType("text/plain; charset=x-user-defined"),f.onload=function(){if(200===f.status&&""!==f.responseText){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(this.responseText)),g={url:a,img:b};c.store(g,d)}else d(!1,f.status+" "+f.statusText+": "+f.response+" when downloading "+e)},f.onerror=function(a){d(!1,a)},f.send(null)},this._createCellsForOffline=function(a,b,c,d,e){for(var f=new O.esri.Tiles.TilingScheme(a),g=[],h=b;c>=h;h++){var i=f.getAllCellIdsInExtent(d,h);if(i.forEach(function(a){g.push({level:h,row:a[1],col:a[0]})}),g.length>5e3&&h!==c)break}e(g)},this._saveToFile=function(a,b,c){var d=[];d.push("url,img"),b.getAllTiles(function(b,e,f){if("end"===f){var g=new Blob([d.join("\r\n")],{type:"text/plain;charset=utf-8"}),h=O.esri.Tiles.saveAs(g,a);if(h.readyState===h.DONE)return h.error?c(!1,"Error saving file "+a):c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a);h.onerror=function(){c(!1,"Error saving file "+a)},h.onwriteend=function(){c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a)}}else d.push(b+","+e)})},this._estimateTileSize=function(a,b,c,d){if(b){var e=c?c+"?"+b:b;a.get(e,{handleAs:"text/plain; charset=x-user-defined",headers:{"X-Requested-With":""},timeout:2e3}).then(function(a){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(a));d(b.length+e.length,null)},function(a){d(null,a)})}else d(0/0)},this._loadFromFile=function(a,b,c){if(window.File&&window.FileReader&&window.FileList&&window.Blob){var d=new FileReader;d.onload=function(d){var e,f,g=d.target.result,h=g.split("\r\n"),i=0;if("url,img"!==h[0])return c(!1,"File "+a.name+" doesn't contain tiles that can be loaded");for(var j=1;j=c;c++)for(d=i;j>=d;d++)k.push([c,d]);return k}}; \ No newline at end of file diff --git a/dist/offline-tiles-advanced-src.js b/dist/offline-tiles-advanced-src.js index f983928c..7e3e90c6 100644 --- a/dist/offline-tiles-advanced-src.js +++ b/dist/offline-tiles-advanced-src.js @@ -1,4 +1,4 @@ -/*! offline-editor - v2.2 - 2014-09-30 +/*! offline-editor-js - v2.3 - 2014-10-13 * Copyright (c) 2014 Environmental Systems Research Institute, Inc. * Apache License*/ define([ @@ -193,22 +193,9 @@ define([ getMaxZoom: function(callback){ if(this._maxZoom == null){ - var lods = this.tileInfo.lods; - var length = this.tileInfo.lods.length; - var tempArr = []; - for(var i=0; i < length; i++){ - tempArr.push(lods[i].level); - if(i == length -1){ - tempArr.sortNumber(); - this._maxZoom = tempArr[i]; - callback(tempArr[i]); - } - } + this._maxZoom = this.tileInfo.lods[this.tileInfo.lods.length-1].level; } - else{ - callback(this._maxZoom); - } - + callback(this._maxZoom); }, /** @@ -218,21 +205,38 @@ define([ getMinZoom: function(callback){ if(this._minZoom == null){ - var lods = this.tileInfo.lods; - var length = this.tileInfo.lods.length; - var tempArr = []; - for(var i=0; i < length; i++){ - tempArr.push(lods[i].level); - if(i == length -1){ - tempArr.sortNumber(); - this._minZoom = tempArr[0]; - callback(tempArr[0]); - } - } + this._minZoom = this.tileInfo.lods[0].level; + } + callback(this._minZoom); + }, + + /** + * Utility method for bracketing above and below your current Level of Detail. Use + * this in conjunction with setting the minLevel and maxLevel in prepareForOffline(). + * @param minZoomAdjust An Integer specifying how far above the current layer you want to retrieve tiles + * @param maxZoomAdjust An Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles + */ + getMinMaxLOD: function(minZoomAdjust,maxZoomAdjust){ + var zoom = {}; + var map = this.getMap(); + var min = map.getLevel() + minZoomAdjust; + var max = map.getLevel() + maxZoomAdjust; + if(this._maxZoom != null && this._minZoom != null){ + zoom.max = Math.min(this._maxZoom, max); //prevent errors by setting the tile layer floor + zoom.min = Math.max(this._minZoom, min); //prevent errors by setting the tile layer ceiling } else{ - callback(this._minZoom); + this.getMinZoom(function(result){ + zoom.min = Math.max(result, min); //prevent errors by setting the tile layer ceiling + }); + + this.getMaxZoom(function(result){ + zoom.max = Math.min(result, max); //prevent errors by setting the tile layer floor + }); } + + return zoom; + }, /** @@ -805,7 +809,7 @@ O.esri.Tiles.TilesCore = function(){ */ this._getTiles = function(image,imageType,url,tileid,store,query){ store.retrieve(url, function(success, offlineTile) - { console.log("TILE RETURN " + success + ", " + offlineTile) + { console.log("TILE RETURN " + success + ", " + offlineTile.url) /* when the .getTileUrl() callback is triggered we replace the temporary URL originally returned by the data:image url */ // search for the img with src="void:"+level+"-"+row+"-"+col and replace with actual url image = query("img[src="+tileid+"]")[0]; diff --git a/dist/offline-tiles-basic-min.js b/dist/offline-tiles-basic-min.js index 1a30fedc..955fe3bd 100644 --- a/dist/offline-tiles-basic-min.js +++ b/dist/offline-tiles-basic-min.js @@ -1 +1 @@ -define(["dojo/query","dojo/request","esri/geometry/Polygon","dojo/_base/declare"],function(a,b,c,d){"use strict";return d("O.esri.Tiles.OfflineTilesEnabler",[],{getBasemapLayer:function(a){var b=a.layerIds[0];return a.getLayer(b)},extend:function(c,d,e){c._tilesCore=new O.esri.Tiles.TilesCore,c._lastTileUrl="",c._imageType="",c._getTileUrl=c.getTileUrl;var f=!0;return"undefined"!=typeof e&&(f=e),c.offline={online:f,store:new O.esri.Tiles.TilesStore,proxyPath:null},c.offline.store.isSupported()?(c.offline.store.init(function(b){b&&(c.resampling=!1,c.getTileUrl=function(b,d,e){var f=this._getTileUrl(b,d,e);if(this.offline.online)return""==c._imageType&&(c._imageType=this.tileInfo.format.toLowerCase()),c._lastTileUrl=f,f;f=f.split("?")[0];var g="void:/"+b+"/"+d+"/"+e,h=null;return c._tilesCore._getTiles(h,this._imageType,f,g,this.offline.store,a),g},d&&d(!0))}.bind(this)),c.getLevelEstimation=function(a,b,c){var d=new O.esri.Tiles.TilingScheme(this),e=d.getAllCellIdsInExtent(a,b),f={level:b,tileCount:e.length,sizeBytes:e.length*c};return f},c.prepareForOffline=function(a,b,d,e){c._tilesCore._createCellsForOffline(this,a,b,d,function(a){this._doNextTile(0,a,e)}.bind(this))},c.goOffline=function(){this.offline.online=!1},c.goOnline=function(){this.offline.online=!0,this.refresh()},c.isOnline=function(){return this.offline.online},c.deleteAllTiles=function(a){var b=this.offline.store;b.deleteAll(a)},c.getOfflineUsage=function(a){var b=this.offline.store;b.usedSpace(a)},c.getTilePolygons=function(a){c._tilesCore._getTilePolygons(this.offline.store,c.url,this,a)},c.saveToFile=function(a,b){c._tilesCore._saveToFile(a,this.offline.store,b)},c.loadFromFile=function(a,b){c._tilesCore._loadFromFile(a,this.offline.store,b)},c.estimateTileSize=function(a){c._tilesCore._estimateTileSize(b,this._lastTileUrl,this.offline.proxyPath,a)},c.getExtentBuffer=function(a,b){return b.xmin-=a,b.ymin-=a,b.xmax+=a,b.ymax+=a,b},c.getTileUrlsByExtent=function(a,b){var d=new O.esri.Tiles.TilingScheme(c),e=d.getAllCellIdsInExtent(a,b),f=[];return e.forEach(function(a){f.push(c.url+"/"+b+"/"+a[1]+"/"+a[0])}.bind(this)),f},void(c._doNextTile=function(a,b,d){var e=b[a],f=this._getTileUrl(e.level,e.row,e.col);c._tilesCore._storeTile(f,this.offline.proxyPath,this.offline.store,function(c,f){c||(f={cell:e,msg:f});var g=d({countNow:a,countMax:b.length,cell:e,error:f,finishedDownloading:!1});g||a===b.length-1?d({finishedDownloading:!0,cancelRequested:g}):this._doNextTile(a+1,b,d)}.bind(this))})):d(!1,"indexedDB not supported")}})}),"undefined"!=typeof O?O.esri.Tiles={}:(O={},O.esri={Tiles:{}}),O.esri.Tiles.Base64Utils={},O.esri.Tiles.Base64Utils.outputTypes={Base64:0,Hex:1,String:2,Raw:3},O.esri.Tiles.Base64Utils.addWords=function(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c},O.esri.Tiles.Base64Utils.stringToWord=function(a){for(var b=8,c=(1<e;e+=b)d[e>>5]|=(a.charCodeAt(e/b)&c)<e;e+=b)d.push(String.fromCharCode(a[e>>5]>>>e%32&c));return d.join("")},O.esri.Tiles.Base64Utils.wordToHex=function(a){for(var b="0123456789abcdef",c=[],d=0,e=4*a.length;e>d;d++)c.push(b.charAt(a[d>>2]>>d%4*8+4&15)+b.charAt(a[d>>2]>>d%4*8&15));return c.join("")},O.esri.Tiles.Base64Utils.wordToBase64=function(a){for(var b="=",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=[],e=0,f=4*a.length;f>e;e+=3)for(var g=(a[e>>2]>>8*(e%4)&255)<<16|(a[e+1>>2]>>8*((e+1)%4)&255)<<8|a[e+2>>2]>>8*((e+2)%4)&255,h=0;4>h;h++)d.push(8*e+6*h>32*a.length?b:c.charAt(g>>6*(3-h)&63));return d.join("")},O.esri.Tiles.saveAs=function(a){"use strict";var b=a.document,c=function(){return a.URL||a.webkitURL||a},d=a.URL||a.webkitURL||a,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f=!a.externalHost&&"download"in e,g=a.webkitRequestFileSystem,h=a.requestFileSystem||g||a.mozRequestFileSystem,i=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},j="application/octet-stream",k=0,l=[],m=function(){for(var a=l.length;a--;){var b=l[a];"string"==typeof b?d.revokeObjectURL(b):b.remove()}l.length=0},n=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){i(f)}}},o=function(d,i){var m,o,p,q=this,r=d.type,s=!1,t=function(){var a=c().createObjectURL(d);return l.push(a),a},u=function(){n(q,"writestart progress write writeend".split(" "))},v=function(){(s||!m)&&(m=t(d)),o?o.location.href=m:window.open(m,"_blank"),q.readyState=q.DONE,u()},w=function(a){return function(){return q.readyState!==q.DONE?a.apply(this,arguments):void 0}},x={create:!0,exclusive:!1};if(q.readyState=q.INIT,i||(i="download"),f){m=t(d),b=a.document,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),e.href=m,e.download=i;var y=b.createEvent("MouseEvents");return y.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),e.dispatchEvent(y),q.readyState=q.DONE,void u()}return a.chrome&&r&&r!==j&&(p=d.slice||d.webkitSlice,d=p.call(d,0,d.size,j),s=!0),g&&"download"!==i&&(i+=".download"),(r===j||g)&&(o=a),h?(k+=d.size,void h(a.TEMPORARY,k,w(function(a){a.root.getDirectory("saved",x,w(function(a){var b=function(){a.getFile(i,x,w(function(a){a.createWriter(w(function(b){b.onwriteend=function(b){o.location.href=a.toURL(),l.push(a),q.readyState=q.DONE,n(q,"writeend",b)},b.onerror=function(){var a=b.error;a.code!==a.ABORT_ERR&&v()},"writestart progress write abort".split(" ").forEach(function(a){b["on"+a]=q["on"+a]}),b.write(d),q.abort=function(){b.abort(),q.readyState=q.DONE},q.readyState=q.WRITING}),v)}),v)};a.getFile(i,{create:!1},w(function(a){a.remove(),b()}),w(function(a){a.code===a.NOT_FOUND_ERR?b():v()}))}),v)}),v)):void v()},p=o.prototype,q=function(a,b){return new o(a,b)};return p.abort=function(){var a=this;a.readyState=a.DONE,n(a,"abort")},p.readyState=p.INIT=0,p.WRITING=1,p.DONE=2,p.error=p.onwritestart=p.onprogress=p.onwrite=p.onabort=p.onerror=p.onwriteend=null,a.addEventListener("unload",m,!1),q}(this.self||this.window||this.content),O.esri.Tiles.TilesCore=function(){this._getTiles=function(a,b,c,d,e,f){e.retrieve(c,function(c,e){a=f("img[src="+d+"]")[0];var g;return c?(a.style.borderColor="blue",g="data:image/"+b+";base64,"+e.img):(a.style.borderColor="green",g="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXm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wCeKjUweoA8pQAAAABJRU5ErkJggg=="),a.style.visibility="visible",a.src=g,""})},this._storeTile=function(a,b,c,d){a=a.split("?")[0];var e=b?b+"?"+a:a,f=new XMLHttpRequest;f.open("GET",e,!0),f.overrideMimeType("text/plain; charset=x-user-defined"),f.onload=function(){if(200===f.status&&""!==f.responseText){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(this.responseText)),g={url:a,img:b};c.store(g,d)}else d(!1,f.status+" "+f.statusText+": "+f.response+" when downloading "+e)},f.onerror=function(a){d(!1,a)},f.send(null)},this._createCellsForOffline=function(a,b,c,d,e){for(var f=new O.esri.Tiles.TilingScheme(a),g=[],h=b;c>=h;h++){var i=f.getAllCellIdsInExtent(d,h);if(i.forEach(function(a){g.push({level:h,row:a[1],col:a[0]})}),g.length>5e3&&h!==c)break}e(g)},this._saveToFile=function(a,b,c){var d=[];d.push("url,img"),b.getAllTiles(function(b,e,f){if("end"===f){var g=new Blob([d.join("\r\n")],{type:"text/plain;charset=utf-8"}),h=O.esri.Tiles.saveAs(g,a);if(h.readyState===h.DONE)return h.error?c(!1,"Error saving file "+a):c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a);h.onerror=function(){c(!1,"Error saving file "+a)},h.onwriteend=function(){c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a)}}else d.push(b+","+e)})},this._estimateTileSize=function(a,b,c,d){if(b){var e=c?c+"?"+b:b;a.get(e,{handleAs:"text/plain; charset=x-user-defined",headers:{"X-Requested-With":""},timeout:2e3}).then(function(a){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(a));d(b.length+e.length,null)},function(a){d(null,a)})}else d(0/0)},this._loadFromFile=function(a,b,c){if(window.File&&window.FileReader&&window.FileList&&window.Blob){var d=new FileReader;d.onload=function(d){var e,f,g=d.target.result,h=g.split("\r\n"),i=0;if("url,img"!==h[0])return c(!1,"File "+a.name+" doesn't contain tiles that can be loaded");for(var j=1;j=c;c++)for(d=i;j>=d;d++)k.push([c,d]);return k}}; \ No newline at end of file +define(["dojo/query","dojo/request","esri/geometry/Polygon","dojo/_base/declare"],function(a,b,c,d){"use strict";return d("O.esri.Tiles.OfflineTilesEnabler",[],{getBasemapLayer:function(a){var b=a.layerIds[0];return a.getLayer(b)},extend:function(c,d,e){c._tilesCore=new O.esri.Tiles.TilesCore,c._lastTileUrl="",c._imageType="",c._minZoom=null,c._maxZoom=null,c._getTileUrl=c.getTileUrl;var f=!0;return"undefined"!=typeof e&&(f=e),c.offline={online:f,store:new O.esri.Tiles.TilesStore,proxyPath:null},c.offline.store.isSupported()?(c.offline.store.init(function(b){b&&(c.resampling=!1,c.getTileUrl=function(b,d,e){var f=this._getTileUrl(b,d,e);if(this.offline.online)return""==c._imageType&&(c._imageType=this.tileInfo.format.toLowerCase()),c._lastTileUrl=f,f;f=f.split("?")[0];var g="void:/"+b+"/"+d+"/"+e,h=null;return c._tilesCore._getTiles(h,this._imageType,f,g,this.offline.store,a),g},d&&d(!0))}.bind(this)),c.getLevelEstimation=function(a,b,c){var d=new O.esri.Tiles.TilingScheme(this),e=d.getAllCellIdsInExtent(a,b),f={level:b,tileCount:e.length,sizeBytes:e.length*c};return f},c.prepareForOffline=function(a,b,d,e){c._tilesCore._createCellsForOffline(this,a,b,d,function(a){this._doNextTile(0,a,e)}.bind(this))},c.goOffline=function(){this.offline.online=!1},c.goOnline=function(){this.offline.online=!0,this.refresh()},c.isOnline=function(){return this.offline.online},c.deleteAllTiles=function(a){var b=this.offline.store;b.deleteAll(a)},c.getOfflineUsage=function(a){var b=this.offline.store;b.usedSpace(a)},c.getTilePolygons=function(a){c._tilesCore._getTilePolygons(this.offline.store,c.url,this,a)},c.saveToFile=function(a,b){c._tilesCore._saveToFile(a,this.offline.store,b)},c.loadFromFile=function(a,b){c._tilesCore._loadFromFile(a,this.offline.store,b)},c.getMaxZoom=function(a){null==this._maxZoom&&(this._maxZoom=c.tileInfo.lods[c.tileInfo.lods.length-1].level),a(this._maxZoom)},c.getMinZoom=function(a){null==this._minZoom&&(this._minZoom=c.tileInfo.lods[0].level),a(this._minZoom)},c.getMinMaxLOD=function(a,b){var d={},e=c.getMap(),f=e.getLevel()+a,g=e.getLevel()+b;return null!=this._maxZoom&&null!=this._minZoom?(d.max=Math.min(this._maxZoom,g),d.min=Math.max(this._minZoom,f)):(c.getMinZoom(function(a){d.min=Math.max(a,f)}),c.getMaxZoom(function(a){d.max=Math.min(a,g)})),d},c.estimateTileSize=function(a){c._tilesCore._estimateTileSize(b,this._lastTileUrl,this.offline.proxyPath,a)},c.getExtentBuffer=function(a,b){return b.xmin-=a,b.ymin-=a,b.xmax+=a,b.ymax+=a,b},c.getTileUrlsByExtent=function(a,b){var d=new O.esri.Tiles.TilingScheme(c),e=d.getAllCellIdsInExtent(a,b),f=[];return e.forEach(function(a){f.push(c.url+"/"+b+"/"+a[1]+"/"+a[0])}.bind(this)),f},void(c._doNextTile=function(a,b,d){var e=b[a],f=this._getTileUrl(e.level,e.row,e.col);c._tilesCore._storeTile(f,this.offline.proxyPath,this.offline.store,function(c,f){c||(f={cell:e,msg:f});var g=d({countNow:a,countMax:b.length,cell:e,error:f,finishedDownloading:!1});g||a===b.length-1?d({finishedDownloading:!0,cancelRequested:g}):this._doNextTile(a+1,b,d)}.bind(this))})):d(!1,"indexedDB not supported")}})}),"undefined"!=typeof O?O.esri.Tiles={}:(O={},O.esri={Tiles:{}}),O.esri.Tiles.Base64Utils={},O.esri.Tiles.Base64Utils.outputTypes={Base64:0,Hex:1,String:2,Raw:3},O.esri.Tiles.Base64Utils.addWords=function(a,b){var c=(65535&a)+(65535&b),d=(a>>16)+(b>>16)+(c>>16);return d<<16|65535&c},O.esri.Tiles.Base64Utils.stringToWord=function(a){for(var b=8,c=(1<e;e+=b)d[e>>5]|=(a.charCodeAt(e/b)&c)<e;e+=b)d.push(String.fromCharCode(a[e>>5]>>>e%32&c));return d.join("")},O.esri.Tiles.Base64Utils.wordToHex=function(a){for(var b="0123456789abcdef",c=[],d=0,e=4*a.length;e>d;d++)c.push(b.charAt(a[d>>2]>>d%4*8+4&15)+b.charAt(a[d>>2]>>d%4*8&15));return c.join("")},O.esri.Tiles.Base64Utils.wordToBase64=function(a){for(var b="=",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",d=[],e=0,f=4*a.length;f>e;e+=3)for(var g=(a[e>>2]>>8*(e%4)&255)<<16|(a[e+1>>2]>>8*((e+1)%4)&255)<<8|a[e+2>>2]>>8*((e+2)%4)&255,h=0;4>h;h++)d.push(8*e+6*h>32*a.length?b:c.charAt(g>>6*(3-h)&63));return d.join("")},O.esri.Tiles.saveAs=function(a){"use strict";var b=a.document,c=function(){return a.URL||a.webkitURL||a},d=a.URL||a.webkitURL||a,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),f=!a.externalHost&&"download"in e,g=a.webkitRequestFileSystem,h=a.requestFileSystem||g||a.mozRequestFileSystem,i=function(b){(a.setImmediate||a.setTimeout)(function(){throw b},0)},j="application/octet-stream",k=0,l=[],m=function(){for(var a=l.length;a--;){var b=l[a];"string"==typeof b?d.revokeObjectURL(b):b.remove()}l.length=0},n=function(a,b,c){b=[].concat(b);for(var d=b.length;d--;){var e=a["on"+b[d]];if("function"==typeof e)try{e.call(a,c||a)}catch(f){i(f)}}},o=function(d,i){var m,o,p,q=this,r=d.type,s=!1,t=function(){var a=c().createObjectURL(d);return l.push(a),a},u=function(){n(q,"writestart progress write writeend".split(" "))},v=function(){(s||!m)&&(m=t(d)),o?o.location.href=m:window.open(m,"_blank"),q.readyState=q.DONE,u()},w=function(a){return function(){return q.readyState!==q.DONE?a.apply(this,arguments):void 0}},x={create:!0,exclusive:!1};if(q.readyState=q.INIT,i||(i="download"),f){m=t(d),b=a.document,e=b.createElementNS("http://www.w3.org/1999/xhtml","a"),e.href=m,e.download=i;var y=b.createEvent("MouseEvents");return y.initMouseEvent("click",!0,!1,a,0,0,0,0,0,!1,!1,!1,!1,0,null),e.dispatchEvent(y),q.readyState=q.DONE,void u()}return a.chrome&&r&&r!==j&&(p=d.slice||d.webkitSlice,d=p.call(d,0,d.size,j),s=!0),g&&"download"!==i&&(i+=".download"),(r===j||g)&&(o=a),h?(k+=d.size,void h(a.TEMPORARY,k,w(function(a){a.root.getDirectory("saved",x,w(function(a){var b=function(){a.getFile(i,x,w(function(a){a.createWriter(w(function(b){b.onwriteend=function(b){o.location.href=a.toURL(),l.push(a),q.readyState=q.DONE,n(q,"writeend",b)},b.onerror=function(){var a=b.error;a.code!==a.ABORT_ERR&&v()},"writestart progress write abort".split(" ").forEach(function(a){b["on"+a]=q["on"+a]}),b.write(d),q.abort=function(){b.abort(),q.readyState=q.DONE},q.readyState=q.WRITING}),v)}),v)};a.getFile(i,{create:!1},w(function(a){a.remove(),b()}),w(function(a){a.code===a.NOT_FOUND_ERR?b():v()}))}),v)}),v)):void v()},p=o.prototype,q=function(a,b){return new o(a,b)};return p.abort=function(){var a=this;a.readyState=a.DONE,n(a,"abort")},p.readyState=p.INIT=0,p.WRITING=1,p.DONE=2,p.error=p.onwritestart=p.onprogress=p.onwrite=p.onabort=p.onerror=p.onwriteend=null,a.addEventListener("unload",m,!1),q}(this.self||this.window||this.content),O.esri.Tiles.TilesCore=function(){this._getTiles=function(a,b,c,d,e,f){e.retrieve(c,function(c,e){a=f("img[src="+d+"]")[0];var g;return c?(a.style.borderColor="blue",g="data:image/"+b+";base64,"+e.img):(a.style.borderColor="green",g="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2Afk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Ewmk2ia5uSOu91uIyJiPB4ffU+/rJ/AA6cAZ2A6ncbz83NUVRV5nr97hO8n104Nrftln53s+ypVVR2czpj8MwLghPl8HkmSDBN556xt22ia5tU/jAA4IU3TmE6nUVVVVFUVs9nsbH/LqUuFGAFwxPX1deR5HnVdD+f8LwPx0fl9f2OQy20IwJm6vb0dTgX2+/3wej8vcCoA/VDb3XYIwLmeoyVJzGaz6LpuOKJHRFxeXkbEP5cDj+mX9e8FAThD4/H44HJfURSRpmk0TROPj48Hn3l4eIimaSJN06O3A4NJwDMxm82ibdtXo4D5fB6r1Sp+//4dz8/Pw5H+6ekpdrtdJEkS8/n8S/9f713ie3vaceo9x557QAB451Sgfyin34HKshweunk5HzAej2MymXz5+f9nbjJyI9L39Wu5XP55+XQZ39uxR4Z3u90wSXjqEV0wAjhjx47oaZq63Me/ZhIQBAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEAAbAJQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAQAAAAQAEABAAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEABAAAABAAQAEAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEABAAQAEAAAAEAvqe/BwCeKjUweoA8pQAAAABJRU5ErkJggg=="),a.style.visibility="visible",a.src=g,""})},this._storeTile=function(a,b,c,d){a=a.split("?")[0];var e=b?b+"?"+a:a,f=new XMLHttpRequest;f.open("GET",e,!0),f.overrideMimeType("text/plain; charset=x-user-defined"),f.onload=function(){if(200===f.status&&""!==f.responseText){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(this.responseText)),g={url:a,img:b};c.store(g,d)}else d(!1,f.status+" "+f.statusText+": "+f.response+" when downloading "+e)},f.onerror=function(a){d(!1,a)},f.send(null)},this._createCellsForOffline=function(a,b,c,d,e){for(var f=new O.esri.Tiles.TilingScheme(a),g=[],h=b;c>=h;h++){var i=f.getAllCellIdsInExtent(d,h);if(i.forEach(function(a){g.push({level:h,row:a[1],col:a[0]})}),g.length>5e3&&h!==c)break}e(g)},this._saveToFile=function(a,b,c){var d=[];d.push("url,img"),b.getAllTiles(function(b,e,f){if("end"===f){var g=new Blob([d.join("\r\n")],{type:"text/plain;charset=utf-8"}),h=O.esri.Tiles.saveAs(g,a);if(h.readyState===h.DONE)return h.error?c(!1,"Error saving file "+a):c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a);h.onerror=function(){c(!1,"Error saving file "+a)},h.onwriteend=function(){c(!0,"Saved "+(d.length-1)+" tiles ("+Math.floor(g.size/1024/1024*100)/100+" Mb) into "+a)}}else d.push(b+","+e)})},this._estimateTileSize=function(a,b,c,d){if(b){var e=c?c+"?"+b:b;a.get(e,{handleAs:"text/plain; charset=x-user-defined",headers:{"X-Requested-With":""},timeout:2e3}).then(function(a){var b=O.esri.Tiles.Base64Utils.wordToBase64(O.esri.Tiles.Base64Utils.stringToWord(a));d(b.length+e.length,null)},function(a){d(null,a)})}else d(0/0)},this._loadFromFile=function(a,b,c){if(window.File&&window.FileReader&&window.FileList&&window.Blob){var d=new FileReader;d.onload=function(d){var e,f,g=d.target.result,h=g.split("\r\n"),i=0;if("url,img"!==h[0])return c(!1,"File "+a.name+" doesn't contain tiles that can be loaded");for(var j=1;j=c;c++)for(d=i;j>=d;d++)k.push([c,d]);return k}}; \ No newline at end of file diff --git a/dist/offline-tiles-basic-src.js b/dist/offline-tiles-basic-src.js index 4db38f63..e88bb985 100644 --- a/dist/offline-tiles-basic-src.js +++ b/dist/offline-tiles-basic-src.js @@ -1,4 +1,4 @@ -/*! offline-editor - v2.2 - 2014-09-30 +/*! offline-editor-js - v2.3 - 2014-10-13 * Copyright (c) 2014 Environmental Systems Research Institute, Inc. * Apache License*/ define([ @@ -37,6 +37,8 @@ define([ layer._tilesCore = new O.esri.Tiles.TilesCore(); layer._lastTileUrl = ""; layer._imageType = ""; + layer._minZoom = null; + layer._maxZoom = null; /* we add some methods to the layer object */ /* we don't want to extend the tiled layer class, as it is a capability that we want to add only to one instance */ @@ -242,6 +244,59 @@ define([ layer._tilesCore._loadFromFile(file,this.offline.store,callback); }; + /** + * Returns the maximum zoom level for this layer + * @param callback number + */ + layer.getMaxZoom = function(callback){ + // TO-DO make this a simple return rather than a callback + if(this._maxZoom == null){ + this._maxZoom = layer.tileInfo.lods[layer.tileInfo.lods.length-1].level; + } + callback(this._maxZoom); + }, + + /** + * Returns the minimum zoom level for this layer + * @param callback number + */ + layer.getMinZoom = function(callback){ + // TO-DO make this a simple return rather than a callback + if(this._minZoom == null){ + this._minZoom = layer.tileInfo.lods[0].level; + } + callback(this._minZoom); + }; + + /** + * Utility method for bracketing above and below your current Level of Detail. Use + * this in conjunction with setting the minLevel and maxLevel in prepareForOffline(). + * @param minZoomAdjust An Integer specifying how far above the current layer you want to retrieve tiles + * @param maxZoomAdjust An Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles + */ + layer.getMinMaxLOD = function(minZoomAdjust,maxZoomAdjust){ + var zoom = {}; + var map = layer.getMap(); + var min = map.getLevel() + minZoomAdjust; + var max = map.getLevel() + maxZoomAdjust; + if(this._maxZoom != null && this._minZoom != null){ + zoom.max = Math.min(this._maxZoom, max); //prevent errors by setting the tile layer floor + zoom.min = Math.max(this._minZoom, min); //prevent errors by setting the tile layer ceiling + } + else{ + layer.getMinZoom(function(result){ + zoom.min = Math.max(result, min); //prevent errors by setting the tile layer ceiling + }); + + layer.getMaxZoom(function(result){ + zoom.max = Math.min(result, max); //prevent errors by setting the tile layer floor + }); + } + + return zoom; + + }; + /* internal methods */ /** @@ -668,7 +723,7 @@ O.esri.Tiles.TilesCore = function(){ */ this._getTiles = function(image,imageType,url,tileid,store,query){ store.retrieve(url, function(success, offlineTile) - { console.log("TILE RETURN " + success + ", " + offlineTile) + { console.log("TILE RETURN " + success + ", " + offlineTile.url) /* when the .getTileUrl() callback is triggered we replace the temporary URL originally returned by the data:image url */ // search for the img with src="void:"+level+"-"+row+"-"+col and replace with actual url image = query("img[src="+tileid+"]")[0]; diff --git a/dist/offline-tpk-src.js b/dist/offline-tpk-src.js index 096eb5ee..e1a91406 100644 --- a/dist/offline-tpk-src.js +++ b/dist/offline-tpk-src.js @@ -1,4 +1,4 @@ -/*! offline-editor - v2.2 - 2014-09-30 +/*! offline-editor-js - v2.3 - 2014-10-13 * Copyright (c) 2014 Environmental Systems Research Institute, Inc. * Apache License*/ /** diff --git a/doc/howtouseappcache.md b/doc/howtouseappcache.md index 0f409649..2347d41d 100644 --- a/doc/howtouseappcache.md +++ b/doc/howtouseappcache.md @@ -3,7 +3,7 @@ Tips on using application cache If you have a requirement to reload your application or restart the browser while offline then you will need to use the [application cache](http://appcachefacts.info/). Some developers also use application caches to speed up page reload performance. For example, Google uses an application cache when load their main web page. -The application cache, also sometimes referred to as the 'manifest file', will allow you to store any file that is required for offline use. The list of acceptable files includes html, JavaScript libraries, CSS and images. Any file that your application requires to run normally will have to be referenced in the application cache. +The application cache, also sometimes referred to as the 'manifest file', will allow you to store any file that is required for offline use. The list of acceptable files that you can store includes html, JavaScript libraries, CSS and images. Any file that your application requires to run normally will have to be referenced in the application cache. This is not to be confused with the Local Storage API. Once an application and its associated files are stored in the application cache it will be available from the cache the next time an application restarts. @@ -35,6 +35,27 @@ NOTE: You cannot use the regular CDN for the ArcGIS API for JavaScript because t In the `/samples` directory there are two examples, `appcache-features.html` and `appcache-tiles.html` that demonstrate how to use tiles, features and the appCacheManager with the application cache. +### IMPORTANT Usage Tips + +The application cache isn't ready until the `CACHE_LOADED` event fires. After that event a user can safely take the application offline. Sometimes files can load very slowwwwwly, and sometimes they can timeout. Be sure to take this into account. + +If ANY file specified in the application cache fails to load for any reason, then the entire load will be rejected by the browser. The entire application cache will fail to load and no files will from the loading process will be cached. + +There may be differences in the amount of application cache storage available between desktop browsers, mobile browsers and browsers that use WebView (e.g. PhoneGap). If this is mission critical for you, we strongly recommend that you do your own testing to verify the facts. + +Use an application cache validator, for example: [http://manifest-validator.com/](http://manifest-validator.com/) + +Too large of an application can cause a mobile browser to run slugglishly or crash frequently. Be aware of how large the application cache is. To check the size: + +* Chrome - [chrome://appcache-internals/](chrome://appcache-internals/). This gives you access to all files stored for each application, and the total size of each cache. +* Firefox - Menu (or on Mac go to Firefox > preferences) > advanced > Network. + * For firefox Mobile user will be prompted after first 5MBs have been consumed. + * Note, you can also increase the amount of storage here by checking 'Override automatic cache manage' and enter a new limit value. Or, type about:config in address bar > modify the value field for `browser.cache.disk.capacity`. + * Note: firefox has a theoretical upper bound of [1GB](http://mxr.mozilla.org/mozilla-central/source/netwerk/cache/nsCacheService.cpp#607) and apparently a tested/verified(?) upper bound of [500MB](http://www.html5rocks.com/en/tutorials/offline/quota-research/) on Android. + +* Safari - Developer Tools > Show Web Inspector > Application Cache (click on the cookie crumbs at the top left of the console window). this won't give you the total size, but you can at least see what is in the cache and each objects size. + + ###Configuring your web server Your web server must be able to serve up the MIME TYPE `TEXT/cache-manifest`. If this is missing there's a really good chance that the application cache file won't be served up to your app. @@ -65,8 +86,12 @@ Most modern browsers support application cache including IE v10 and v11, Firefox ### References +[Offline web applications - Quota Research](http://www.html5rocks.com/en/tutorials/offline/quota-research/) + [Support for application cache](http://caniuse.com/#search=appcache) [Appcache Facts](http://appcachefacts.info/) -[Using the application cache - Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache) \ No newline at end of file +[Using the application cache - Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache) + +[Safari Client-side Storage and Offline Applications](https://developer.apple.com/library/safari/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html) \ No newline at end of file diff --git a/doc/offlinefeaturesmanager.md b/doc/offlinefeaturesmanager.md index 63b1004e..2f3ace26 100644 --- a/doc/offlinefeaturesmanager.md +++ b/doc/offlinefeaturesmanager.md @@ -1,8 +1,8 @@ API OfflineFeaturesManager -================================== +========================== ##O.esri.Edit.OfflineFeaturesManager -Extends and overrides a feature layer. This library allows you to extend esri.layers.FeatureLayer objects with offline capability and manage the resync process. +The `offline-edit-min.js` library provides the following tools for working with esri.layers.FeatureLayer objects while partially or fully offline. ###Constructor diff --git a/doc/offlinetilesenabler.md b/doc/offlinetilesenabler.md index dfd0f817..7983a71e 100644 --- a/doc/offlinetilesenabler.md +++ b/doc/offlinetilesenabler.md @@ -3,74 +3,37 @@ API Doc for OfflineTilesEnabler There are two different libraries for taking tiles offline: `offline-tiles-basic-min.js` and `offline-tiles-advanced-min.js`. The basic library is for use with ArcGIS.com web maps and partial/intermittently offline use cases. You won't be able to restart or reload your app when using this library offline. -If you have a requirement for restarting or reloading the app while offline then you should use the advanced library. The `offline-tiles-advanced-min.js` library lets you create a custom basemap layer that extends TiledMapServiceLayer. To view the docs for this library scroll down on this page. +If you have a requirement for restarting or reloading the app while offline then you should use the advanced library. The `offline-tiles-advanced-min.js` library lets you create a custom basemap layer that extends TiledMapServiceLayer. ##O.esri.Tiles.OfflineTilesEnabler -Extends and overrides a tiled map service. For use with ArcGIS.com maps or partial-offline situations that don't require a browser restart or reload. - -Provides the ability to customize the extent used to cut the tiles. See the detailed description of `basemap.prepareForOffline()` in the "How To Use" section below to learn different options. +The `offline-tiles-basic-min.js` library provides the following tools for working with with ArcGIS.com maps or tiled map services in partial-offline situations that don't require a browser restart or reload. ###Constructor Constructor | Description --- | --- `O.esri.Tiles.OfflineTilesEnabler()` | Creates an instance of the offlineTilesEnabler class. This library allows you to extend an ArcGISTiledMapServiceLayer with partial offline capability as well as manage the online/offline resynchronization process. - -###Methods -Methods | Returns | Description ---- | --- | --- -`extend(layer, callback)`|`callback(boolean, string)` |Overrides an ArcGISTiledMapServiceLayer. Callback is called after indexedDb store is initialized and informs the application whether it is indexedDb is supported or not. -`goOffline()` | nothing | This method puts the layer in offline mode. When in offline mode, the layer will not fetch any tile from the remote server. It will look up the tiles in the indexed db database and display them in the layer. If the tile can't be found in the local database it will show up blank (even if there is actual connectivity). The pair of methods `goOffline()` and `goOnline() `allows the developer to manually control the behaviour of the layer. Used in conjunction with the offline dectection library, you can put the layer in the appropriate mode when the offline condition changes. -`goOnline()` | nothing | This method puts the layer in online mode. When in online mode, the layer will behave as regular layers, fetching all tiles from the remote server. If there is no internet connectivity the tiles may appear thanks to the browsers cache, but no attempt will be made to look up tiles in the local database. -`getLevelEstimation(extent,` `level, tileSize)` | {level, tileCount, sizeBytes} | Returns an object that contains the number of tiles that would need to be downloaded for the specified extent and zoom level, and the estimated byte size of such tiles. This method is useful to give the user an indication of the required time and space before launching the actual download operation. The byte size estimation is very rough. -`getExtentBuffer(buffer,extent)`| Extent | Returns a new extent buffered by a given measurement that's based on map units. For example, if you are using mercator map projection then the buffer property would be in meters and the new extent would be returned in mercactor. -`getTileUrlsByExtent(extent, level)` | Array | Returns an array of tile urls within a given map extent and zoom level. -`deleteAllTiles(callback)` | `callback(boolean, errors)` | Clears the local cache of tiles. -`getOfflineUsage(callback)` | `callback(size, error)` | Gets the size in bytes of the local tile cache. -`getTilePolygons(callback)` | `callback(polygon, error)` | Gets polygons representing all cached tiles. This is helpful to give users a visual feedback of the current content of the tile cache. -`saveToFile(filename, callback)` | `callback( boolean, error)` | Saves tile cache into a portable csv format. -`loadFromFile(filename, callback)` | `callback( boolean, error)` | Reads a csv file into local tile cache. -`estimateTileSize(callback)` | `callback(number)` | Retrieves one tile from a layer and then returns its size. -`prepareForOffline(` `minLevel, maxLevel, extent, ` `reportProgress)` | `callback(number)` | Retrieves tiles and stores them in the local cache. See the "How To Use" section below to learn more about customizing the use of this method. - ###Properties Property | Description --- | --- -`layer.offline.proxyPath`| For CORS enabled servers this can be set to `null`. The default is to use the internal resource-proxy path: `libs/offline-editor-js/resource-proxy/proxy.php.` Don't forget to check your proxy configuration to allow connections for all possible services that you might be using. More information on using proxies with ArcGIS can be found here: [https://developers.arcgis.com/javascript/jshelp/ags_proxy.html](https://developers.arcgis.com/javascript/jshelp/ags_proxy.html). - - - -##O.esri.Tiles.OfflineTilesEnablerLayer -Extends and overrides a tiled map service. This library can be used in situations where an offline browser restart or reload is required. - -###Constructor -Constructor | Description ---- | --- -`O.esri.Tiles.OfflineTilesEnablerLayer(url,callback,state)` | Creates an instance of the offlineTilesEnabler class. This library allows you to extend an ArcGISTiledMapServiceLayer with offline capability as well as manage the online/offline resynchronization process. Any Esri basemap REST endpoint should work. The state property is a boolean for specifying if the application is intializing the layer online (true) or offline (false). When you first load the map you should set this property to `true`. - +`layer.offline.proxyPath`| The default is `null`. If you have a CORS-enabled service then use the default. Don't forget to check your proxy configuration to allow connections for all possible services that you might be using. More information on using proxies with ArcGIS can be found here: [https://developers.arcgis.com/javascript/jshelp/ags_proxy.html](https://developers.arcgis.com/javascript/jshelp/ags_proxy.html). ###Methods Methods | Returns | Description --- | --- | --- -`goOffline()` | nothing | This method puts the layer in offline mode. When in offline mode, the layer will not fetch any tile from the remote server. It will look up the tiles in the indexed db database and display them in the layer. If the tile can't be found in the local database it will show up blank (even if there is actual connectivity). The pair of methods `goOffline()` and `goOnline() `allows the developer to manually control the behaviour of the layer. Used in conjunction with the offline dectection library, you can put the layer in the appropriate mode when the offline condition changes. +`extend(layer, callback)`|`callback(boolean, string)` |Overrides an ArcGISTiledMapServiceLayer. Callback is called after indexedDB store is initialized and informs the application whether it is indexedDB is supported or not. +`prepareForOffline(` `minLevel, maxLevel, extent, ` `reportProgress)` | `callback(number)` | Retrieves tiles and stores them in the local cache. For more information see [How To Use Tiles Library](howtousetiles.md). +`goOffline()` | nothing | This method puts the layer in offline mode. When in offline mode, the layer will not fetch any tile from the remote server. It will look up the tiles in the IndexedDB database and display them in the layer. If the tile can't be found in the local database it will show up blank (even if there is actual connectivity). The pair of methods `goOffline()` and `goOnline() `allows the developer to manually control the behaviour of the layer. Used in conjunction with the offline dectection library, you can put the layer in the appropriate mode when the offline condition changes. `goOnline()` | nothing | This method puts the layer in online mode. When in online mode, the layer will behave as regular layers, fetching all tiles from the remote server. If there is no internet connectivity the tiles may appear thanks to the browsers cache, but no attempt will be made to look up tiles in the local database. -`getLevelEstimation(extent,` `level, tileSize)` | {level, tileCount, sizeBytes} | Returns an object that contains the number of tiles that would need to be downloaded for the specified extent and zoom level, and the estimated byte size of such tiles. This method is useful to give the user an indication of the required time and space before launching the actual download operation. The byte size estimation is very rough. -`getExtentBuffer(buffer,extent)`| Extent | Returns a new extent buffered by a given measurement that's based on map units. For example, if you are using mercator map projection then the buffer property would be in meters and the new extent would be returned in mercactor. -`getTileUrlsByExtent(extent, level)` | Array | Returns an array of tile urls within a given map extent and zoom level. +`getLevelEstimation(extent,` `level, tileSize)` | {level, tileCount, sizeBytes} | Returns an object that contains the number of tiles that would need to be downloaded for the specified `"esri/geometry/Extent"`, zoom level `integer`, and the estimated byte size `integer`. This method is useful to give the user an indication of the required time and space before launching the actual download operation. The byte size estimation is very rough. +`getExtentBuffer(buffer,extent)`| Extent | `buffer` property is an `integer`. `extent` property is an `"esri/geometry/Extent"`. Returns a new extent buffered by a given measurement that's based on map units. For example, if you are using mercator map projection then the buffer property would be in meters and the new extent would be returned in mercactor. +`getTileUrlsByExtent(extent, level)` | Array | Returns an array of tile urls within a given map extent `"esri/geometry/Extent"` and zoom level `integer`. `deleteAllTiles(callback)` | `callback(boolean, errors)` | Clears the local cache of tiles. `getOfflineUsage(callback)` | `callback(size, error)` | Gets the size in bytes of the local tile cache. `getTilePolygons(callback)` | `callback(polygon, error)` | Gets polygons representing all cached tiles. This is helpful to give users a visual feedback of the current content of the tile cache. `saveToFile(filename, callback)` | `callback( boolean, error)` | Saves tile cache into a portable csv format. `loadFromFile(filename, callback)` | `callback( boolean, error)` | Reads a csv file into local tile cache. `estimateTileSize(callback)` | `callback(number)` | Retrieves one tile from a layer and then returns its size. -`prepareForOffline(` `minLevel, maxLevel, extent, ` `reportProgress)` | `callback(number)` | Retrieves tiles and stores them in the local cache. See the "How To Use" section below to learn more about customizing the use of this method. -`getMaxZoom(callback)` | `callback(number)` | Returns the maximum zoom level of the layer. -`getMinZoom(callback)` | `callback(number)` | Returns the minimum zoom level of the layer. - - -###Properties -Property | Description ---- | --- -`layer.offline.proxyPath`| For CORS enabled servers this can be set to `null`. The default is to use the internal resource-proxy path: `libs/offline-editor-js/resource-proxy/proxy.php.` Don't forget to check your proxy configuration to allow connections for all possible services that you might be using. More information on using proxies with ArcGIS can be found here: [https://developers.arcgis.com/javascript/jshelp/ags_proxy.html](https://developers.arcgis.com/javascript/jshelp/ags_proxy.html). - - +`getMinZoom(callback)` | `callback(number)` | Returns the minimum zoom level of the layer. This is the zoom level farther away from the earth. +`getMaxZoom(callback)` | `callback(number)` | Returns the maximum zoom level of the layer. This is the zoom level closest to the earth. +`getMinMaxLOD(minZoomAdjust,` `maxZoomAdjust)` | `{min: zoomLevel, max: zoomLevel}` | Utility method for bracketing above and below your current Level of Detail. Use this in conjunction with setting the minLevel and maxLevel in `prepareForOffline()`. `minZoomAdjust` is an Integer specifying how far above the current layer you want to retrieve tiles. `maxZoomAdjust` is an Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles \ No newline at end of file diff --git a/doc/offlinetilesenablerlayer.md b/doc/offlinetilesenablerlayer.md new file mode 100644 index 00000000..0a2f1d3b --- /dev/null +++ b/doc/offlinetilesenablerlayer.md @@ -0,0 +1,40 @@ +API Doc for OfflineTilesEnablerLayer +==================================== + +There are two different libraries for taking tiles offline: `offline-tiles-basic-min.js` and `offline-tiles-advanced-min.js`. The basic library is for use with ArcGIS.com web maps and partial/intermittently offline use cases. You won't be able to restart or reload your app when using this library offline. + +If you have a requirement for restarting or reloading the app while offline then you should use the advanced library. The `offline-tiles-advanced-min.js` library lets you create a custom basemap layer that extends TiledMapServiceLayer. + +##O.esri.Tiles.OfflineTilesEnablerLayer +The `offline-tiles-advanced-min.js` library provides the following tools for working with tiled map services. This library is designed for both partial and full offline use cases, and it will work if you have a requirement for browser reloads or restarts while offline. + +###Constructor +Constructor | Description +--- | --- +`O.esri.Tiles.OfflineTilesEnablerLayer(url,callback,state)` | Creates an instance of the offlineTilesEnabler class. This library allows you to extend an ArcGISTiledMapServiceLayer with offline capability as well as manage the online/offline resynchronization process. Any Esri basemap REST endpoint should work. The state property is a boolean for specifying if the application is intializing the layer online (true) or offline (false). When you first load the map you should set this property to `true`. + +###Properties +Property | Description +--- | --- +`layer.offline.proxyPath`| For CORS enabled servers this can be set to `null`. The default is null. All ArcGIS Online-based services uses CORS. If you are using a non-CORS enabled server you'll need a proxy. Don't forget to check your proxy configuration to allow connections for all possible services that you might be using. More information on using proxies with ArcGIS can be found here: [https://developers.arcgis.com/javascript/jshelp/ags_proxy.html](https://developers.arcgis.com/javascript/jshelp/ags_proxy.html). + +###Methods +Methods | Returns | Description +--- | --- | --- +`prepareForOffline(` `minLevel, maxLevel, extent, ` `reportProgress)` | `callback(number)` | Retrieves tiles and stores them in the local cache. For more information see [How To Use Tiles Library](howtousetiles.md). +`goOffline()` | nothing | This method puts the layer in offline mode. When in offline mode, the layer will not fetch any tile from the remote server. It will look up the tiles in the indexed db database and display them in the layer. If the tile can't be found in the local database it will show up blank (even if there is actual connectivity). The pair of methods `goOffline()` and `goOnline() `allows the developer to manually control the behaviour of the layer. Used in conjunction with the offline dectection library, you can put the layer in the appropriate mode when the offline condition changes. +`goOnline()` | nothing | This method puts the layer in online mode. When in online mode, the layer will behave as regular layers, fetching all tiles from the remote server. If there is no internet connectivity the tiles may appear thanks to the browsers cache, but no attempt will be made to look up tiles in the local database. +`getLevelEstimation(extent,` `level, tileSize)` | {level, tileCount, sizeBytes} | Returns an object that contains the number of tiles that would need to be downloaded for the specified `"esri/geometry/Extent"`, zoom level `integer`, and the estimated byte size `integer`. This method is useful to give the user an indication of the required time and space before launching the actual download operation. The byte size estimation is very rough. +`getExtentBuffer(buffer,extent)`| Extent | `buffer` property is an `integer`. `extent` property is an `"esri/geometry/Extent"`. Returns a new extent buffered by a given measurement that's based on map units. For example, if you are using mercator map projection then the buffer property would be in meters and the new extent would be returned in mercactor. +`getTileUrlsByExtent(extent, level)` | Array | Returns an array of tile urls within a given map extent and zoom level. +`deleteAllTiles(callback)` | `callback(boolean, errors)` | Clears the local cache of tiles. +`getOfflineUsage(callback)` | `callback(size, error)` | Gets the size in bytes of the local tile cache. +`getTilePolygons(callback)` | `callback(polygon, error)` | Gets polygons representing all cached tiles. This is helpful to give users a visual feedback of the current content of the tile cache. +`saveToFile(filename, callback)` | `callback( boolean, error)` | Saves tile cache into a portable csv format. +`loadFromFile(filename, callback)` | `callback( boolean, error)` | Reads a csv file into local tile cache. +`estimateTileSize(callback)` | `callback(number)` | Retrieves one tile from a layer and then returns its size. +`getMaxZoom(callback)` | `callback(number)` | Returns the maximum zoom level of the layer. +`getMinZoom(callback)` | `callback(number)` | Returns the minimum zoom level of the layer. +`getMinMaxLOD(minZoomAdjust,` `maxZoomAdjust)` | `{min: zoomLevel, max: zoomLevel}` | Utility method for bracketing above and below your current Level of Detail. Use this in conjunction with setting the minLevel and maxLevel in `prepareForOffline()`. `minZoomAdjust` is an Integer specifying how far above the current layer you want to retrieve tiles. `maxZoomAdjust` is an Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles + + diff --git a/doc/tpklayer.md b/doc/tpklayer.md index 80c9800f..e22c6e0b 100644 --- a/doc/tpklayer.md +++ b/doc/tpklayer.md @@ -3,7 +3,7 @@ API Doc for TPKLayer ##O.esri.TPK.TPKLayer -Extends a tiled map service and provides the ability to display tiles from a .tpk (ArcGIS Tile Page). +The `offline-tpk-min.js` library extends a tiled map service and provides the following tools for working with and displaying tiles from a .tpk file (ArcGIS Tile Package). ###Constructor diff --git a/lib/tiles/OfflineTilesEnablerLayer.js b/lib/tiles/OfflineTilesEnablerLayer.js index 62a5d021..31553cb8 100644 --- a/lib/tiles/OfflineTilesEnablerLayer.js +++ b/lib/tiles/OfflineTilesEnablerLayer.js @@ -190,22 +190,9 @@ define([ getMaxZoom: function(callback){ if(this._maxZoom == null){ - var lods = this.tileInfo.lods; - var length = this.tileInfo.lods.length; - var tempArr = []; - for(var i=0; i < length; i++){ - tempArr.push(lods[i].level); - if(i == length -1){ - tempArr.sortNumber(); - this._maxZoom = tempArr[i]; - callback(tempArr[i]); - } - } - } - else{ - callback(this._maxZoom); + this._maxZoom = this.tileInfo.lods[this.tileInfo.lods.length-1].level; } - + callback(this._maxZoom); }, /** @@ -215,21 +202,38 @@ define([ getMinZoom: function(callback){ if(this._minZoom == null){ - var lods = this.tileInfo.lods; - var length = this.tileInfo.lods.length; - var tempArr = []; - for(var i=0; i < length; i++){ - tempArr.push(lods[i].level); - if(i == length -1){ - tempArr.sortNumber(); - this._minZoom = tempArr[0]; - callback(tempArr[0]); - } - } + this._minZoom = this.tileInfo.lods[0].level; + } + callback(this._minZoom); + }, + + /** + * Utility method for bracketing above and below your current Level of Detail. Use + * this in conjunction with setting the minLevel and maxLevel in prepareForOffline(). + * @param minZoomAdjust An Integer specifying how far above the current layer you want to retrieve tiles + * @param maxZoomAdjust An Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles + */ + getMinMaxLOD: function(minZoomAdjust,maxZoomAdjust){ + var zoom = {}; + var map = this.getMap(); + var min = map.getLevel() + minZoomAdjust; + var max = map.getLevel() + maxZoomAdjust; + if(this._maxZoom != null && this._minZoom != null){ + zoom.max = Math.min(this._maxZoom, max); //prevent errors by setting the tile layer floor + zoom.min = Math.max(this._minZoom, min); //prevent errors by setting the tile layer ceiling } else{ - callback(this._minZoom); + this.getMinZoom(function(result){ + zoom.min = Math.max(result, min); //prevent errors by setting the tile layer ceiling + }); + + this.getMaxZoom(function(result){ + zoom.max = Math.min(result, max); //prevent errors by setting the tile layer floor + }); } + + return zoom; + }, /** diff --git a/lib/tiles/TilesCore.js b/lib/tiles/TilesCore.js index 0c2f860e..5a7d4da5 100644 --- a/lib/tiles/TilesCore.js +++ b/lib/tiles/TilesCore.js @@ -16,7 +16,7 @@ O.esri.Tiles.TilesCore = function(){ */ this._getTiles = function(image,imageType,url,tileid,store,query){ store.retrieve(url, function(success, offlineTile) - { console.log("TILE RETURN " + success + ", " + offlineTile) + { console.log("TILE RETURN " + success + ", " + offlineTile.url) /* when the .getTileUrl() callback is triggered we replace the temporary URL originally returned by the data:image url */ // search for the img with src="void:"+level+"-"+row+"-"+col and replace with actual url image = query("img[src="+tileid+"]")[0]; diff --git a/lib/tiles/offlineTilesEnabler.js b/lib/tiles/offlineTilesEnabler.js index 771699ad..359ca7cd 100644 --- a/lib/tiles/offlineTilesEnabler.js +++ b/lib/tiles/offlineTilesEnabler.js @@ -34,6 +34,8 @@ define([ layer._tilesCore = new O.esri.Tiles.TilesCore(); layer._lastTileUrl = ""; layer._imageType = ""; + layer._minZoom = null; + layer._maxZoom = null; /* we add some methods to the layer object */ /* we don't want to extend the tiled layer class, as it is a capability that we want to add only to one instance */ @@ -239,6 +241,59 @@ define([ layer._tilesCore._loadFromFile(file,this.offline.store,callback); }; + /** + * Returns the maximum zoom level for this layer + * @param callback number + */ + layer.getMaxZoom = function(callback){ + // TO-DO make this a simple return rather than a callback + if(this._maxZoom == null){ + this._maxZoom = layer.tileInfo.lods[layer.tileInfo.lods.length-1].level; + } + callback(this._maxZoom); + }, + + /** + * Returns the minimum zoom level for this layer + * @param callback number + */ + layer.getMinZoom = function(callback){ + // TO-DO make this a simple return rather than a callback + if(this._minZoom == null){ + this._minZoom = layer.tileInfo.lods[0].level; + } + callback(this._minZoom); + }; + + /** + * Utility method for bracketing above and below your current Level of Detail. Use + * this in conjunction with setting the minLevel and maxLevel in prepareForOffline(). + * @param minZoomAdjust An Integer specifying how far above the current layer you want to retrieve tiles + * @param maxZoomAdjust An Integer specifying how far below (closer to earth) the current layer you want to retrieve tiles + */ + layer.getMinMaxLOD = function(minZoomAdjust,maxZoomAdjust){ + var zoom = {}; + var map = layer.getMap(); + var min = map.getLevel() + minZoomAdjust; + var max = map.getLevel() + maxZoomAdjust; + if(this._maxZoom != null && this._minZoom != null){ + zoom.max = Math.min(this._maxZoom, max); //prevent errors by setting the tile layer floor + zoom.min = Math.max(this._minZoom, min); //prevent errors by setting the tile layer ceiling + } + else{ + layer.getMinZoom(function(result){ + zoom.min = Math.max(result, min); //prevent errors by setting the tile layer ceiling + }); + + layer.getMaxZoom(function(result){ + zoom.max = Math.min(result, max); //prevent errors by setting the tile layer floor + }); + } + + return zoom; + + }; + /* internal methods */ /** diff --git a/package.json b/package.json index 358c05b1..1728b3a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "offline-editor", - "version": "2.2", + "name": "offline-editor-js", + "version": "2.3", "description": "Lighweight set of libraries for working offline with map tiles and ArcGIS feature services", "author": "Andy Gup (http://blog.andygup.net)", "license": "Apache 2", diff --git a/samples/Gruntfile.js b/samples/Gruntfile.js index 2622387b..0c5bd9f6 100644 --- a/samples/Gruntfile.js +++ b/samples/Gruntfile.js @@ -25,27 +25,35 @@ module.exports = function(grunt) { "<%= pkg.appHomePage %>", "#", "# ArcGIS API for JavaScript files", - "<%= pkg.optimizedApiURL %>/dojo/dojo.js", - "<%= pkg.optimizedApiURL %>/dojo/nls/dojo_en-us.js", - "<%= pkg.optimizedApiURL %>/dojo/selector/acme.js", + "<%= pkg.optimizedApiURL %>/dojo.js", + "<%= pkg.optimizedApiURL %>/selector/acme.js", + "<%= pkg.optimizedApiURL %>/nls/dojo_en.js", + "<%= pkg.optimizedApiURL %>/resources/blank.gif", "#", - "#<%= pkg.arcGISBaseURL %>/js/esri/dijit/images/popup-sprite.png", - "<%= pkg.arcGISBaseURL %>/js/esri/dijit/images/attribute_inspector_sprite.png", - "<%= pkg.arcGISBaseURL %>/js/dojo/dojox/gfx/svg.js", - "<%= pkg.arcGISBaseURL %>/js/dojo/dojo/resources/blank.gif", - "<%= pkg.arcGISBaseURL %>/js/esri/dijit/images/ajax-loader.gif", - "<%= pkg.arcGISBaseURL %>/js/esri/images/map/logo-sm.png", - "<%= pkg.arcGISBaseURL %>/js/esri/images/map/logo-med.png", - "<%= pkg.arcGISBaseURL %>/js/esri/css/esri.css", - "<%= pkg.arcGISBaseURL %>/js/dojo/dijit/themes/claro/claro.css", - "<%= pkg.arcGISBaseURL %>/js/esri/nls/jsapi_en-us.js", + "#<%= pkg.arcGISBaseURL %>/esri/dijit/images/popup-sprite.png", + "<%= pkg.arcGISBaseURL %>/esri/dijit/images/attribute_inspector_sprite.png", + "#<%= pkg.arcGISBaseURL %>/dojo/resources/blank.gif", + "<%= pkg.arcGISBaseURL %>/esri/dijit/images/ajax-loader.gif", + "<%= pkg.arcGISBaseURL %>/esri/images/map/logo-sm.png", + "<%= pkg.arcGISBaseURL %>/esri/images/map/logo-med.png", + "<%= pkg.arcGISBaseURL %>/esri/css/esri.css", + "<%= pkg.arcGISBaseURL %>/dijit/themes/claro/claro.css", + "<%= pkg.arcGISBaseURL %>/esri/nls/jsapi_en-us.js", "#", "//services.arcgisonline.com/ArcGIS/rest/info?f=json", "//static.arcgis.com/attribution/World_Topo_Map?f=json", + "//server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=pjson", "//services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback", "#", - "# required for web maps", - "<%= pkg.arcGISBaseURL %>/js/esri/dijit/images/ajax-loader.gif", + "# Bootstrap files", + "//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", + "//esri.github.io/bootstrap-map-js/src/js/bootstrapmap.js", + "https://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", "#", "# required local html", "# /xyz/style.css", @@ -70,7 +78,14 @@ module.exports = function(grunt) { "../utils/*.js", "../dist/offline-edit-src.js", "../dist/offline-tiles-advanced-src.js", - "../dist/offline-tiles-basic-src.js" + "../dist/offline-tiles-basic-src.js", + "../samples/widgets/modal/css/*.css", + "../samples/widgets/modal/template/*.html", + "../samples/widgets/modal/popup.js", + "<%= pkg.optimizedApiURL %>/nls/*.js", + "<%= pkg.optimizedApiURL %>/resources/*.gif", + "<%= pkg.optimizedApiURL %>/dojo.js", + "<%= pkg.optimizedApiURL %>/selector/*.js" /* "images/*", "css/*.css" diff --git a/samples/appcache-features.appcache b/samples/appcache-features.appcache index a13b9fd6..66af0dd7 100644 --- a/samples/appcache-features.appcache +++ b/samples/appcache-features.appcache @@ -1,35 +1,41 @@ CACHE MANIFEST # This manifest was generated by grunt-manifest HTML5 Cache Manifest Generator -# Time: Mon Sep 08 2014 11:50:44 GMT-0600 (MDT) +# Time: Fri Oct 10 2014 16:02:50 GMT-0600 (MDT) CACHE: -# manifest-generator, version: 0.0.1 +# manifest-generator, version: 2.3 # # Home Page appcache-features.html # # ArcGIS API for JavaScript files -http://js.arcgis.com/o/agup_hack4co/appcacheFeatures/dojo/dojo.js -http://js.arcgis.com/o/agup_hack4co/appcacheFeatures/dojo/nls/dojo_en-us.js -http://js.arcgis.com/o/agup_hack4co/appcacheFeatures/dojo/selector/acme.js +# http://js.arcgis.com/o/agup_hack4co/appcacheFeatures2/dojo/dojo.js +# http://js.arcgis.com/o/agup_hack4co/appcacheFeatures2/dojo/selector/acme.js # -#http://js.arcgis.com/3.10/js/esri/dijit/images/popup-sprite.png -http://js.arcgis.com/3.10/js/esri/dijit/images/attribute_inspector_sprite.png -http://js.arcgis.com/3.10/js/dojo/dojox/gfx/svg.js -http://js.arcgis.com/3.10/js/dojo/dojo/resources/blank.gif -http://js.arcgis.com/3.10/js/esri/dijit/images/ajax-loader.gif -http://js.arcgis.com/3.10/js/esri/images/map/logo-sm.png -http://js.arcgis.com/3.10/js/esri/images/map/logo-med.png -http://js.arcgis.com/3.10/js/esri/css/esri.css -http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css -http://js.arcgis.com/3.10/js/esri/nls/jsapi_en-us.js +#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/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 +http://js.arcgis.com/3.11/esri/css/esri.css +http://js.arcgis.com/3.11/dijit/themes/claro/claro.css +http://js.arcgis.com/3.11/esri/nls/jsapi_en-us.js # //services.arcgisonline.com/ArcGIS/rest/info?f=json //static.arcgis.com/attribution/World_Topo_Map?f=json +//server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=pjson //services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback # -# required for web maps -http://js.arcgis.com/3.10/js/esri/dijit/images/ajax-loader.gif +# Bootstrap files +//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 + +# Custom feature service +http://services.arcgis.com/IZtlGBUe4KTzLOl4/arcgis/rest/services/BPX_RTD_BusStops2/FeatureServer/0?f=json # # required local html # /xyz/style.css @@ -47,6 +53,14 @@ http://js.arcgis.com/3.10/js/esri/dijit/images/ajax-loader.gif ../dist/offline-edit-src.js ../dist/offline-tiles-advanced-src.js ../dist/offline-tiles-basic-src.js +../samples/widgets/modal/css/modal-popup.css +../samples/widgets/modal/template/popup.html +../samples/widgets/modal/popup.js +../samples/jsolib/nls/dojo_en.js +../samples/jsolib/resources/blank.gif +../samples/jsolib/dojo.js +../samples/jsolib/selector/acme.js +../samples/jsolib/selector/lite.js NETWORK: * diff --git a/samples/appcache-features.html b/samples/appcache-features.html index f4c5508f..ff21644b 100644 --- a/samples/appcache-features.html +++ b/samples/appcache-features.html @@ -1,98 +1,77 @@ - + + + AppCache Tiles and Features - + + + - + + + + + + + + + + + + - - - + + + -
- - -
- -
Pending edits: 0
-
-
-