Java源码示例:com.esri.arcgisruntime.mapping.view.GraphicsOverlay
示例1
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);
}
示例2
@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);
});
}
示例3
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));
}
}
示例4
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);
}
示例5
/**
* 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());
}
});
}
}
示例6
@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);
}
示例7
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);
}
示例8
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);
}
示例9
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;
}
示例10
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;
}
示例11
private void removeAllGraphics(List<GraphicsOverlay> go){
if(go.size()>0){
for(GraphicsOverlay graphics:go){
mapView.getGraphicsOverlays().remove(graphics);
}
}
}
示例12
@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);
}
示例13
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());
});
}
示例14
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()));
}
示例15
@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);
}
}
示例16
@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));
}
}
示例17
/**
* 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));
}
示例18
/**
* 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();
}
示例19
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;
}
示例20
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);
}
示例21
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);
}
示例22
@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;
}
});
}
示例23
@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]
}
示例24
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);
}
});
}
示例25
@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));
}
示例26
/**
* 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;
}
示例27
@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);
}
}
示例28
@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());
}
示例29
public void addGraphicsOverlay(ReadableMap args) {
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
RNAGSGraphicsOverlay overlay = new RNAGSGraphicsOverlay(args, graphicsOverlay);
rnGraphicsOverlays.put(overlay.getReferenceId(), overlay);
}
示例30
public GraphicsOverlay getAGSGraphicsOverlay() {
return graphicsOverlay;
}