com.esri.arcgisruntime.mapping.view.GraphicsOverlay Java Examples

The following examples show how to use com.esri.arcgisruntime.mapping.view.GraphicsOverlay. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RNAGSMapView.java    From react-native-arcgis-mapview with MIT License 7 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
public void setUpMap() {
    mapView.setMap(new ArcGISMap(Basemap.Type.STREETS_VECTOR, 34.057, -117.196, 17));
    mapView.setOnTouchListener(new OnSingleTouchListener(getContext(),mapView));
    routeGraphicsOverlay = new GraphicsOverlay();
    mapView.getGraphicsOverlays().add(routeGraphicsOverlay);
    mapView.getMap().addDoneLoadingListener(() -> {
        ArcGISRuntimeException e = mapView.getMap().getLoadError();
        Boolean success = e != null;
        String errorMessage = !success ? "" : e.getMessage();
        WritableMap map = Arguments.createMap();
        map.putBoolean("success",success);
        map.putString("errorMessage",errorMessage);

        emitEvent("onMapDidLoad",map);
    });
}
 
Example #2
Source File: RNAGSRouter.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
public ListenableFuture<RouteResult> createRoute(@NonNull GraphicsOverlay graphicsOverlay, @Nullable ArrayList<String> excludeGraphics) {
    // Clear stops
    if (routeParameters == null) {
        Log.w("WARNING (AGS)", "It looks like the Esri Routing service is down, or you did not provide valid credentials. Please try again later, or submit an issue.");
        return null;
    }
    routeParameters.clearStops();
    // I know this is deprecated but it just works ._. setStops does not work... good job, Esri
    // See https://developers.arcgis.com/android/latest/api-reference/reference/com/esri/arcgisruntime/tasks/networkanalysis/RouteParameters.html
    List<Stop> stops = routeParameters.getStops();
    for (Graphic item : graphicsOverlay.getGraphics()) {
        String referenceId = ((String) item.getAttributes().get("referenceId"));
        if (excludeGraphics == null || !(excludeGraphics.contains(referenceId))) {
            // Reform the point with spatial reference
            Point point = ((Point) item.getGeometry());
            stops.add(new Stop(point));
        }
    }
    routeParameters.setOutputSpatialReference(SpatialReferences.getWgs84());
    return routeTask.solveRouteAsync(routeParameters);
}
 
Example #3
Source File: RNAGSGraphicsOverlay.java    From react-native-arcgis-mapview with MIT License 6 votes vote down vote up
public RNAGSGraphicsOverlay(ReadableMap rawData, GraphicsOverlay graphicsOverlay) {
    this.referenceId = rawData.getString("referenceId");
    ReadableArray pointImageDictionaryRaw = rawData.getArray("pointGraphics");
    pointImageDictionary = new HashMap<>();
    this.graphicsOverlay = graphicsOverlay;

    for (int i = 0; i < pointImageDictionaryRaw.size(); i++) {
        ReadableMap item = pointImageDictionaryRaw.getMap(i);
        if (item.hasKey("graphicId")) {
            String graphicId = item.getString("graphicId");
            String uri = item.getMap("graphic").getString("uri");
            pointImageDictionary.put(graphicId, uri);
        }
    }
    // Create graphics within overlay
    ReadableArray rawPoints = rawData.getArray("points");
    for (int i = 0; i < rawPoints.size(); i++) {
        addGraphicsLoop(rawPoints.getMap(i));

    }
}
 
Example #4
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // inflate MapView from layout
  mMapView = (MapView) findViewById(R.id.mapView);
  // create a map with the BasemapType topographic
  ArcGISMap map = new ArcGISMap(Basemap.Type.OCEANS, 56.075844, -2.681572, 11);
  // set the map to be displayed in this view
  mMapView.setMap(map);
  // add graphics overlay to MapView.
  GraphicsOverlay graphicsOverlay = addGraphicsOverlay(mMapView);
  //add some buoy positions to the graphics overlay
  addBuoyPoints(graphicsOverlay);
  //add boat trip polyline to graphics overlay
  addBoatTrip(graphicsOverlay);
  //add nesting ground polygon to graphics overlay
  addNestingGround(graphicsOverlay);
  //add text symbols and points to graphics overlay
  addText(graphicsOverlay);
}
 
Example #5
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
/**
 * Queries the sublayer's feature table with the query parameters and displays the result features as graphics
 *
 * @param sublayer        - type of sublayer to query from
 * @param sublayerSymbol  - symbol to display on map
 * @param query           - filters based on the population and the current view point
 * @param graphicsOverlay - manages the graphics that will be added to the map view
 */
private static void QueryAndDisplayGraphics(ArcGISMapImageSublayer sublayer, Symbol sublayerSymbol, QueryParameters query,
    GraphicsOverlay graphicsOverlay) {
  if (sublayer.getLoadStatus() == LoadStatus.LOADED) {
    ServiceFeatureTable sublayerTable = sublayer.getTable();
    ListenableFuture<FeatureQueryResult> sublayerQuery = sublayerTable.queryFeaturesAsync(query);
    sublayerQuery.addDoneListener(() -> {
      try {
        FeatureQueryResult result = sublayerQuery.get();
        for (Feature feature : result) {
          Graphic sublayerGraphic = new Graphic(feature.getGeometry(), sublayerSymbol);
          graphicsOverlay.getGraphics().add(sublayerGraphic);
        }
      } catch (InterruptedException | ExecutionException e) {
        Log.e(MainActivity.class.getSimpleName(), e.toString());
      }
    });
  }
}
 
Example #6
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
private void addGraphicsOverlay() {
    // create the polygon
    PolygonBuilder polygonGeometry = new PolygonBuilder(SpatialReferences.getWebMercator());
    polygonGeometry.addPoint(-20e5, 20e5);
    polygonGeometry.addPoint(20e5, 20.e5);
    polygonGeometry.addPoint(20e5, -20e5);
    polygonGeometry.addPoint(-20e5, -20e5);

    // create solid line symbol
    SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, null);
    // create graphic from polygon geometry and symbol
    Graphic graphic = new Graphic(polygonGeometry.toGeometry(), polygonSymbol);

    // create graphics overlay
    grOverlay = new GraphicsOverlay();
    // create list of graphics
    ListenableList<Graphic> graphics = grOverlay.getGraphics();
    // add graphic to graphics overlay
    graphics.add(graphic);
    // add graphics overlay to the MapView
    mMapView.getGraphicsOverlays().add(grOverlay);
}
 
Example #7
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
private void addBuoyPoints(GraphicsOverlay graphicOverlay) {
  //define the buoy locations
  Point buoy1Loc = new Point(-2.712642647560347, 56.062812566811544, wgs84);
  Point buoy2Loc = new Point(-2.6908416959572303, 56.06444173689877, wgs84);
  Point buoy3Loc = new Point(-2.6697273884990937, 56.064250073402874, wgs84);
  Point buoy4Loc = new Point(-2.6395150461199726, 56.06127916736989, wgs84);
  //create a marker symbol
  SimpleMarkerSymbol buoyMarker = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED, 10);
  //create graphics
  Graphic buoyGraphic1 = new Graphic(buoy1Loc, buoyMarker);
  Graphic buoyGraphic2 = new Graphic(buoy2Loc, buoyMarker);
  Graphic buoyGraphic3 = new Graphic(buoy3Loc, buoyMarker);
  Graphic buoyGraphic4 = new Graphic(buoy4Loc, buoyMarker);
  //add the graphics to the graphics overlay
  graphicOverlay.getGraphics().add(buoyGraphic1);
  graphicOverlay.getGraphics().add(buoyGraphic2);
  graphicOverlay.getGraphics().add(buoyGraphic3);
  graphicOverlay.getGraphics().add(buoyGraphic4);
}
 
Example #8
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
private void addText(GraphicsOverlay graphicOverlay) {
  //create a point geometry
  Point bassLocation = new Point(-2.640631, 56.078083, wgs84);
  Point craigleithLocation = new Point(-2.720324, 56.073569, wgs84);

  //create text symbols
  TextSymbol bassRockSymbol =
      new TextSymbol(10, "Bass Rock", Color.rgb(0, 0, 230),
          TextSymbol.HorizontalAlignment.LEFT, TextSymbol.VerticalAlignment.BOTTOM);
  TextSymbol craigleithSymbol = new TextSymbol(10, "Craigleith", Color.rgb(0, 0, 230),
      TextSymbol.HorizontalAlignment.RIGHT, TextSymbol.VerticalAlignment.TOP);

  //define a graphic from the geometry and symbol
  Graphic bassRockGraphic = new Graphic(bassLocation, bassRockSymbol);
  Graphic craigleithGraphic = new Graphic(craigleithLocation, craigleithSymbol);
  //add the text to the graphics overlay
  graphicOverlay.getGraphics().add(bassRockGraphic);
  graphicOverlay.getGraphics().add(craigleithGraphic);
}
 
Example #9
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add the given point to the list of service areas and use it to create a facility graphic, which is then added to
 * the facility overlay.
 */
private void addServicePoint(Point mapPoint, PictureMarkerSymbol facilitySymbol,
    List<ServiceAreaFacility> serviceAreaFacilities, GraphicsOverlay facilityOverlay) {
  Point servicePoint = new Point(mapPoint.getX(), mapPoint.getY(), mMapView.getSpatialReference());
  serviceAreaFacilities.add(new ServiceAreaFacility(servicePoint));
  facilityOverlay.getGraphics().add(new Graphic(servicePoint, facilitySymbol));
}
 
Example #10
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
private GraphicsOverlay addGraphicsOverlay(MapView mapView) {
  //create the graphics overlay
  GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
  //add the overlay to the map view
  mapView.getGraphicsOverlays().add(graphicsOverlay);
  return graphicsOverlay;
}
 
Example #11
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get the reference to the map view
  mMapView = findViewById(R.id.mapView);
  ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
  mMapView.setMap(map);

  // once graphics overlay had loaded with a valid spatial reference, set the viewpoint to the graphics overlay extent
  mMapView.addSpatialReferenceChangedListener(spatialReferenceChangedEvent -> mMapView
      .setViewpointGeometryAsync(mMapView.getGraphicsOverlays().get(0).getExtent()));

  GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
  // graphics no longer show after zooming passed this scale
  graphicsOverlay.setMinScale(1000000);
  mMapView.getGraphicsOverlays().add(graphicsOverlay);

  // create symbol dictionary from specification
  DictionarySymbolStyle symbolDictionary = DictionarySymbolStyle
      .createFromFile(getExternalFilesDir(null) + getString(R.string.mil2525d_stylx));

  // tells graphics overlay how to render graphics with symbol dictionary attributes set
  DictionaryRenderer renderer = new DictionaryRenderer(symbolDictionary);
  graphicsOverlay.setRenderer(renderer);

  // parse graphic attributes from a XML file
  List<Map<String, Object>> messages = parseMessages();

  // create graphics with attributes and add to graphics overlay
  for (Map<String, Object> attributes : messages) {
    graphicsOverlay.getGraphics().add(createGraphic(attributes));
  }
}
 
Example #12
Source File: ReadSymbolsFromMobileStyleFileController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
@FXML
public void initialize() {

  // create a map
  ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
  // add the map to the map view
  mapView.setMap(map);

  // create a graphics overlay and add it to the map
  graphicsOverlay = new GraphicsOverlay();
  mapView.getGraphicsOverlays().add(graphicsOverlay);

  // load the available symbols from the style file
  loadSymbolsFromStyleFile();

  // create a listener that builds the composite symbol when an item from the list view is selected
  ChangeListener<Object> changeListener = (obs, oldValue, newValue) -> buildCompositeSymbol();

  // create a list of the ListView objects and iterate over it
  List<ListView<SymbolStyleSearchResult>> listViews = Arrays.asList(hatSelectionListView, eyesSelectionListView, mouthSelectionListView);
  for (ListView<SymbolStyleSearchResult> listView : listViews) {
    // add the cell factory to show the symbol within the list view
    listView.setCellFactory(c -> new SymbolLayerInfoListCell());
    // add the change listener to rebuild the preview when a selection is made
    listView.getSelectionModel().selectedItemProperty().addListener(changeListener);
    // add an empty entry to the list view to allow selecting 'nothing', and make it selected by default
    listView.getItems().add(null);
    listView.getSelectionModel().select(0);
  }
}
 
Example #13
Source File: ScenePropertiesExpressionsController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
public void initialize() {

    // create a scene and add a basemap to it
    ArcGISScene scene = new ArcGISScene();
    scene.setBasemap(Basemap.createImagery());

    // add the SceneView to the stack pane
    sceneView.setArcGISScene(scene);

    // add a camera and initial camera position
    Point point = new Point(83.9, 28.4, 1000, SpatialReferences.getWgs84());
    Camera camera = new Camera(point, 1000, 0, 50, 0);
    sceneView.setViewpointCamera(camera);

    // create a graphics overlay
    GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
    graphicsOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.RELATIVE);
    sceneView.getGraphicsOverlays().add(graphicsOverlay);

    // add renderer using rotation expressions
    SimpleRenderer renderer = new SimpleRenderer();
    renderer.getSceneProperties().setHeadingExpression("[HEADING]");
    renderer.getSceneProperties().setPitchExpression("[PITCH]");
    graphicsOverlay.setRenderer(renderer);

    // create a red (0xFFFF0000) cone graphic
    SimpleMarkerSceneSymbol coneSymbol = SimpleMarkerSceneSymbol.createCone(0xFFFF0000, 100, 100);
    coneSymbol.setPitch(-90);  // correct symbol's default pitch
    Graphic cone = new Graphic(new Point(83.9, 28.41, 200, SpatialReferences.getWgs84()), coneSymbol);
    graphicsOverlay.getGraphics().add(cone);

    // bind attribute values to sliders
    headingSlider.valueProperty().addListener(o -> cone.getAttributes().put("HEADING", headingSlider.getValue()));
    pitchSlider.valueProperty().addListener(o -> cone.getAttributes().put("PITCH", pitchSlider.getValue()));
  }
 
Example #14
Source File: Draw.java    From ArcgisTool with Apache License 2.0 5 votes vote down vote up
private void removeAllGraphics(List<GraphicsOverlay> go){
    if(go.size()>0){
        for(GraphicsOverlay graphics:go){
            mapView.getGraphicsOverlays().remove(graphics);
        }
    }
}
 
Example #15
Source File: GenerateOfflineMapOverridesController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
@FXML
private void initialize() {
  // handle authentication with the portal
  AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler());

  // create a portal item with the itemId of the web map
  Portal portal = new Portal("https://www.arcgis.com", true);
  PortalItem portalItem = new PortalItem(portal, "acc027394bc84c2fb04d1ed317aac674");

  // create a map with the portal item
  map = new ArcGISMap(portalItem);
  map.addDoneLoadingListener(() -> {
    // enable the generate offline map button when the map is loaded
    if (map.getLoadStatus() == LoadStatus.LOADED) {
      generateOfflineMapButton.setDisable(false);

      // create a graphics overlay for displaying the download area
      graphicsOverlay = new GraphicsOverlay();
      mapView.getGraphicsOverlays().add(graphicsOverlay);

      // show a red border around the download area
      downloadArea = new Graphic();
      graphicsOverlay.getGraphics().add(downloadArea);
      SimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFFFF0000, 2);
      downloadArea.setSymbol(simpleLineSymbol);

      updateDownloadArea();
    }
  });

  // update the download area whenever the viewpoint changes
  mapView.addViewpointChangedListener(viewpointChangedEvent -> updateDownloadArea());

  // set the map to the map view
  mapView.setMap(map);
}
 
Example #16
Source File: ArrayHelper.java    From react-native-arcgis-mapview with MIT License 5 votes vote down vote up
public static Graphic graphicViaReferenceId(GraphicsOverlay graphicsOverlay, String referenceId) {
    List<Graphic> list = graphicsOverlay.getGraphics();
    for (Graphic item : list) {
        String referenceIdFromGraphic = ((String) item.getAttributes().get("referenceId"));
        if (referenceIdFromGraphic != null && referenceIdFromGraphic.equals(referenceId))
            return item;
    }
    return null;
}
 
Example #17
Source File: DrawEntity.java    From ArcgisTool with Apache License 2.0 5 votes vote down vote up
public DrawEntity(List<GraphicsOverlay> textGraphic, List<GraphicsOverlay> polygonGraphic, List<GraphicsOverlay> lineGraphic, List<GraphicsOverlay> pointGraphic, List<List<Point>> pointGroup) {
    this.textGraphic = textGraphic;
    this.polygonGraphic = polygonGraphic;
    this.lineGraphic = lineGraphic;
    this.pointGraphic = pointGraphic;
    this.pointGroup = pointGroup;
}
 
Example #18
Source File: SketchOnMapController.java    From arcgis-runtime-samples-java with Apache License 2.0 5 votes vote down vote up
public void initialize() {

    // create a map with a basemap and add it to the map view
    ArcGISMap map = new ArcGISMap(Basemap.Type.IMAGERY, 64.3286, -15.5314, 13);
    mapView.setMap(map);

    // create a graphics overlay for the graphics
    graphicsOverlay = new GraphicsOverlay();

    // add the graphics overlay to the map view
    mapView.getGraphicsOverlays().add(graphicsOverlay);

    // create a new sketch editor and add it to the map view
    sketchEditor = new SketchEditor();
    mapView.setSketchEditor(sketchEditor);

    // red square for points
    pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.SQUARE, 0xFFFF0000, 20);
    // thin green line for polylines
    lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF64c113, 4);
    // blue outline for polygons
    SimpleLineSymbol polygonLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF1396c1, 4);
    // cross-hatched interior for polygons
    fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.CROSS, 0x40FFA9A9, polygonLineSymbol);

    // add a listener for when sketch geometry is changed
    sketchEditor.addGeometryChangedListener(SketchGeometryChangedListener -> {
      stopButton.setDisable(false);
      // save button enable depends on if the sketch is valid. If the sketch is valid then set disable opposite of true
      saveButton.setDisable(!sketchEditor.isSketchValid());
      undoButton.setDisable(!sketchEditor.canUndo());
      redoButton.setDisable(!sketchEditor.canUndo());
    });
  }
 
Example #19
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
/**
 * Clears all graphics from map view and clears all facilities and barriers from service area parameters.
 */
private void clearRouteAndGraphics(Button addFacilityButton, Button addBarrierButton,
    List<ServiceAreaFacility> serviceAreaFacilities, GraphicsOverlay facilityOverlay,
    GraphicsOverlay serviceAreasOverlay, GraphicsOverlay barrierOverlay) {
  addFacilityButton.setSelected(false);
  addBarrierButton.setSelected(false);
  mServiceAreaParameters.clearFacilities();
  mServiceAreaParameters.clearPolylineBarriers();
  serviceAreaFacilities.clear();
  facilityOverlay.getGraphics().clear();
  serviceAreasOverlay.getGraphics().clear();
  barrierOverlay.getGraphics().clear();
}
 
Example #20
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // define symbols
  mPointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.SQUARE, 0xFFFF0000, 20);
  mLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFFFF8800, 4);
  mFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.CROSS, 0x40FFA9A9, mLineSymbol);

  // inflate map view from layout
  mMapView = findViewById(R.id.mapView);
  // create a map with the Basemap Type topographic
  ArcGISMap map = new ArcGISMap(Basemap.Type.LIGHT_GRAY_CANVAS, 34.056295, -117.195800, 16);
  // set the map to be displayed in this view
  mMapView.setMap(map);

  mGraphicsOverlay = new GraphicsOverlay();
  mMapView.getGraphicsOverlays().add(mGraphicsOverlay);

  // create a new sketch editor and add it to the map view
  mSketchEditor = new SketchEditor();
  mMapView.setSketchEditor(mSketchEditor);

  // get buttons from layouts
  mPointButton = findViewById(R.id.pointButton);
  mMultiPointButton = findViewById(R.id.pointsButton);
  mPolylineButton = findViewById(R.id.polylineButton);
  mPolygonButton = findViewById(R.id.polygonButton);
  mFreehandLineButton = findViewById(R.id.freehandLineButton);
  mFreehandPolygonButton = findViewById(R.id.freehandPolygonButton);

  // add click listeners
  mPointButton.setOnClickListener(view -> createModePoint());
  mMultiPointButton.setOnClickListener(view -> createModeMultipoint());
  mPolylineButton.setOnClickListener(view -> createModePolyline());
  mPolygonButton.setOnClickListener(view -> createModePolygon());
  mFreehandLineButton.setOnClickListener(view -> createModeFreehandLine());
  mFreehandPolygonButton.setOnClickListener(view -> createModeFreehandPolygon());
}
 
Example #21
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
private void addBoatTrip(GraphicsOverlay graphicOverlay) {
  //define a polyline for the boat trip
  Polyline boatRoute = getBoatTripGeometry();
  //define a line symbol
  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(128, 0, 128), 4);
  //create the graphic
  Graphic boatTripGraphic = new Graphic(boatRoute, lineSymbol);
  //add to the graphic overlay
  graphicOverlay.getGraphics().add(boatTripGraphic);
}
 
Example #22
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
private void addNestingGround(GraphicsOverlay graphicOverlay) {
  //define the polygon for the nesting ground
  Polygon nestingGround = getNestingGroundGeometry();
  //define the fill symbol and outline
  SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, Color.rgb(0, 0, 128), 1);
  SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.DIAGONAL_CROSS, Color.rgb(0, 80, 0),
      outlineSymbol);
  //define graphic
  Graphic nestingGraphic = new Graphic(nestingGround, fillSymbol);
  //add to graphics overlay
  graphicOverlay.getGraphics().add(nestingGraphic);
}
 
Example #23
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  // initialize reverse geocode params
  mReverseGeocodeParameters = new ReverseGeocodeParameters();
  mReverseGeocodeParameters.setMaxResults(1);
  mReverseGeocodeParameters.getResultAttributeNames().add("*");
  // retrieve the MapView from layout
  mMapView = (MapView) findViewById(R.id.mapView);
  // add route and marker overlays to map view
  mMarkerGraphicsOverlay = new GraphicsOverlay();
  mRouteGraphicsOverlay = new GraphicsOverlay();
  mMapView.getGraphicsOverlays().add(mRouteGraphicsOverlay);
  mMapView.getGraphicsOverlays().add(mMarkerGraphicsOverlay);
  // add the map from the mobile map package to the MapView
  loadMobileMapPackage(getExternalFilesDir(null) + getString(R.string.san_francisco_mmpk));
  mMapView.setOnTouchListener(new DefaultMapViewOnTouchListener(this, mMapView) {

    @Override
    public boolean onSingleTapConfirmed(MotionEvent motionEvent) {
      // get the point that was clicked and convert it to a point in map coordinates
      android.graphics.Point screenPoint = new android.graphics.Point(Math.round(motionEvent.getX()), Math.round(motionEvent.getY()));
      // create a map point from screen point
      Point mapPoint = mMapView.screenToLocation(screenPoint);
      geoView(screenPoint, mapPoint);
      return true;
    }
  });
}
 
Example #24
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // inflate MapView from layout
  mMapView = (MapView) findViewById(R.id.mapView);

  // create a map with the imagery basemap
  ArcGISMap map = new ArcGISMap(Basemap.createImagery());

  // create an initial viewpoint with a point and scale
  Point point = new Point(-226773, 6550477, SpatialReferences.getWebMercator());
  Viewpoint vp = new Viewpoint(point, 7500);

  // set initial map extent
  map.setInitialViewpoint(vp);

  // set the map to be displayed in the mapview
  mMapView.setMap(map);

  // create a new graphics overlay and add it to the mapview
  GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
  mMapView.getGraphicsOverlays().add(graphicsOverlay);

  //[DocRef: Name=Point graphic with symbol, Category=Fundamentals, Topic=Symbols and Renderers]
  //create a simple marker symbol
  SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.RED,
      12); //size 12, style of circle

  //add a new graphic with a new point geometry
  Point graphicPoint = new Point(-226773, 6550477, SpatialReferences.getWebMercator());
  Graphic graphic = new Graphic(graphicPoint, symbol);
  graphicsOverlay.getGraphics().add(graphic);
  //[DocRef: END]

}
 
Example #25
Source File: ResponderAppController.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
public void initialize() {
  // create a basemap from local data (a tile package)
  TileCache tileCache = new TileCache(tilePackageFilePath); // "/data/tiled
                                                            // packages/RedlandsBasemap.tpk"
  Basemap offlineBasemap = new Basemap(new ArcGISTiledLayer(tileCache));

  // create a map
  map = new ArcGISMap(offlineBasemap);
  mapView.setMap(map);

  // add feature data
  ServiceFeatureTable featureTable = new ServiceFeatureTable(LAYER_URL);
  featureLayer = new FeatureLayer(featureTable);
  map.getOperationalLayers().add(featureLayer);

  // create overlay for temporary graphics
  geometryResult = new GraphicsOverlay();
  mapView.getGraphicsOverlays().add(geometryResult);
  routeResult = new GraphicsOverlay();
  mapView.getGraphicsOverlays().add(routeResult);

  // set functions to execute when map is clicked and mouse moved over the
  // map
  mapView.setOnMouseClicked(mapClickEvent -> {
    if (functionOnMapClick != null) {
      functionOnMapClick.apply(mapClickEvent);
    }
  });
  mapView.setOnMouseMoved(mapMoveEvent -> {
    if (functionOnMouseMove != null) {
      functionOnMouseMove.apply(mapMoveEvent);
    }
  });
}
 
Example #26
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get MapView from layout
  mMapView = (MapView) findViewById(R.id.mapView);

  // create a map with the BasemapType topographic
  final ArcGISMap mMap = new ArcGISMap(Basemap.createTopographic());

  // set the map to be displayed in this view
  mMapView.setMap(mMap);

  // create color and symbols for drawing graphics
  SimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.TRIANGLE, Color.BLUE, 14);
  SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.CROSS, Color.BLUE, null);
  SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 3);

  // add a graphic of point, multipoint, polyline and polygon.
  GraphicsOverlay overlay = new GraphicsOverlay();
  mMapView.getGraphicsOverlays().add(overlay);
  overlay.getGraphics().add(new Graphic(createPolygon(), fillSymbol));
  overlay.getGraphics().add(new Graphic(createPolyline(), lineSymbol));
  overlay.getGraphics().add(new Graphic(createMultipoint(), markerSymbol));
  overlay.getGraphics().add(new Graphic(createPoint(), markerSymbol));

  // use the envelope to set the map viewpoint
  mMapView.setViewpointGeometryAsync(createEnvelope(), getResources().getDimension(R.dimen.viewpoint_padding));

}
 
Example #27
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new Graphic to a GraphicsOverlay in the MapView contained in the layout. Creates and adds a
 * new GraphicsOverlay to the MapView's collection, if required.
 *
 * @param graphicGeometry a Point to be used as the Geometry of the new Graphic
 * @param color           integer representing the color of the new Symbol
 * @return the Graphic which was added to an overlay
 */
private Graphic addGraphic(Point graphicGeometry, int color, SimpleMarkerSymbol.Style style) {
  if (mMapView.getGraphicsOverlays().size() < 1) {
    mMapView.getGraphicsOverlays().add(new GraphicsOverlay());
  }
  SimpleMarkerSymbol sym = new SimpleMarkerSymbol(style, color, 15.0f);
  Graphic g = new Graphic(graphicGeometry, sym);
  mMapView.getGraphicsOverlays().get(0).getGraphics().add(g);
  return g;
}
 
Example #28
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // get a reference to the scene view
  mSceneView = findViewById(R.id.sceneView);
  // create a scene and add it to the scene view
  ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
  mSceneView.setScene(scene);

  // add base surface for elevation data
  final Surface surface = new Surface();
  ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(
      getString(R.string.elevation_image_service_url));
  surface.getElevationSources().add(elevationSource);
  scene.setBaseSurface(surface);

  // add a camera and initial camera position
  Camera camera = new Camera(28.9, 45, 12000, 0, 45, 0);
  mSceneView.setViewpointCamera(camera);

  // add graphics overlay(s)
  GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
  graphicsOverlay.getSceneProperties().setSurfacePlacement(LayerSceneProperties.SurfacePlacement.ABSOLUTE);
  mSceneView.getGraphicsOverlays().add(graphicsOverlay);

  int[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.MAGENTA, Color.CYAN, Color.WHITE };
  SimpleMarkerSceneSymbol.Style[] symbolStyles = SimpleMarkerSceneSymbol.Style.values();

  // for each symbol style (cube, cone, cylinder, diamond, sphere, tetrahedron)
  for (int i = 0; i < symbolStyles.length; i++) {
    SimpleMarkerSceneSymbol simpleMarkerSceneSymbol = new SimpleMarkerSceneSymbol(symbolStyles[i], colors[i], 200,
        200, 200, SceneSymbol.AnchorPosition.CENTER);
    Graphic graphic = new Graphic(new Point(44.975 + .01 * i, 29, 500, SpatialReferences.getWgs84()),
        simpleMarkerSceneSymbol);
    graphicsOverlay.getGraphics().add(graphic);
  }
}
 
Example #29
Source File: DrawEntity.java    From ArcgisTool with Apache License 2.0 4 votes vote down vote up
public List<GraphicsOverlay> getPolygonGraphic() {
    return polygonGraphic;
}
 
Example #30
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // inflate MapView from layout
  mMapView = (MapView) findViewById(R.id.mapView);

  // create a map with the imagery basemap
  ArcGISMap map = new ArcGISMap(Basemap.createTopographic());

  // set the map to be displayed in the mapview
  mMapView.setMap(map);

  // create an initial viewpoint using an envelope (of two points, bottom left and top right)
  Envelope envelope = new Envelope(new Point(-228835, 6550763, SpatialReferences.getWebMercator()),
      new Point(-223560, 6552021, SpatialReferences.getWebMercator()));
  //set viewpoint on mapview
  mMapView.setViewpointGeometryAsync(envelope, 100.0);

  // create a new graphics overlay and add it to the mapview
  mGraphicsOverlay = new GraphicsOverlay();
  mMapView.getGraphicsOverlays().add(mGraphicsOverlay);

  //[DocRef: Name=Picture Marker Symbol URL, Category=Fundamentals, Topic=Symbols and Renderers]
  //Create a picture marker symbol from a URL resource
  //When using a URL, you need to call load to fetch the remote resource
  PictureMarkerSymbol campsiteSymbol = new PictureMarkerSymbol(
      "http://sampleserver6.arcgisonline"
          + ".com/arcgis/rest/services/Recreation/FeatureServer/0/images/e82f744ebb069bb35b234b3fea46deae");
  //Optionally set the size, if not set the image will be auto sized based on its size in pixels,
  //its appearance would then differ across devices with different resolutions.
  campsiteSymbol.setHeight(18);
  campsiteSymbol.setWidth(18);
  //[DocRef: END]
  // add a new graphic to the graphic overlay
  Point campsitePoint = new Point(-223560, 6552021, SpatialReferences.getWebMercator());
  Graphic campsiteGraphic = new Graphic(campsitePoint, campsiteSymbol);
  mGraphicsOverlay.getGraphics().add(campsiteGraphic);

  //[DocRef: Name=Picture Marker Symbol Drawable-android, Category=Fundamentals, Topic=Symbols and Renderers]
  //Create a picture marker symbol from an app resource
  BitmapDrawable pinStarBlueDrawable = (BitmapDrawable) ContextCompat.getDrawable(this, R.drawable.pin_star_blue);
  PictureMarkerSymbol pinStarBlueSymbol = new PictureMarkerSymbol(pinStarBlueDrawable);
  //Optionally set the size, if not set the image will be auto sized based on its size in pixels,
  //its appearance would then differ across devices with different resolutions.
  pinStarBlueSymbol.setHeight(40);
  pinStarBlueSymbol.setWidth(40);
  //Optionally set the offset, to align the base of the symbol aligns with the point geometry
  pinStarBlueSymbol.setOffsetY(
      11); //The image used for the symbol has a transparent buffer around it, so the offset is not simply height/2
  pinStarBlueSymbol.loadAsync();
  //[DocRef: END]
  //add a new graphic with the same location as the initial viewpoint
  Point pinStarBluePoint = new Point(-226773, 6550477, SpatialReferences.getWebMercator());
  Graphic pinStarBlueGraphic = new Graphic(pinStarBluePoint, pinStarBlueSymbol);
  mGraphicsOverlay.getGraphics().add(pinStarBlueGraphic);

  //see createPictureMarkerSymbolFromFile() method for implementation
  //first run checks for external storage and permissions,
  checkSaveResourceToExternalStorage();

}