diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/ApplyScheduledUpdatesToPreplannedMapArea.png b/map/apply-scheduled-updates-to-preplanned-map-area/ApplyScheduledUpdatesToPreplannedMapArea.png new file mode 100644 index 0000000000..1bfebbb2bc Binary files /dev/null and b/map/apply-scheduled-updates-to-preplanned-map-area/ApplyScheduledUpdatesToPreplannedMapArea.png differ diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/README.md b/map/apply-scheduled-updates-to-preplanned-map-area/README.md new file mode 100644 index 0000000000..804478ae59 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/README.md @@ -0,0 +1,48 @@ +# Apply scheduled updates to preplanned map area + +Apply scheduled updates to a downloaded preplanned map area. + +![Apply Scheduled Updates to Preplanned Map Area Sample](ApplyScheduledUpdatesToPreplannedMapArea.png) + +## Use case + +With scheduled updates, the author can update the features within the preplanned areas on the service once, and multiple end-users can request these updates to bring their local copies up to date with the most recent state. Importantly, any number of end-users can download the same set of cached updates which means that this workflow is extremely scalable for large operations where you need to minimize load on the server. + +This workflow can be used by survey workers operating in remote areas where network connectivity is not available. The workers could download mobile map packages to their individual devices and perform their work normally. Once they regain internet connectivity, the mobile map packages can be updated to show any new features that have been added to the online service. + +## How to use the sample + +Start the app. It will display an offline map, check for available updates, and show an alert with update availability and size. Confirm to apply the updates to the local offline map and show the results. + +## How it works + +1. Create an `OfflineMapSyncTask` with an offline map. +2. Use `offlineMapSyncTask.checkForUpdatesAsync()` to get a `OfflineMapUpdatesInfo` object. +3. Check if the download availability on the info is `AVAILABLE`. +4. To download the updates, create default sync parameters from the task. +5. Set the `PreplannedScheduledUpdatesOption` and the rollback behavior on the parameters. +6. Use `offlineMapSyncTask.syncOfflineMap(parameters)` to create an `OfflineMapSyncJob`. +7. Start the job and get the `OfflineMapSyncResult`. +8. Check if the mobile map package needs to be reopened, and do so if necessary. Display the offline map to see the + changes. + +## Relevant API + +* MobileMapPackage +* OfflineMapSyncJob +* OfflineMapSyncParameters +* OfflineMapSyncResult +* OfflineMapSyncTask +* OfflineMapUpdatesInfo + +## About the data + +The data in this sample shows the roads and trails in the Canyonlands National Park, Utah. Data by [U.S. National Parks Service](https://public-nps.opendata.arcgis.com/). No claim to original U.S. Government works. + +## Additional information + +**Note:** preplanned areas using the Scheduled Updates workflow are read-only. For preplanned areas that can be edited on the end-user device, see [Take a map offline - preplanned](https://developers.arcgis.com/java/latest/guide/take-map-offline-preplanned.htm). + +## Tags + +offline, preplanned, pre-planned, synchronize, update diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/README.metadata.json b/map/apply-scheduled-updates-to-preplanned-map-area/README.metadata.json new file mode 100644 index 0000000000..75751397ee --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/README.metadata.json @@ -0,0 +1,28 @@ +{ + "category": "Map", + "description": "Apply scheduled updates to a downloaded preplanned map area.", + "ignore": false, + "images": [ + "ApplyScheduledUpdatesToPreplannedMapArea.png" + ], + "keywords": [ + "offline", + "preplanned", + "pre-planned", + "synchronize", + "update" + ], + "redirect_from": "", + "relevant_apis": [ + "MobileMapPackage", + "OfflineMapSyncJob", + "OfflineMapSyncParameters", + "OfflineMapSyncResult", + "OfflineMapSyncTask", + "OfflineMapUpdatesInfo" + ], + "snippets": [ + "src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaSample.java" + ], + "title": "Apply scheduled updates to preplanned map area" +} diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/build.gradle b/map/apply-scheduled-updates-to-preplanned-map-area/build.gradle new file mode 100644 index 0000000000..7d91252871 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/build.gradle @@ -0,0 +1,78 @@ +plugins { + id 'application' + id 'org.openjfx.javafxplugin' version '0.0.5' +} + +group = 'com.esri.samples' + +ext { + arcgisVersion = '100.6.0' +} + +javafx { + version = "11.0.1" + modules = [ 'javafx.controls' ] +} + +compileJava.options.encoding = 'UTF-8' + +repositories { + jcenter() + maven { + url 'https://esri.bintray.com/arcgis' + } + maven { + url 'http://olympus.esri.com/artifactory/arcgisruntime-repo' + } +} + +configurations { + natives +} + +dependencies { + compile "com.esri.arcgisruntime:arcgis-java:$arcgisVersion" + natives "com.esri.arcgisruntime:arcgis-java-jnilibs:$arcgisVersion" + natives "com.esri.arcgisruntime:arcgis-java-resources:$arcgisVersion" + compile 'commons-io:commons-io:2.4' +} + +task copyNatives(type: Copy) { + description = "Copies the arcgis native libraries into the project build directory for development." + group = "build" + configurations.natives.asFileTree.each { + from(zipTree(it)) + } + // store native libraries in a common location shared with other samples + into "${System.properties.getProperty("user.home")}/.arcgis/$arcgisVersion" +} + +run { + dependsOn copyNatives + mainClassName = 'com.esri.samples.apply_scheduled_updates_to_preplanned_map_area.ApplyScheduledUpdatesToPreplannedMapAreaLauncher' +} + +jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + manifest { + attributes("Main-Class": "$mainClassName") + } + from { + configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } + } +} + +task productionZip(type: Zip) { + group = 'distribution' + from ("samples-data") { + into "samples-data" + } + from copyNatives + from jar.destinationDir + into (project.name) + baseName = project.name +} + +wrapper { + gradleVersion = '5.0' +} diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/gradle/wrapper/gradle-wrapper.jar b/map/apply-scheduled-updates-to-preplanned-map-area/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..5c2d1cf016 Binary files /dev/null and b/map/apply-scheduled-updates-to-preplanned-map-area/gradle/wrapper/gradle-wrapper.jar differ diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/gradlew b/map/apply-scheduled-updates-to-preplanned-map-area/gradlew new file mode 100644 index 0000000000..8e25e6c19d --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/gradlew @@ -0,0 +1,188 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/gradlew.bat b/map/apply-scheduled-updates-to-preplanned-map-area/gradlew.bat new file mode 100644 index 0000000000..9618d8d960 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/gradlew.bat @@ -0,0 +1,100 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/settings.gradle b/map/apply-scheduled-updates-to-preplanned-map-area/settings.gradle new file mode 100644 index 0000000000..c9943f3e0e --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/settings.gradle @@ -0,0 +1,16 @@ +rootProject.name = 'apply-scheduled-updates-to-preplanned-map-area' + +// download sample data +def ant = new groovy.util.AntBuilder() + +if (!file("./samples-data").exists()) { + ant.get( + src: "https://arcgisruntime.maps.arcgis.com/sharing/rest/content/items/740b663bff5e4198b9b6674af93f638a/data", + dest: file("./data.zip") + ) + ant.unzip( + src: file("./data.zip"), + dest: file("./samples-data/canyonlands") + ) + delete file("./data.zip") +} diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaLauncher.java b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaLauncher.java new file mode 100644 index 0000000000..14cb990c02 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaLauncher.java @@ -0,0 +1,11 @@ +package com.esri.samples.apply_scheduled_updates_to_preplanned_map_area; + +/** +* Wrapper required for launching a JavaFX 11 app through Gradle or from a jar. +*/ +public class ApplyScheduledUpdatesToPreplannedMapAreaLauncher { + + public static void main(String[] args) { + ApplyScheduledUpdatesToPreplannedMapAreaSample.main(args); + } +} diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaSample.java b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaSample.java new file mode 100644 index 0000000000..bb715fad99 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/java/com/esri/samples/apply_scheduled_updates_to_preplanned_map_area/ApplyScheduledUpdatesToPreplannedMapAreaSample.java @@ -0,0 +1,225 @@ +/* + * Copyright 2019 Esri. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.esri.samples.apply_scheduled_updates_to_preplanned_map_area; + +import java.io.File; +import java.nio.file.Files; +import java.util.Optional; +import java.util.concurrent.ExecutionException; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.ButtonType; +import javafx.scene.layout.StackPane; +import javafx.stage.Stage; +import org.apache.commons.io.FileUtils; + +import com.esri.arcgisruntime.concurrent.Job; +import com.esri.arcgisruntime.concurrent.ListenableFuture; +import com.esri.arcgisruntime.loadable.LoadStatus; +import com.esri.arcgisruntime.mapping.ArcGISMap; +import com.esri.arcgisruntime.mapping.MobileMapPackage; +import com.esri.arcgisruntime.mapping.view.MapView; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineMapSyncJob; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineMapSyncParameters; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineMapSyncResult; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineMapSyncTask; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineMapUpdatesInfo; +import com.esri.arcgisruntime.tasks.offlinemap.OfflineUpdateAvailability; +import com.esri.arcgisruntime.tasks.offlinemap.PreplannedScheduledUpdatesOption; + +public class ApplyScheduledUpdatesToPreplannedMapAreaSample extends Application { + + private MapView mapView; + private MobileMapPackage mobileMapPackage; + private OfflineMapSyncTask offlineMapSyncTask; + + @Override + public void start(Stage stage) { + try { + // create stack pane and application scene + StackPane stackPane = new StackPane(); + Scene scene = new Scene(stackPane); + scene.getStylesheets().add(getClass().getResource("/style.css").toExternalForm()); + + // set title, size, and add scene to stage + stage.setTitle("Apply Scheduled Updates to Preplanned Map Area"); + stage.setWidth(800); + stage.setHeight(700); + stage.setScene(scene); + stage.show(); + + // add a map view to the stack pane + mapView = new MapView(); + stackPane.getChildren().add(mapView); + + // create a temporary copy of the local offline map files, so that updating does not overwrite them permanently + File tempMobileMapPackageDirectory = Files.createTempDirectory("canyonlands_offline_map").toFile(); + tempMobileMapPackageDirectory.deleteOnExit(); + File sourceDirectory = new File("./samples-data/canyonlands/"); + FileUtils.copyDirectory(sourceDirectory, tempMobileMapPackageDirectory); + + // load the offline map as a mobile map package + mobileMapPackage = new MobileMapPackage(tempMobileMapPackageDirectory.toString()); + mobileMapPackage.loadAsync(); + mobileMapPackage.addDoneLoadingListener(() -> { + if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mobileMapPackage.getMaps().isEmpty()) { + + // add the map from the mobile map package to the map view + ArcGISMap offlineMap = mobileMapPackage.getMaps().get(0); + mapView.setMap(offlineMap); + + // create an offline map sync task with the preplanned area + offlineMapSyncTask = new OfflineMapSyncTask(offlineMap); + + // check for available updates to the mobile map package + checkForScheduledUpdates(); + + } else { + new Alert(Alert.AlertType.ERROR, "Failed to load the mobile map package.").show(); + } + }); + + } catch (Exception e) { + // on any error, display the stack trace. + e.printStackTrace(); + } + } + + /** + * Checks for scheduled updates to the preplanned map area. + */ + private void checkForScheduledUpdates() { + + // check for updates to the offline map + ListenableFuture offlineMapUpdatesInfoFuture = offlineMapSyncTask.checkForUpdatesAsync(); + offlineMapUpdatesInfoFuture.addDoneListener(() -> { + try { + // get and check the results + OfflineMapUpdatesInfo offlineMapUpdatesInfo = offlineMapUpdatesInfoFuture.get(); + + // update UI for available updates + if (offlineMapUpdatesInfo.getDownloadAvailability() == OfflineUpdateAvailability.AVAILABLE) { + + // get the update size + long updateSize = offlineMapUpdatesInfo.getScheduledUpdatesDownloadSize(); + + // create a dialog to show the update information + Alert alert = new Alert(Alert.AlertType.CONFIRMATION, "Update size: " + updateSize + " bytes. Apply the update?"); + alert.setTitle("Updates Available"); + alert.setHeaderText("An update is available for this preplanned map area."); + + // show the dialog and wait for confirmation + Optional result = alert.showAndWait(); + + // apply the update if the dialog is confirmed + if (result.isPresent() && result.get() == ButtonType.OK) { + applyScheduledUpdates(); + } + + } else { + // show a dialog that no updates are available + Alert alert = new Alert(Alert.AlertType.INFORMATION, "The preplanned map area is up to date."); + alert.setTitle("Up to Date"); + alert.setHeaderText("No updates available."); + alert.show(); + } + + } catch (Exception ex) { + new Alert(Alert.AlertType.ERROR, "Error checking for Scheduled Updates Availability.").show(); + } + }); + } + + /** + * Applies the scheduled updates to the preplanned map area. + */ + private void applyScheduledUpdates() { + + // create default parameters for the sync task + ListenableFuture offlineMapSyncParametersFuture = offlineMapSyncTask.createDefaultOfflineMapSyncParametersAsync(); + offlineMapSyncParametersFuture.addDoneListener(() -> { + try { + OfflineMapSyncParameters offlineMapSyncParameters = offlineMapSyncParametersFuture.get(); + + // set the parameters to download all updates for the mobile map packages + offlineMapSyncParameters.setPreplannedScheduledUpdatesOption(PreplannedScheduledUpdatesOption.DOWNLOAD_ALL_UPDATES); + // set the map package to rollback to the old state should the sync job fail + offlineMapSyncParameters.setRollbackOnFailure(true); + + // create a sync job using the parameters + OfflineMapSyncJob offlineMapSyncJob = offlineMapSyncTask.syncOfflineMap(offlineMapSyncParameters); + + // start the job and get the results + offlineMapSyncJob.start(); + offlineMapSyncJob.addJobDoneListener(() -> { + if (offlineMapSyncJob.getStatus() == Job.Status.SUCCEEDED) { + OfflineMapSyncResult offlineMapSyncResult = offlineMapSyncJob.getResult(); + + // if mobile map package reopen is required, close the existing mobile map package and load it again + if (offlineMapSyncResult.isMobileMapPackageReopenRequired()) { + mobileMapPackage.close(); + mobileMapPackage.loadAsync(); + mobileMapPackage.addDoneLoadingListener(() -> { + if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mobileMapPackage.getMaps().isEmpty()) { + + // add the map from the mobile map package to the map view + mapView.setMap(mobileMapPackage.getMaps().get(0)); + + } else { + new Alert(Alert.AlertType.ERROR, "Failed to load the mobile map package.").show(); + } + }); + } + + // perform another check for updates, to make sure that the newest update was applied + checkForScheduledUpdates(); + + } else { + new Alert(Alert.AlertType.ERROR, "Error syncing the offline map.").show(); + } + + }); + } catch (InterruptedException | ExecutionException ex) { + new Alert(Alert.AlertType.ERROR, "Error creating DefaultOfflineMapSyncParameters").show(); + } + }); + } + + /** + * Stops and releases all resources used in application. + */ + @Override + public void stop() { + + if (mapView != null) { + mapView.dispose(); + } + } + + /** + * Opens and runs application. + * + * @param args arguments passed to this application + */ + public static void main(String[] args) { + + Application.launch(args); + } + +} \ No newline at end of file diff --git a/map/apply-scheduled-updates-to-preplanned-map-area/src/main/resources/style.css b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/resources/style.css new file mode 100644 index 0000000000..3f98729623 --- /dev/null +++ b/map/apply-scheduled-updates-to-preplanned-map-area/src/main/resources/style.css @@ -0,0 +1,3 @@ +.panel-region .label { + -fx-text-fill: white; +} \ No newline at end of file diff --git a/map/download-preplanned-map/gradle/wrapper/gradle-wrapper.jar b/map/download-preplanned-map/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..457aad0d98 Binary files /dev/null and b/map/download-preplanned-map/gradle/wrapper/gradle-wrapper.jar differ