You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于ArcGIS离线地图的Java图形绘制问题求助

Hey there! Let's work through this ArcGIS offline map drawing issue together. The paint() method error you're hitting is pretty common—because ArcGIS has its own managed rendering pipeline, directly calling paint() bypasses the layer system and causes context/rendering state mismatches. Here's the correct way to draw graphics on your offline map:

Step-by-Step Solution

Instead of using paint(), you'll use ArcGIS's built-in GraphicsLayer and Graphic classes to add shapes to your map. This is the official, supported approach that avoids rendering errors.

1. Add a GraphicsLayer to Your Map

All drawn graphics need to be attached to a GraphicsLayer, which you'll add to your map's operational layers:

// For Android (Java)
GraphicsLayer graphicsLayer = new GraphicsLayer();
map.getOperationalLayers().add(graphicsLayer);
// For iOS (Swift)
let graphicsLayer = AGSGraphicsLayer()
mapView.map?.operationalLayers.add(graphicsLayer)

2. Create Your Geometry & Symbol

Define the shape you want to draw (point, line, polygon) and a symbol to style it (color, thickness, fill type). Make sure the spatial reference of your geometry matches your offline map's spatial reference—this prevents your shapes from showing up in the wrong place!

// Example: Draw a red polygon with black border (Android)
// Create polygon points
List<Point> polygonPoints = new ArrayList<>();
polygonPoints.add(new Point(-118.0, 34.0, SpatialReferences.getWgs84()));
polygonPoints.add(new Point(-118.0, 35.0, SpatialReferences.getWgs84()));
polygonPoints.add(new Point(-117.0, 35.0, SpatialReferences.getWgs84()));
polygonPoints.add(new Point(-117.0, 34.0, SpatialReferences.getWgs84()));
Polygon polygon = new Polygon(polygonPoints);

// Create fill symbol
SimpleLineSymbol borderSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 2);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol(SimpleFillSymbol.Style.SOLID, Color.RED, borderSymbol);

3. Add the Graphic to the Layer

Wrap your geometry and symbol into a Graphic object, then add it to the GraphicsLayer—this will automatically render it on your map:

// Android
Graphic polygonGraphic = new Graphic(polygon, fillSymbol);
graphicsLayer.getGraphics().add(polygonGraphic);
// iOS
let graphic = AGSGraphic(geometry: polygon, symbol: fillSymbol, attributes: nil)
graphicsLayer.graphics.add(graphic)
Common Pitfalls to Avoid
  • Mismatched Spatial References: If your offline map uses a projected coordinate system (like Web Mercator), make sure your geometry uses the same spatial reference. Use GeometryEngine.project() to convert if needed.
  • Direct Paint Calls: Never try to draw directly in MapView's paint() callback—ArcGIS's rendering system handles all drawing internally, and manual calls break this flow.
  • Layer Order: Ensure your GraphicsLayer is added above your offline base layer so your shapes are visible.

This approach will get your graphics rendering correctly without the paint() method errors you were seeing. Let me know if you hit any specific edge cases with your offline setup!

内容的提问来源于stack exchange,提问作者Manjunatha Bhat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:39:40