com.esri.core.map.Graphic Java Examples

The following examples show how to use com.esri.core.map.Graphic. 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: DriveTimeExecutor.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        Graphic theGraphic = new Graphic(graphic.getGeometry(), zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #2
Source File: GeoJsonApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Parse GeoJSON file and add the features to a graphics layer.
 * @param graphicsLayer layer to which the features should be added.
 */
private void addGeoJsonFeatures(GraphicsLayer graphicsLayer) {
  try {
    // create an instance of the parser
    GeoJsonParser geoJsonParser = new GeoJsonParser();
    
    // provide the symbology for the features
    CompositeSymbol symbol = new CompositeSymbol();
    symbol.add(new SimpleFillSymbol(new Color(0, 255, 0, 70)));
    symbol.add(new SimpleLineSymbol(Color.BLACK, 2));
    geoJsonParser.setSymbol(symbol).setOutSpatialReference(map.getSpatialReference());
    
    // parse geojson data
    File geoJsonFile = new File(GEOJSON_DATA_FILE);
    List<Feature> features = geoJsonParser.parseFeatures(geoJsonFile);
    
    // add parsed features to a layer
    for (Feature f : features) {
     graphicsLayer.addGraphic(new Graphic(f.getGeometry(), f.getSymbol(), f.getAttributes()));
    }
  } catch (Exception ex) {
    throw new RuntimeException(ex);
  }
}
 
Example #3
Source File: GeoJsonParser.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private List<Feature> parseFeatures(ArrayNode jsonFeatures) {
  List<Feature> features = new LinkedList<Feature>();
  for (JsonNode jsonFeature : jsonFeatures) {
    String type = jsonFeature.path(FIELD_TYPE).getTextValue();
    if (!FIELD_FEATURE.equals(type)) {
      continue;
    }
    Geometry g = parseGeometry(jsonFeature.path(FIELD_GEOMETRY));
    if (outSR != null && outSR.getID() != 4326) {
      g = GeometryEngine.project(g, inSR, outSR);
    }
    Map<String, Object> attributes = parseProperties(jsonFeature.path(FIELD_PROPERTIES));
    Feature f = new Graphic(g, symbol, attributes);
    features.add(f);
  } 
  return features; 
}
 
Example #4
Source File: DemoTheatreAppImproved.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #5
Source File: AddAndMoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void addStaticGraphicsBulk(int numberOfGraphicsToAdd) {

    double minx = mapExtent.getXMin();
    double maxx = mapExtent.getXMax();
    double miny= mapExtent.getYMin();
    double maxy = mapExtent.getYMax();

    Point[] points = new Point[numberOfGraphicsToAdd];
    Graphic[] graphics = new Graphic[numberOfGraphicsToAdd];
    int i = 0;
    while (i < numberOfGraphicsToAdd) {
      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
      points[i] = point;
      graphics[i] = new Graphic(point, null);
      i++;
    }
    int[] ids = staticGraphicsLayer.addGraphics(graphics);
    
    for (int j = 0; j < numberOfGraphicsToAdd; j++) {
      latestStaticPoints.put(Integer.valueOf(ids[j]), points[j]);
    }
  }
 
Example #6
Source File: SymbolRendererApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void addGraphics(int numberOfGraphicsToAdd) {

    double minx = mapExtent.getXMin();
    double maxx = mapExtent.getXMax();
    double miny= mapExtent.getYMin();
    double maxy = mapExtent.getYMax();

    int i = 0;
    long startTime = System.currentTimeMillis();
    while (i < numberOfGraphicsToAdd) {
      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
      int id;
      if (addWithSymbol) {
    	  id = graphicsLayer.addGraphic(new Graphic(point, symbol));
      } else {
    	  id = graphicsLayer.addGraphic(new Graphic(point, null));  
      }
      latestDynamicPoints.put(Integer.valueOf(id), point);
      i++;
    }
    JOptionPane.showMessageDialog(appWindow, "Total time: " + (System.currentTimeMillis() - startTime)/1000.0 + " seconds.");
  }
 
Example #7
Source File: MoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void movePoints() {
  // loop through them all
  if (dynamicGraphicsLayer.getGraphicIDs()!=null) {
    for (int id : dynamicGraphicsLayer.getGraphicIDs()) {
      Point p1 = latestDynamicPoints.get(Integer.valueOf(id));
      Point p2 = getPointForSmoothMove(p1.getX(), p1.getY(), id);
      if (moveWithReplace) {
      	dynamicGraphicsLayer.removeGraphic(id);
      	int newId = dynamicGraphicsLayer.addGraphic(new Graphic(p2, null));
          latestDynamicPoints.put(Integer.valueOf(newId), p2);
      } else {
      	dynamicGraphicsLayer.updateGraphic(id, p2);
          //dynamicGraphicsLayer.movePointGraphic(id, p2);
          latestDynamicPoints.put(Integer.valueOf(id), p2);
      }
      
      //      dynamicGraphicsLayer.movePointGraphic(id, getRandomPointFrom(p.getX(), p.getY(), spreadOfMove));
    }
  }
}
 
Example #8
Source File: ClusterLayer.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void add(List<Cluster<ClusterableLocation>> clusters) {
  int max = getMax(clusters);
  for (Cluster<ClusterableLocation> cluster : clusters) {
    Geometry geometry = null;
    Symbol symbol = null;
    Color color = cluster.getPoints().size() == max ? Color.RED : Color.GRAY;
    ClusterType thisClusterType = cluster.getPoints().size() < 2 ? ClusterType.POINT : clusterType;
    switch (thisClusterType) {
      default:
      case POINT:
        geometry = getCenter(cluster);
        symbol = createPointSymbol(color, cluster.getPoints().size());
        break;
      case BOUNDING_RECTANGLE:
        geometry = getBoundingRectangle(cluster);
        symbol = createPolygonSymbol(color, cluster.getPoints().size());
        break;
      case CONVEX_HULL:
        geometry = getConvexHull(cluster);
        symbol = createPolygonSymbol(color, cluster.getPoints().size());
        break;
    };
    addGraphic(new Graphic(geometry, symbol));
  }
}
 
Example #9
Source File: ClusterApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Adds graphics symbolized with SimpleMarkerSymbols.
 * @param graphicsLayer
 */
private void addSimpleMarkerGraphics(GraphicsLayer graphicsLayer, Envelope bounds) {
  SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(Color.RED, 16, Style.CIRCLE);
  double xmin = bounds.getXMin();
  double xmax = bounds.getXMax();
  double xrand;
  double ymin = bounds.getYMin();
  double ymax = bounds.getYMax();
  double yrand;
  for (int i = 0; i < 1000; i++) {
    xrand = xmin + (int) (Math.random() * ((xmax - xmin) + 1));
    yrand = ymin + (int) (Math.random() * ((ymax - ymin) + 1));
    Point point = new Point(xrand, yrand);
    graphicsLayer.addGraphic(new Graphic(point, symbol));
  }
  
}
 
Example #10
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Process result from geoprocessing execution.
 * 
 * @param result output of geoprocessing execution.
 */
private void processResult(GPParameter[] result) {
  for (GPParameter outputParameter : result) {
    if (outputParameter instanceof GPFeatureRecordSetLayer) {
      GPFeatureRecordSetLayer gpLayer = (GPFeatureRecordSetLayer) outputParameter;
      int zone = 0;
      // get all the graphics and add them to the graphics layer.
      // there will be one graphic per zone.
      for (Graphic graphic : gpLayer.getGraphics()) {
        SpatialReference fromSR = SpatialReference.create(4326);
        Geometry g = graphic.getGeometry();
        Geometry pg = GeometryEngine.project(g, fromSR, jMap.getSpatialReference());
        Graphic theGraphic = new Graphic(pg, zoneFillSymbols[zone++]);
        // add to the graphics layer
        graphicsLayer.addGraphic(theGraphic);
      }
    }
  }
}
 
Example #11
Source File: AdvancedSymbolController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
private void removeGeomessage(Graphic graphic, boolean sendRemoveMessageForOwnMessages) {
    final String geomessageId = (String) graphic.getAttributeValue(Geomessage.ID_FIELD_NAME);
    final String geomessageType = (String) graphic.getAttributeValue(Geomessage.TYPE_FIELD_NAME);
    String uniqueDesignation = (String) graphic.getAttributeValue("uniquedesignation");
    if (sendRemoveMessageForOwnMessages && null != uniqueDesignation && uniqueDesignation.equals(messageController.getSenderUsername())) {
        new Thread() {
            public void run() {
                try {
                    sendRemoveMessage(messageController, geomessageId, geomessageType);
                } catch (Throwable t) {
                    Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Couldn't send REMOVE message", t);
                }
            }
        }.start();
    } else {
        processRemoveGeomessage(geomessageId, geomessageType);
    }
}
 
Example #12
Source File: IdentifyResultsJPanel.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the point that was used for the identify operation, for display purposes.
 * Ignored if null.
 * @param pt The point that was used for the identify operation, for display
 *           purposes. Ignored if null.
 */
public void setIdentifyPoint(Point pt) {
    identifyPoint = pt;
    if (null != pt) {
        graphicsLayer.setVisible(true);
        if (!isGraphicsLayerAdded) {
            mapController.addLayer(Integer.MAX_VALUE, graphicsLayer, false);
            isGraphicsLayerAdded = true;
        }
        String mgrs = mapController.pointToMgrs(pt, mapController.getSpatialReference());
        jLabel_mgrs.setText(mgrs);

        if (-1 != identifyPointGraphicUid) {
            graphicsLayer.updateGraphic(identifyPointGraphicUid, pt);
        } else {
            identifyPointGraphicUid = graphicsLayer.addGraphic(new Graphic(pt, identifyPointSymbol));
        }

    }
}
 
Example #13
Source File: DriveTimeExecutor.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the drive time zones on click of the mouse.
 */
@Override
public void mouseClicked(MouseEvent mapEvent) {

  super.mouseClicked(mapEvent);

  if (!enabled) {
    return;
  }

  if (mapEvent.getButton() == MouseEvent.BUTTON3) {
    // remove zones from previous computation
    graphicsLayer.removeAll();
    return;
  }

  // the click point is the starting point
  Point startPoint = jMap.toMapPoint(mapEvent.getX(), mapEvent.getY());
  Graphic startPointGraphic = new Graphic(startPoint, SYM_START_POINT);
  graphicsLayer.addGraphic(startPointGraphic);

  executeDriveTimes(startPointGraphic);
}
 
Example #14
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void highlightGeometry(Point point) {
  if (point == null) {
    return;
  }

  graphicsLayer.removeAll();
  graphicsLayer.addGraphic(
    new Graphic(point, new SimpleMarkerSymbol(Color.CYAN, 20, SimpleMarkerSymbol.Style.CIRCLE)));
  
  // -----------------------------------------------------------------------------------------
  // Zoom to the highlighted graphic
  // -----------------------------------------------------------------------------------------
  Geometry geometryForZoom = GeometryEngine.buffer(
    point, 
    map.getSpatialReference(), 
    map.getFullExtent().getWidth() * 0.10, 
    map.getSpatialReference().getUnit());
  map.zoomTo(geometryForZoom);
}
 
Example #15
Source File: AdvancedSymbolController.java    From defense-solutions-proofs-of-concept with Apache License 2.0 6 votes vote down vote up
@Override
protected Integer displaySpotReport(double x, double y, final int wkid, Integer graphicId, Geomessage geomessage) {
    try {
        Geometry pt = new Point(x, y);
        if (null != mapController.getSpatialReference() && wkid != mapController.getSpatialReference().getID()) {
            pt = GeometryEngine.project(pt, SpatialReference.create(wkid), mapController.getSpatialReference());
        }
        if (null != graphicId) {
            spotReportLayer.updateGraphic(graphicId, pt);
            spotReportLayer.updateGraphic(graphicId, geomessage.getProperties());
        } else {
            Graphic graphic = new Graphic(pt, spotReportSymbol, geomessage.getProperties());
            graphicId = spotReportLayer.addGraphic(graphic);
            
        }
        return graphicId;
    } catch (NumberFormatException nfe) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Could not parse spot report", nfe);
        return null;
    }
}
 
Example #16
Source File: AddAndMoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 6 votes vote down vote up
private void addStaticGraphicsBulk(int numberOfGraphicsToAdd) {

    double minx = mapExtent.getXMin();
    double maxx = mapExtent.getXMax();
    double miny= mapExtent.getYMin();
    double maxy = mapExtent.getYMax();

    Point[] points = new Point[numberOfGraphicsToAdd];
    Graphic[] graphics = new Graphic[numberOfGraphicsToAdd];
    int i = 0;
    while (i < numberOfGraphicsToAdd) {
      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
      points[i] = point;
      graphics[i] = new Graphic(point, null);
      i++;
    }
    int[] ids = staticGraphicsLayer.addGraphics(graphics);
    
    for (int j = 0; j < numberOfGraphicsToAdd; j++) {
      latestStaticPoints.put(Integer.valueOf(ids[j]), points[j]);
    }
  }
 
Example #17
Source File: DemoTheatreAppImproved.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void highlightGeometry(Point point) {
  if (point == null) {
    return;
  }

  graphicsLayer.removeAll();
  graphicsLayer.addGraphic(
    new Graphic(point, new SimpleMarkerSymbol(Color.CYAN, 20, SimpleMarkerSymbol.Style.CIRCLE)));
  
  // -----------------------------------------------------------------------------------------
  // Zoom to the highlighted graphic
  // -----------------------------------------------------------------------------------------
  // from base map's information, zoom to a resolution so that city is in focus
  map.zoomToResolution(0.02197265625, point);
}
 
Example #18
Source File: DemoTheatreAppImproved.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void handleAddGraphic(MouseEvent mapEvent) {
  Point p = jMap.toMapPoint(mapEvent.getPoint().x, mapEvent.getPoint().y);
  // Tip: use the right symbol for geometry
  SimpleMarkerSymbol s = new SimpleMarkerSymbol(Color.RED, 14, Style.CROSS);
  //SimpleLineSymbol s = new SimpleLineSymbol(Color.RED, 10);
  graphicsLayer.addGraphic(new Graphic(p, s));  
}
 
Example #19
Source File: DemoTheatreAppImproved.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void handleAnalyzeDriveTime(MouseEvent mapEvent) {
  tasksInProgress.incrementAndGet();
  updateProgresBarUI("Computing drive time zones...", true);

  // the click point is the starting point
  Point startPoint = jMap.toMapPoint(mapEvent.getX(), mapEvent.getY());
  Graphic startPointGraphic = new Graphic(startPoint, SYM_START_POINT);
  graphicsLayer.addGraphic(startPointGraphic);

  executeDriveTimes(startPointGraphic);
}
 
Example #20
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void handleAddGraphic(MouseEvent mapEvent) {
  Point p = jMap.toMapPoint(mapEvent.getPoint().x, mapEvent.getPoint().y);
  // Tip: use the right symbol for geometry
  // SimpleMarkerSymbol s = new SimpleMarkerSymbol(Color.RED, 14, Style.CROSS);
  SimpleLineSymbol s = new SimpleLineSymbol(Color.RED, 10);
  graphicsLayer.addGraphic(new Graphic(p, s));  
}
 
Example #21
Source File: DemoTheatreApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void handleAnalyzeDriveTime(MouseEvent mapEvent) {
  tasksInProgress.incrementAndGet();
  updateProgresBarUI("Computing drive time zones...", true);

  // the click point is the starting point
  Point startPoint = jMap.toMapPoint(mapEvent.getX(), mapEvent.getY());
  Graphic startPointGraphic = new Graphic(startPoint, SYM_START_POINT);
  graphicsLayer.addGraphic(startPointGraphic);

  executeDriveTimes(startPointGraphic);
}
 
Example #22
Source File: MyMapApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
protected void solveRoute() {
  // ROUTING
  RoutingTask task = new RoutingTask(
      "http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World", 
      credentials);

  RoutingTaskParameters parameters = new RoutingTaskParameters();
  stops.setSpatialReference(map.getSpatialReference());
  parameters.setStops(stops);
  parameters.setOutSpatialReference(map.getSpatialReference());
  task.solveAsync(parameters, new CallbackListener<RoutingResult>() {

    @Override
    public void onError(Throwable e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(map.getParent(),
          "An error has occured. "+e.getLocalizedMessage(), "", JOptionPane.WARNING_MESSAGE);
    }

    @Override
    public void onCallback(RoutingResult result) {
      if (result != null ) {
        Route topRoute = result.getRoutes().get(0);
        Graphic routeGraphic = new Graphic(topRoute.getRoute().getGeometry(),
            new SimpleLineSymbol(Color.BLUE, 2.0f));
        stopGraphics.addGraphic(routeGraphic);
      }
    }
  });
}
 
Example #23
Source File: SymbolRendererApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void addGraphicsBulk(int numberOfGraphicsToAdd) {

	    double minx = mapExtent.getXMin();
	    double maxx = mapExtent.getXMax();
	    double miny= mapExtent.getYMin();
	    double maxy = mapExtent.getYMax();

	    int i = 0;
	    long startTime = System.currentTimeMillis();
	    int BATCH_SIZE = 1000;
	    Graphic[] batchGraphics = new Graphic[BATCH_SIZE];
	    int c = 0;
	    while (i < numberOfGraphicsToAdd) {
	    	
	      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
	      int id;
	      if (addWithSymbol) {
	    	  batchGraphics[c++] = new Graphic(point, symbol);
	      }
	      if (c == 100) {
	    	  graphicsLayer.addGraphics(batchGraphics);
	    	  c = 0;
	      }
	      
	      //latestDynamicPoints.put(Integer.valueOf(id), point);
	      i++;
	    }
	    JOptionPane.showMessageDialog(appWindow, "Total time: " + (System.currentTimeMillis() - startTime)/1000.0 + " seconds.");
	  }
 
Example #24
Source File: OverlayApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent e) {
  Point pt = map.toMapPoint(e.getX(), e.getY());

  Geometry buffer = GeometryEngine.buffer(pt, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());

  Graphic g = new Graphic(buffer, bufferSymbol);
  graphicsLayer.addGraphic(g);
}
 
Example #25
Source File: GPSTesterActivityController.java    From android-gps-test-tool with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method that uses latitude/longitude points to programmatically 
 * draw a <code>SimpleMarkerSymbol</code> and adds the <code>Graphic</code> to map.
 * @param latitude
 * @param longitude
 * @param attributes
 * @param style You defined the style via the Enum <code>SimpleMarkerSymbol.STYLE</code>
 */
public static void addGraphicLatLon(double latitude, double longitude, Map<String, Object> attributes, 
		SimpleMarkerSymbol.STYLE style,int color,int size, GraphicsLayer graphicsLayer, MapView map){
	
	Point latlon = new Point(longitude,latitude);		
	
	//Convert latlon Point to mercator map point.
	Point point = (Point)GeometryEngine.project(latlon,SpatialReference.create(4326), map.getSpatialReference());		
	
	//Set market's color, size and style. You can customize these as you see fit
	SimpleMarkerSymbol symbol = new SimpleMarkerSymbol(color,size, style);			
	Graphic graphic = new Graphic(point, symbol,attributes);
	graphicsLayer.addGraphic(graphic);
}
 
Example #26
Source File: OverlayApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent e) {
  Point pt = map.toMapPoint(e.getX(), e.getY());

  Geometry buffer = GeometryEngine.buffer(pt, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());

  Graphic g = new Graphic(buffer, bufferSymbol);
  graphicsLayer.addGraphic(g);
}
 
Example #27
Source File: GeometryOnlineApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseClicked(MouseEvent event) {
  graphicsLayer.removeAll();

  // add buffer as a graphic
  Point mapPoint = map.toMapPoint(event.getX(), event.getY());
  Geometry buffer = GeometryEngine.buffer(
      mapPoint, map.getSpatialReference(), 200000, map.getSpatialReference().getUnit());
  graphicsLayer.addGraphic(new Graphic(buffer, new SimpleFillSymbol(new Color(100, 0, 0, 80))));

  // get states at the buffered area
  QueryTask queryTask = new QueryTask(featureLayer.getUrl());
  QueryParameters queryParams = new QueryParameters();
  queryParams.setInSpatialReference(map.getSpatialReference());
  queryParams.setOutSpatialReference(map.getSpatialReference());
  queryParams.setGeometry(buffer);
  queryParams.setReturnGeometry(true);
  queryParams.setOutFields(new String[] {"STATE_NAME"});

  queryTask.executeAsync(queryParams, new CallbackListener<FeatureResult>() {

    @Override
    public void onError(Throwable arg0) {
      // deal with any exception
    }

    @Override
    public void onCallback(FeatureResult result) {
      for (Object objFeature : result) {
        Feature feature = (Feature) objFeature;
        graphicsLayer.addGraphic(new Graphic(feature.getGeometry(), stateSymbol));
      }
    }
  });
}
 
Example #28
Source File: ParticleGraphicsEllipseApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void addEllipses(int numberOfEllipses) {
  SimpleMarkerSymbol[] symbols = {symbol4, symbol3, symbol2, symbol1};
  // some values that works well
  int majorAxisLength = 4612483;
  int minorAxisLength = 1843676;

  centerPoint = new Point(500000-5000000, 500000 + 3000000);
  centerGraphicsLayer.addGraphic(new Graphic(centerPoint, null));

  for (int i = 0; i < numberOfEllipses; i++) {
    Point center = new Point(random.nextInt(500000)-5000000, random.nextInt(500000) + 3000000);
    int majorAxisDirection = random.nextInt(60);
    LinearUnit unit = new LinearUnit(LinearUnit.Code.METER);

    Geometry ellipse = GeometryEngine.geodesicEllipse(center, map.getSpatialReference(), majorAxisLength, minorAxisLength,
        majorAxisDirection, pointCount, unit, Geometry.Type.MULTIPOINT);

    if (ellipse instanceof MultiPoint) {
      SimpleMarkerSymbol symbol = symbols[i%4];
      MultiPoint mp = (MultiPoint) ellipse;
      Ellipse currentEllipse = new Ellipse(mp); 
      ellipses.add(currentEllipse);
      int j = 0;
      while (j < mp.getPointCount()) {
        if (j%8==0) {
          Point point = mp.getPoint(j);
          int id = ellipseGraphicsLayer.addGraphic(new Graphic(point, symbol));
          currentEllipse.addPoint(id, j);
        }
        j++;
      }
    }
  }
}
 
Example #29
Source File: AddAndMoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void addDynamicGraphics(int numberOfGraphicsToAdd) {

    double minx = mapExtent.getXMin();
    double maxx = mapExtent.getXMax();
    double miny= mapExtent.getYMin();
    double maxy = mapExtent.getYMax();

    int i = 0;
    while (i < numberOfGraphicsToAdd) {
      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
      int id = dynamicGraphicsLayer.addGraphic(new Graphic(point, null));
      latestDynamicPoints.put(Integer.valueOf(id), point);
      i++;
    }
  }
 
Example #30
Source File: MoveGraphicsApp.java    From arcgis-runtime-demo-java with Apache License 2.0 5 votes vote down vote up
private void addDynamicGraphics(int numberOfGraphicsToAdd) {

    double minx = mapExtent.getXMin();
    double maxx = mapExtent.getXMax();
    double miny= mapExtent.getYMin();
    double maxy = mapExtent.getYMax();

    int i = 0;
    while (i < numberOfGraphicsToAdd) {
      Point point = new Point((random.nextFloat()*(maxx-minx)) + minx, (random.nextFloat()*(maxy-miny)) + miny);
      int id = dynamicGraphicsLayer.addGraphic(new Graphic(point, null));
      latestDynamicPoints.put(Integer.valueOf(id), point);
      i++;
    }
  }