Setting the "extent" of the map? / setting map boundries

582
0
11-20-2019 10:11 AM
CAMPSP
by
New Contributor

I'm attempting to add in boundaries so that a user would be unable to scroll outside of the map's extent, where no map has been generated. (see attached image) This is for an offline map, and yes, it MUST be an offline map - I am currently using an exported .mmpk file with an extent specified, as well as the map and basemap exported into the map package.

I'm currently trying to do this for the ArcGISMap, or MapView object, whichever this applies to, but can't find where to set this parameter, if it exists at all.

private final String MMPKFile = "./src/resources/mapfile.mmpk";     //Basemap and Map included.

private MapView mapView = new MapView();     //com.esri.arcgisruntime.mapping.view

// /.../

MobileMapPackage mapPackage = new MobileMapPackage(MMPKFile);

mapPackage.loadAsync();

mapPackage.addDoneLoadingListener(() -> {
    if (mapPackage.getLoadStatus() == LoadStatus.LOADED && mapPackage.getMaps().size() > 0) {
        ArcGISMap map = mapPackage.getMaps().get(0);
        mapView.setMap(map); //need to set the extent for this map.

    }
});

I have also tried setting the map extent in an Envelope object using the getItem().setExtent(enevlope) method, but it appears this doesn't work, or I am using that method incorrectly.

ArcGISMap map = mapPackage.getMaps().get(0);

Point point1 = new Point(x1, y1);
Point point2 = new Point(x2, y2);
Envelope envelopeExtent = new Envelope(point1, point2);
map.getItem().setExtent(envelopeExtent); //Does not change map limits, throws error.

mapView.setMap(map);

This actually gives me an error saying that Envelope needs a Spatial Reference, but there isn't a method to add just the spatial reference to the Envelope object. There is a constructor method that allows it to be added via:

Envelope(double x1, double y1, double x2, double y2, SpatialReference spatialReference)

But this doesn't work either.

The documentation here [Map extent | ArcGIS for Developers] seems to be out of date, and no "com.esri.map" package exists in the JDK that is available for download.

I've tried google and searching the docs and help pages but haven't found anything, or anything that clearly defines this type of function. Help is appreciated.

0 Kudos
0 Replies