Java源码示例:com.esri.arcgisruntime.mapping.MobileMapPackage

示例1
/**
 * Loads a mobile map package and map previews.
 *
 * @param path to location of mobile map package on device
 */
private void loadMobileMapPackage(String path) {
  // create the mobile map package
  mMobileMapPackage = new MobileMapPackage(path);
  // load the mobile map package asynchronously
  mMobileMapPackage.loadAsync();
  // add done listener which will load when package has maps
  mMobileMapPackage.addDoneLoadingListener(() -> {
    // check load status and that the mobile map package has maps
    if (mMobileMapPackage.getLoadStatus() == LoadStatus.LOADED && !mMobileMapPackage.getMaps().isEmpty()) {
      mLocatorTask = mMobileMapPackage.getLocatorTask();
      // default to display of first map in package
      loadMap(0);
      loadMapPreviews();
    } else {
      String error = "Mobile map package failed to load: " + mMobileMapPackage.getLoadError().getMessage();
      Log.e(TAG, error);
      Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
  });
}
 
示例2
@Override
public void start(Stage stage) {

  try {
    // create stack pane and application scene
    StackPane stackPane = new StackPane();
    Scene scene = new Scene(stackPane);

    // set title, size, and add scene to stage
    stage.setTitle("Open Mobile Map Package Sample");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.setScene(scene);
    stage.show();

    // create a map view
    mapView = new MapView();

    //load a mobile map package
    final String mmpkPath = new File(System.getProperty("data.dir"), "./samples-data/mmpk/Yellowstone.mmpk").getAbsolutePath();
    mobileMapPackage = new MobileMapPackage(mmpkPath);

    mobileMapPackage.loadAsync();
    mobileMapPackage.addDoneLoadingListener(() -> {
      if (mobileMapPackage.getLoadStatus() == LoadStatus.LOADED && mobileMapPackage.getMaps().size() > 0) {
        //add the map from the mobile map package to the map view
        mapView.setMap(mobileMapPackage.getMaps().get(0));
      } else {
        Alert alert = new Alert(Alert.AlertType.ERROR, "Failed to load the mobile map package");
        alert.show();
      }
    });

    // add the map view to stack pane
    stackPane.getChildren().add(mapView);
  } catch (Exception e) {
    // on any error, display the stack trace.
    e.printStackTrace();
  }
}
 
示例3
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get a reference to the map view
  mMapView = findViewById(R.id.mapView);

  //[DocRef: Name=Open Mobile Map Package-android, Category=Work with maps, Topic=Create an offline map]
  // create the mobile map package
  mMapPackage = new MobileMapPackage(getExternalFilesDir(null) + getString(R.string.yellowstone_mmpk));
  // load the mobile map package asynchronously
  mMapPackage.loadAsync();

  // add done listener which will invoke when mobile map package has loaded
  mMapPackage.addDoneLoadingListener(() -> {
    // check load status and that the mobile map package has maps
    if (mMapPackage.getLoadStatus() == LoadStatus.LOADED && !mMapPackage.getMaps().isEmpty()) {
      // add the map from the mobile map package to the MapView
      mMapView.setMap(mMapPackage.getMaps().get(0));
    } else {
      String error = "Error loading mobile map package: " + mMapPackage.getLoadError().getMessage();
      Log.e(TAG, error);
      Toast.makeText(this, error, Toast.LENGTH_SHORT).show();
    }
  });
  //[DocRef: END]
}
 
示例4
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get a reference to the map view
  mMapView = findViewById(R.id.mapView);

  // get a reference to the expiration text view
  mExpirationMessageTextView = findViewById(R.id.expirationMessageTextView);

  // create a mobile map package from a local mmpk
  mMobileMapPackage = new MobileMapPackage(getExternalFilesDir(null) + getString(R.string.path_to_expired_mmpk));

  // wait for the map package to load
  mMobileMapPackage.addDoneLoadingListener(() -> {
    // check if the map package has expiration information and if so, has it expired yet
    if (mMobileMapPackage.getExpiration() != null && mMobileMapPackage.getExpiration().isExpired()) {
      // define a format for the date
      SimpleDateFormat daysHoursFormat = new SimpleDateFormat("yyyy-MM-dd' at 'hh:mm:ss", Locale.US);
      // show the expiration text view
      mExpirationMessageTextView.setVisibility(View.VISIBLE);
      // set the expiration message and expiration date to the text view
      mExpirationMessageTextView.setText(getString(R.string.expiration_text,
          mMobileMapPackage.getExpiration().getMessage(),
          daysHoursFormat.format(mMobileMapPackage.getExpiration().getDateTime().getTime())));
      if (mMobileMapPackage.getExpiration().getType() == ExpirationType.ALLOW_EXPIRED_ACCESS) {
        // add the map to the map view
        mMapView.setMap(mMobileMapPackage.getMaps().get(0));
      } else if (mMobileMapPackage.getExpiration().getType() == ExpirationType.PREVENT_EXPIRED_ACCESS) {
        Toast.makeText(this, "The author of this mobile map package has disallowed access after the expiration date.",
            Toast.LENGTH_LONG).show();
      }
    }
  });
  mMobileMapPackage.loadAsync();
}
 
示例5
@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(
            "/apply_scheduled_updates_to_preplanned_map_area/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
    tempMobileMapPackageDirectory = Files.createTempDirectory("canyonlands_offline_map").toFile();
    tempMobileMapPackageDirectory.deleteOnExit();
    File sourceDirectory = new File(System.getProperty("data.dir"), "./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();
  }
}
 
示例6
@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("/honor_mobile_map_package_expiration_date/style.css").toExternalForm());

    // set title, size, and add scene to stage
    stage.setTitle("Honor Mobile Map Package Expiration Date Sample");
    stage.setWidth(800);
    stage.setHeight(700);
    stage.setScene(scene);
    stage.show();

    // create an overlay to display the expiration information
    VBox expirationMessageVbox = new VBox(6);
    expirationMessageVbox.setBackground(new Background(new BackgroundFill(Paint.valueOf("rgba(0,0,0,0.3)"), CornerRadii.EMPTY,
            Insets.EMPTY)));
    expirationMessageVbox.setPadding(new Insets(10.0));
    expirationMessageVbox.setMaxSize(800, 150);
    expirationMessageVbox.setAlignment(Pos.CENTER);
    expirationMessageVbox.getStyleClass().add("panel-region");

    // create a label to display the expiration message and expiration date
    Label expirationDetailsLabel = new Label();
    expirationMessageVbox.getStyleClass().add("label");

    // add the labels to the overlay
    expirationMessageVbox.getChildren().add(expirationDetailsLabel);

    // create a map view
    mapView = new MapView();

    // load the mobile map package
    File mmpkFile = new File(System.getProperty("data.dir"), "./samples-data/mmpk/LothianRiversAnno.mmpk");
    mobileMapPackage = new MobileMapPackage(mmpkFile.getAbsolutePath());
    mobileMapPackage.loadAsync();
    mobileMapPackage.addDoneLoadingListener(() -> {
      // check if the map package has expiration information and if so, has it expired yet
      if (mobileMapPackage.getExpiration() != null && mobileMapPackage.getExpiration().isExpired()) {

        // get the expiration of the mobile map package
        Expiration expiration = mobileMapPackage.getExpiration();

        // get the expiration message
        String expirationMessage = expiration.getMessage();

        // get the expiration date
        SimpleDateFormat daysHoursFormat = new SimpleDateFormat("EEE',' d MMM yyyy 'at' hh:mm:ss a", Locale.US);
        String expirationDate = daysHoursFormat.format(expiration.getDateTime().getTimeInMillis());

        // set the expiration message to the label
        expirationDetailsLabel.setText(expirationMessage + "\n Mobile map package expired on: " + expirationDate + ".");

        // load the expired map if it is still accessible after expiration
        if (mobileMapPackage.getExpiration().getType() == ExpirationType.ALLOW_EXPIRED_ACCESS && 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));

          // show an alert if the mobile map package is not accessible after expiration
        } else if (mobileMapPackage.getExpiration().getType() == ExpirationType.PREVENT_EXPIRED_ACCESS) {
          new Alert(Alert.AlertType.ERROR, "The author of this mobile map package has disallowed access after the expiration date.").show();
        }

        // show the map if it is not expired
      } else 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();
      }
    });

    // add the map view and overlay to the stack pane
    stackPane.getChildren().addAll(mapView, expirationMessageVbox);
    StackPane.setAlignment(expirationMessageVbox, Pos.CENTER);

  } catch (Exception e) {
    // on any error, display the stack trace
    e.printStackTrace();
  }
}
 
示例7
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get a reference to the map view
  mMapView = findViewById(R.id.mapView);

  // show current map scale in a text view at the bottom of the screen
  TextView currentMapScaleTextView = findViewById(R.id.mapScale);
  mMapView.addMapScaleChangedListener(mapScaleChangedEvent -> currentMapScaleTextView
      .setText(getString(R.string.map_scale, Math.round(mMapView.getMapScale()))));

  // get a reference to checkboxes
  CheckBox closedCheckBox = findViewById(R.id.closedCheckBox);
  CheckBox openCheckBox = findViewById(R.id.openCheckBox);

  // load the mobile map package
  mMobileMapPackage = new MobileMapPackage(getExternalFilesDir(null) + getString(R.string.gas_device_anno_mmpk_path));
  mMobileMapPackage.loadAsync();
  mMobileMapPackage.addDoneLoadingListener(() -> {
    if (mMobileMapPackage.getLoadStatus() == LoadStatus.LOADED) {
      // set the mobile map package's map to the map view
      mMapView.setMap(mMobileMapPackage.getMaps().get(0));
      // find the annotation layer within the map
      for (Layer layer : mMapView.getMap().getOperationalLayers()) {
        if (layer instanceof AnnotationLayer) {
          // load the annotation layer. The layer must be loaded in order to access sub-layer contents
          layer.loadAsync();
          layer.addDoneLoadingListener(() -> {
            // get annotation sublayer name from sublayer contents
            AnnotationSublayer closedLayer = (AnnotationSublayer) layer.getSubLayerContents().get(0);
            AnnotationSublayer openLayer = (AnnotationSublayer) layer.getSubLayerContents().get(1);

            // set the layer name from the
            closedCheckBox.setText(buildLayerName(closedLayer));
            openCheckBox.setText(buildLayerName(openLayer));

            // toggle annotation sublayer visibility on check
            closedCheckBox.setOnCheckedChangeListener(
                (checkBoxView, isChecked) -> closedLayer.setVisible(isChecked));
            openCheckBox.setOnCheckedChangeListener(
                (checkBoxView, isChecked) -> openLayer.setVisible(isChecked));

            // when the map scale changes
            mMapView.addMapScaleChangedListener(mapScaleChangedEvent -> {
              // if the "open" layer is visible, set text color to black, otherwise set it to gray
              if (openLayer.isVisibleAtScale(mMapView.getMapScale())) {
                openCheckBox.setTextColor(Color.BLACK);
              } else {
                openCheckBox.setTextColor(Color.LTGRAY);
              }
            });

          });
        }
      }
    } else {
      String error = "Mobile map package failed load: " + mMobileMapPackage.getLoadError().getMessage();
      Toast.makeText(this, error, Toast.LENGTH_LONG).show();
      Log.e(TAG, error);
    }
  });
}
 
示例8
/**
 * Sets up a map by opening a mobile map package, getting the first map, adding a tile package as a basemap layer, and
 * and setting the map into the MapView in the layout. Then calls functions to set up geocoding and routing tasks
 * using same mmpk.
 */
private void setupOfflineMap() {
  // Create an MMPK from the specified file.
  final String mmpkPath = getMmpkPath();
  if (TextUtils.isEmpty(mmpkPath)) {
    return;
  }
  mMobileMapPackage = new MobileMapPackage(mmpkPath);

  // Load MMPK - When MMPK is loaded the Maps and other content should be accessible.
  mMobileMapPackage.addDoneLoadingListener(new Runnable() {

    @Override
    public void run() {

      if (mMobileMapPackage.getLoadStatus() != LoadStatus.LOADED) {
        Snackbar.make(mMapView, String.format(getString(R.string.object_not_loaded), "MMPK"),
            Snackbar.LENGTH_SHORT).show();
        return;
      }

      // Get the first map.
      if (mMobileMapPackage.getMaps().size() == 0) {
        Snackbar.make(mMapView, String.format(getString(R.string.no_maps_in_mmpk), mmpkPath),
            Snackbar.LENGTH_SHORT).show();
        return;
      }

      mMap = mMobileMapPackage.getMaps().get(0);

      // Set a Basemap from a raster tile cache package
      String tpkPath = getTpkPath();
      if (TextUtils.isEmpty(tpkPath)) {
        return;
      }
      TileCache tileCache = new TileCache(getTpkPath());
      final ArcGISTiledLayer tiledLayer = new ArcGISTiledLayer(tileCache);
      mMap.setBasemap(new Basemap(tiledLayer));

      // No need to explicitly load the map, just set it into the MapView; that will trigger loading when displayed.
      mMapView.setMap(mMap);
      mMap.addDoneLoadingListener(new Runnable() {
        @Override
        public void run() {

          if (mMobileMapPackage.getLoadStatus() != LoadStatus.LOADED) {
            Snackbar.make(mMapView, String.format(getString(R.string.object_not_loaded), "Map"),
                Snackbar.LENGTH_SHORT).show();
            return;
          }

          mMapView.setViewpointGeometryAsync(tiledLayer.getFullExtent());

          setUpOfflineMapGeocoding();
          setupOfflineNetwork();
          setupSearchView();

          mMap.removeDoneLoadingListener(this);
        }
      });
    }
  });

  // Load the MMPK.
  mMobileMapPackage.loadAsync();
}