import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
/**
* Creates a list of three SimpleLineSymbols, (blue, red, green).
*/
private void createLineSymbols() {
lineSymbols = new ArrayList<>();
// solid blue (0xFF0000FF) simple line symbol
SimpleLineSymbol blueLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 3);
lineSymbols.add(blueLineSymbol);
// solid green (0xFF00FF00) simple line symbol
SimpleLineSymbol greenLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF00FF00, 3);
lineSymbols.add(greenLineSymbol);
// solid red (0xFFFF0000) simple line symbol
SimpleLineSymbol redLineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFFFF0000, 3);
lineSymbols.add(redLineSymbol);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
private void symbolizeShapefile() {
// create a shapefile feature table from the local data
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(
Environment.getExternalStorageDirectory() + getString(R.string.local_folder) + getString(R.string.file_name));
// use the shapefile feature table to create a feature layer
FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);
// create the Symbol
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 1.0f);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, lineSymbol);
// create the Renderer
SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
// set the Renderer on the Layer
featureLayer.setRenderer(renderer);
// add the feature layer to the map
mMap.getOperationalLayers().add(featureLayer);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
/**
* Creates a PolyLine Feature Collection Table with one PolyLine and adds it to the Feature collection that was passed.
*
* @param featureCollection that the polyline Feature Collection Table will be added to
*/
private void createPolylineTable(FeatureCollection featureCollection) {
// defines the schema for the geometry's attribute
List<Field> polylineFields = new ArrayList<>();
polylineFields.add(Field.createString("Boundary", "Boundary Name", 50));
// a feature collection table that creates polyline geometry
FeatureCollectionTable polylineTable = new FeatureCollectionTable(polylineFields, GeometryType.POLYLINE, WGS84);
// set a default symbol for features in the collection table
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, 0xFF00FF00, 3);
SimpleRenderer renderer = new SimpleRenderer(lineSymbol);
polylineTable.setRenderer(renderer);
// add feature collection table to feature collection
featureCollection.getTables().add(polylineTable);
// create feature using the collection table by passing an attribute and geometry
Map<String, Object> attributes = new HashMap<>();
attributes.put(polylineFields.get(0).getName(), "AManAPlanACanalPanama");
PolylineBuilder builder = new PolylineBuilder(WGS84);
builder.addPoint(new Point(-79.497238, 8.849289, WGS84));
builder.addPoint(new Point(-80.035568, 9.432302, WGS84));
Feature addedFeature = polylineTable.createFeature(attributes, builder.toGeometry());
// add feature to collection table
polylineTable.addFeatureAsync(addedFeature);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
/**
* Creates a Polygon Feature Collection Table with one Polygon and adds it to the Feature collection that was passed.
*
* @param featureCollection that the polygon Feature Collection Table will be added to
*/
private void createPolygonTables(FeatureCollection featureCollection) {
// defines the schema for the geometry's attribute
List<Field> polygonFields = new ArrayList<>();
polygonFields.add(Field.createString("Area", "Area Name", 50));
// a feature collection table that creates polygon geometry
FeatureCollectionTable polygonTable = new FeatureCollectionTable(polygonFields, GeometryType.POLYGON, WGS84);
// set a default symbol for features in the collection table
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 2);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.DIAGONAL_CROSS, 0xFF00FFFF, lineSymbol);
SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
polygonTable.setRenderer(renderer);
// add feature collection table to feature collection
featureCollection.getTables().add(polygonTable);
// create feature using the collection table by passing an attribute and geometry
Map<String, Object> attributes = new HashMap<>();
attributes.put(polygonFields.get(0).getName(), "Restricted area");
PolygonBuilder builder = new PolygonBuilder(WGS84);
builder.addPoint(new Point(-79.497238, 8.849289, WGS84));
builder.addPoint(new Point(-79.337936, 8.638903, WGS84));
builder.addPoint(new Point(-79.11409, 8.895422, WGS84));
Feature addedFeature = polygonTable.createFeature(attributes, builder.toGeometry());
// add feature to collection table
polygonTable.addFeatureAsync(addedFeature);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
/**
* Creates a Polyline and adds it to a GraphicsOverlay.
*/
private void createPolyline() {
// create a purple (0xFF800080) simple line symbol
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, 0xFF800080, 4);
// create a new point collection for polyline
PointCollection points = new PointCollection(SPATIAL_REFERENCE);
// create and add points to the point collection
points.add(new Point(-2.715, 56.061));
points.add(new Point(-2.6438, 56.079));
points.add(new Point(-2.638, 56.079));
points.add(new Point(-2.636, 56.078));
points.add(new Point(-2.636, 56.077));
points.add(new Point(-2.637, 56.076));
points.add(new Point(-2.715, 56.061));
// create the polyline from the point collection
Polyline polyline = new Polyline(points);
// create the graphic with polyline and symbol
Graphic graphic = new Graphic(polyline, lineSymbol);
// add graphic to the graphics overlay
graphicsOverlay.getGraphics().add(graphic);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
/**
* Creates a Polygon and adds it to a GraphicsOverlay.
*/
private void createPolygon() {
// create a green (0xFF005000) simple line symbol
SimpleLineSymbol outlineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.DASH, 0xFF005000, 1);
// create a green (0xFF005000) mesh simple fill symbol
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.DIAGONAL_CROSS, 0xFF005000,
outlineSymbol);
// create a new point collection for polygon
PointCollection points = new PointCollection(SPATIAL_REFERENCE);
// create and add points to the point collection
points.add(new Point(-2.6425, 56.0784));
points.add(new Point(-2.6430, 56.0763));
points.add(new Point(-2.6410, 56.0759));
points.add(new Point(-2.6380, 56.0765));
points.add(new Point(-2.6380, 56.0784));
points.add(new Point(-2.6410, 56.0786));
// create the polyline from the point collection
Polygon polygon = new Polygon(points);
// create the graphic with polyline and symbol
Graphic graphic = new Graphic(polygon, fillSymbol);
// add graphic to the graphics overlay
graphicsOverlay.getGraphics().add(graphic);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@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 topographic basemap
final ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
// set the map to be displayed in the mapview
mMapView.setMap(map);
// create feature layer with its service feature table
// create the service feature table
mServiceFeatureTable = new ServiceFeatureTable(getResources().getString(R.string.sample_service_url));
// create the feature layer using the service feature table
mFeaturelayer = new FeatureLayer(mServiceFeatureTable);
mFeaturelayer.setOpacity(0.8f);
//override the renderer
SimpleLineSymbol lineSymbol= new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 1);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.YELLOW, lineSymbol);
mFeaturelayer.setRenderer(new SimpleRenderer(fillSymbol));
// add the layer to the map
map.getOperationalLayers().add(mFeaturelayer);
// zoom to a view point of the USA
mMapView.setViewpointCenterAsync(new Point(-11000000, 5000000, SpatialReferences.getWebMercator()), 100000000);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
private void overrideRenderer() {
// create a new simple renderer for the line feature layer
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(0, 0, 255), 2);
SimpleRenderer simpleRenderer = new SimpleRenderer(lineSymbol);
// override the current renderer with the new renderer defined above
mFeatureLayer.setRenderer(simpleRenderer);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// get MapView from layout
MapView 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));
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@FXML
public void initialize() {
ArcGISMap map = new ArcGISMap(Basemap.createStreets());
mapView.setMap(map);
// set mapview to San Diego
mapView.setViewpoint(new Viewpoint(32.73, -117.14, 60000));
// create service area task from url
final String SanDiegoRegion = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/NetworkAnalysis/SanDiego/NAServer/ServiceArea";
serviceAreaTask = new ServiceAreaTask(SanDiegoRegion);
serviceAreaTask.loadAsync();
// create default parameters from task
ListenableFuture<ServiceAreaParameters> parameters = serviceAreaTask.createDefaultParametersAsync();
parameters.addDoneListener(() -> {
try {
serviceAreaParameters = parameters.get();
serviceAreaParameters.setPolygonDetail(ServiceAreaPolygonDetail.HIGH);
serviceAreaParameters.setReturnPolygons(true);
// adding another service area of 2 minutes
// default parameters have a default service area of 5 minutes
serviceAreaParameters.getDefaultImpedanceCutoffs().addAll(Arrays.asList(2.0));
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
});
// for displaying graphics to mapview
serviceAreasOverlay = new GraphicsOverlay();
facilityOverlay = new GraphicsOverlay();
barrierOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().addAll(Arrays.asList(serviceAreasOverlay, barrierOverlay, facilityOverlay));
barrierBuilder = new PolylineBuilder(spatialReference);
serviceAreaFacilities = new ArrayList<>();
SimpleLineSymbol outline = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF000000, 3.0f);
fillSymbols = new ArrayList<>();
fillSymbols.add(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x66FF0000, outline));
fillSymbols.add(new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0x66FFA500, outline));
// icon used to display facilities to mapview
String facilityUrl = "http://static.arcgis.com/images/Symbols/SafetyHealth/Hospital.png";
PictureMarkerSymbol facilitySymbol = new PictureMarkerSymbol(facilityUrl);
facilitySymbol.setHeight(30);
facilitySymbol.setWidth(30);
// creates facilities and barriers at user's clicked location
mapView.setOnMouseClicked(e -> {
if (e.getButton() == MouseButton.PRIMARY && e.isStillSincePress()) {
// create a point from where the user clicked
Point2D point = new Point2D(e.getX(), e.getY());
Point mapPoint = mapView.screenToLocation(point);
if (btnAddFacility.isSelected()) {
// create facility from point and display to mapview
Point servicePoint = new Point(mapPoint.getX(), mapPoint.getY(), spatialReference);
serviceAreaFacilities.add(new ServiceAreaFacility(servicePoint));
facilityOverlay.getGraphics().add(new Graphic(servicePoint, facilitySymbol));
} else if (btnAddBarrier.isSelected()) {
// create barrier and display to mapview
barrierBuilder.addPoint(new Point(mapPoint.getX(), mapPoint.getY(), spatialReference));
barrierOverlay.getGraphics().add(barrierOverlay.getGraphics().size(), new Graphic(barrierBuilder.toGeometry(), outline));
}
}
});
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
scene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
// set title, size, and add scene to stage
stage.setTitle("Simple Line Symbol Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
// create a control panel
VBox vBoxControl = new VBox(6);
vBoxControl.setMaxSize(180, 200);
vBoxControl.getStyleClass().add("panel-region");
createSymbolFuntionality(vBoxControl);
final ArcGISMap map = new ArcGISMap(Basemap.createImagery());
// set initial map view point
Point point = new Point(-226773, 6550477, SpatialReferences.getWebMercator());
Viewpoint viewpoint = new Viewpoint(point, 7200); // point, scale
map.setInitialViewpoint(viewpoint);
// create a view for this ArcGISMap and set ArcGISMap to it
mapView = new MapView();
mapView.setMap(map);
// creates a line from two points
PointCollection points = new PointCollection(SpatialReferences.getWebMercator());
points.add(-226913, 6550477);
points.add(-226643, 6550477);
Polyline line = new Polyline(points);
// creates a solid red (0xFFFF0000) simple line symbol
lineSymbol = new SimpleLineSymbol(Style.SOLID, 0xFFFF0000, 3);
// add line with symbol to graphics overlay and add overlay to map view
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
mapView.getGraphicsOverlays().add(graphicsOverlay);
graphicsOverlay.getGraphics().add(new Graphic(line, lineSymbol));
// add the map view and control panel to stack pane
stackPane.getChildren().addAll(mapView, vBoxControl);
StackPane.setAlignment(vBoxControl, Pos.TOP_LEFT);
StackPane.setMargin(vBoxControl, new Insets(10, 0, 0, 10));
} catch (Exception e) {
// on any error, display the stack trace
e.printStackTrace();
}
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
StackPane stackPane = new StackPane();
Scene fxScene = new Scene(stackPane);
// for adding styling to any controls that are added
fxScene.getStylesheets().add(getClass().getResource("/css/style.css").toExternalForm());
// set title, size, and add scene to stage
stage.setTitle("Feature Layer Extrusion Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(fxScene);
stage.show();
// so scene can be visible within application
ArcGISScene scene = new ArcGISScene(Basemap.createTopographic());
sceneView = new SceneView();
sceneView.setArcGISScene(scene);
stackPane.getChildren().add(sceneView);
// get us census data as a service feature table
ServiceFeatureTable statesServiceFeatureTable = new ServiceFeatureTable("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3");
// creates feature layer from table and add to scene
final FeatureLayer statesFeatureLayer = new FeatureLayer(statesServiceFeatureTable);
// feature layer must be rendered dynamically for extrusion to work
statesFeatureLayer.setRenderingMode(FeatureLayer.RenderingMode.DYNAMIC);
scene.getOperationalLayers().add(statesFeatureLayer);
// symbols are used to display features (US states) from table
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF000000, 1.0f);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFF0000FF, lineSymbol);
final SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
// need to set an extrusion type, BASE HEIGHT extrudes each point from feature individually
renderer.getSceneProperties().setExtrusionMode(Renderer.SceneProperties.ExtrusionMode.BASE_HEIGHT);
statesFeatureLayer.setRenderer(renderer);
// set camera to focus on state features
Point lookAtPoint = new Point(-10974490, 4814376, 0, SpatialReferences.getWebMercator());
OrbitLocationCameraController orbitCamera = new OrbitLocationCameraController(lookAtPoint, 10000000);
sceneView.setCameraController(orbitCamera);
// create a control panel
VBox vBoxControl = new VBox();
vBoxControl.setMaxSize(200, 40);
vBoxControl.getStyleClass().add("panel-region");
stackPane.getChildren().add(vBoxControl);
StackPane.setAlignment(vBoxControl, Pos.TOP_LEFT);
StackPane.setMargin(vBoxControl, new Insets(10, 0, 0, 10));
// controls for extruding by total population or by population density
Button extrusionButton = new Button("Population Density");
extrusionButton.setOnAction(v -> {
if (showTotalPopulation) {
// some feature's population is really big of need to sink it down
renderer.getSceneProperties().setExtrusionExpression("[POP2007]/ 10");
extrusionButton.setText("Population Density");
showTotalPopulation = false;
} else {
// density of population is a small value to need to increase it
renderer.getSceneProperties().setExtrusionExpression("[POP07_SQMI] * 5000");
extrusionButton.setText("Total Population");
showTotalPopulation = true;
}
});
extrusionButton.setMaxWidth(Double.MAX_VALUE);
extrusionButton.fire();
vBoxControl.getChildren().add(extrusionButton);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@Override
public void start(Stage stage) throws Exception {
try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);
// set title, size, and add scene to stage
stage.setTitle("Add Graphics with Renderer Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();
// create a map with topographic basemap
ArcGISMap map = new ArcGISMap(Basemap.Type.TOPOGRAPHIC, 15.169193, 16.333479, 2);
// set the map to the view
mapView = new MapView();
mapView.setMap(map);
// create a graphics overlay for displaying point graphic
GraphicsOverlay pointGraphicOverlay = new GraphicsOverlay();
// create point geometry
Point point = new Point(40e5, 40e5, SpatialReferences.getWebMercator());
// create graphic for point
Graphic pointGraphic = new Graphic(point);
// red (0xFFFF0000) diamond point symbol
SimpleMarkerSymbol pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.DIAMOND, 0xFFFF0000, 10);
// create simple renderer
SimpleRenderer pointRenderer = new SimpleRenderer(pointSymbol);
// set renderer on graphics overlay
pointGraphicOverlay.setRenderer(pointRenderer);
// add graphic to overlay
pointGraphicOverlay.getGraphics().add(pointGraphic);
// add graphics overlay to the MapView
mapView.getGraphicsOverlays().add(pointGraphicOverlay);
// solid blue (0xFF0000FF) line graphic
GraphicsOverlay lineGraphicOverlay = new GraphicsOverlay();
PolylineBuilder lineGeometry = new PolylineBuilder(SpatialReferences.getWebMercator());
lineGeometry.addPoint(-10e5, 40e5);
lineGeometry.addPoint(20e5, 50e5);
Graphic lineGraphic = new Graphic(lineGeometry.toGeometry());
lineGraphicOverlay.getGraphics().add(lineGraphic);
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, 0xFF0000FF, 5);
SimpleRenderer lineRenderer = new SimpleRenderer(lineSymbol);
lineGraphicOverlay.setRenderer(lineRenderer);
mapView.getGraphicsOverlays().add(lineGraphicOverlay);
// solid yellow (0xFFFFFF00) polygon graphic
GraphicsOverlay polygonGraphicOverlay = new GraphicsOverlay();
PolygonBuilder polygonGeometry = new PolygonBuilder(SpatialReferences.getWebMercator());
polygonGeometry.addPoint(-20e5, 20e5);
polygonGeometry.addPoint(20e5, 20e5);
polygonGeometry.addPoint(20e5, -20e5);
polygonGeometry.addPoint(-20e5, -20e5);
Graphic polygonGraphic = new Graphic(polygonGeometry.toGeometry());
polygonGraphicOverlay.getGraphics().add(polygonGraphic);
SimpleFillSymbol polygonSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, 0xFFFFFF00, null);
SimpleRenderer polygonRenderer = new SimpleRenderer(polygonSymbol);
polygonGraphicOverlay.setRenderer(polygonRenderer);
mapView.getGraphicsOverlays().add(polygonGraphicOverlay);
// add the map view to stack pane
stackPane.getChildren().add(mapView);
} catch (Exception e) {
e.printStackTrace();
}
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
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);
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// set flag for showing total population or population density
showTotalPopulation = true;
// inflate population type toggle button
final Button togglePopButton = findViewById(R.id.toggle_button);
// get us census data as a service feature table
ServiceFeatureTable statesServiceFeatureTable = new ServiceFeatureTable(
getResources().getString(R.string.us_census_feature_service));
// add the service feature table to a feature layer
final FeatureLayer statesFeatureLayer = new FeatureLayer(statesServiceFeatureTable);
// set the feature layer to render dynamically to allow extrusion
statesFeatureLayer.setRenderingMode(FeatureLayer.RenderingMode.DYNAMIC);
// create a scene and add it to the scene view
ArcGISScene scene = new ArcGISScene(Basemap.createImagery());
SceneView sceneView = findViewById(R.id.sceneView);
sceneView.setScene(scene);
// add the feature layer to the scene
scene.getOperationalLayers().add(statesFeatureLayer);
// define line and fill symbols for a simple renderer
SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 1.0f);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.BLUE, lineSymbol);
final SimpleRenderer renderer = new SimpleRenderer(fillSymbol);
// set renderer extrusion mode to base height, which includes base height of each vertex in calculating z values
renderer.getSceneProperties().setExtrusionMode(Renderer.SceneProperties.ExtrusionMode.BASE_HEIGHT);
// set the simple renderer to the feature layer
statesFeatureLayer.setRenderer(renderer);
// define a look at point for the camera at geographical center of the continental US
Point lookAtPoint = new Point(-10974490, 4814376, 0, SpatialReferences.getWebMercator());
// add a camera and set it to orbit the look at point
Camera camera = new Camera(lookAtPoint, 20000000, 0, 55, 0);
OrbitLocationCameraController orbitCamera = new OrbitLocationCameraController(lookAtPoint, 20000000);
sceneView.setCameraController(orbitCamera);
sceneView.setViewpointCamera(camera);
// set button listener
togglePopButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// set extrusion properties to either show total population or population density based on flag
if (showTotalPopulation) {
// divide total population by 10 to make data legible
renderer.getSceneProperties().setExtrusionExpression("[POP2007] / 10");
// change text of button to total pop
togglePopButton.setText(R.string.total_pop);
showTotalPopulation = false;
} else {
// multiple population density by 5000 to make data legible
renderer.getSceneProperties().setExtrusionExpression("[POP07_SQMI] * 5000");
// change text of button to pop density
togglePopButton.setText(R.string.density_pop);
showTotalPopulation = true;
}
}
});
// click to set initial state
togglePopButton.performClick();
}
import com.esri.arcgisruntime.symbology.SimpleLineSymbol; //导入依赖的package包/类
@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 topographic basemap
ArcGISMap map = new ArcGISMap(Basemap.createTopographic());
//[DocRef: Name=Unique Value Renderer, Topic=Symbols and Renderers, Category=Fundamentals]
// Create service feature table
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(getResources().getString(R.string.sample_service_url));
// Create the feature layer using the service feature table
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
// Override the renderer of the feature layer with a new unique value renderer
UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();
// Set the field to use for the unique values
uniqueValueRenderer.getFieldNames().add("STATE_ABBR"); //You can add multiple fields to be used for the renderer in the form of a list, in this case we are only adding a single field
// Create the symbols to be used in the renderer
SimpleFillSymbol defaultFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.NULL, Color.BLACK, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GRAY, 2));
SimpleFillSymbol californiaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.RED, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.RED, 2));
SimpleFillSymbol arizonaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.GREEN, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.GREEN, 2));
SimpleFillSymbol nevadaFillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID,Color.BLUE, new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 2));
// Set default symbol
uniqueValueRenderer.setDefaultSymbol(defaultFillSymbol);
uniqueValueRenderer.setDefaultLabel("Other");
// Set value for california
List<Object> californiaValue = new ArrayList<>();
// You add values associated with fields set on the unique value renderer.
// If there are multiple values, they should be set in the same order as the fields are set
californiaValue.add("CA");
uniqueValueRenderer.getUniqueValues().add(new UniqueValueRenderer.UniqueValue("California", "State of California", californiaFillSymbol, californiaValue));
// Set value for arizona
List<Object> arizonaValue = new ArrayList<>();
// You add values associated with fields set on the unique value renderer.
// If there are multiple values, they should be set in the same order as the fields are set
arizonaValue.add("AZ");
uniqueValueRenderer.getUniqueValues().add(new UniqueValueRenderer.UniqueValue("Arizona", "State of Arizona", arizonaFillSymbol, arizonaValue));
// Set value for nevada
List<Object> nevadaValue = new ArrayList<>();
// You add values associated with fields set on the unique value renderer.
// If there are multiple values, they should be set in the same order as the fields are set
nevadaValue.add("NV");
uniqueValueRenderer.getUniqueValues().add(new UniqueValueRenderer.UniqueValue("Nevada", "State of Nevada", nevadaFillSymbol, nevadaValue));
// Set the renderer on the feature layer
featureLayer.setRenderer(uniqueValueRenderer);
//[DocRef: END]
// add the layer to the map
map.getOperationalLayers().add(featureLayer);
map.setInitialViewpoint(new Viewpoint(new Envelope(-13893029.0, 3573174.0, -12038972.0, 5309823.0, SpatialReferences.getWebMercator())));
// set the map to be displayed in the mapview
mMapView.setMap(map);
}
请发表评论