building applications with arcgis runtime sdk for android - esri
TRANSCRIPT
Building Applications with ArcGIS Runtime SDK for Android—Part II
Will Crick Dan O’Neill
Agenda
• Intro • Connected editing summary • Offline capabilities
- Local features - Geometry Engine
• Platform integration • Accessing content from ArcGIS Online/Portal • Best practice
- Layer performance - UI thread - Device support
Intro
Who are we all?
• Who are you? • Who are we?
ArcGIS 10 — A Complete System
Easier More Powerful and Everywhere
Cloud
Enterprise
Local
• Discover • Create • Manage • Visualize • Analyze • Collaborate
Mobile
Desktop
Web
Runtime SDKs
Native ArcGIS Runtime SDKs
iOS Android Windows Phone
Windows Mobile
Windows Linux
Runtime SDK • Objective C
Runtime SDK • Java
Runtime SDK • Silverlight
Runtime SDK • .NET
Runtime SDK • WPF, Java
Runtime SDK • Java
Core Runtime
Runtime Architecture
Windows Mobile
Windows Phone
Remote Server
Geocoding Mapping
GP Editing
Runtime Core
Tile Package
OpenGL
GPS
DirectX
Messaging Advanced Symbology
Server Sync Offline Routing
Spatial analysis Offline Geocoding
Native platform
capabilities iOS Android
WPF Java Local Server
Geocoding Mapping
GP Editing
SDK Release Status
• ArcGIS for Android SDK - 1.0 – current (12/11) – 1800 unique installs - 1.1 to be released next week
- Multiple maps - Advanced symbology/message processing - ArcGIS Online/Portal & webmap loading - Group layer - Improved secure service framework - Supports ADT r17
- 1.x/2.0 summer
Connected editing
Editing
• AttributeEditor & GeometryEditor samples in SDK • Uses Feature Service
- Same model as other webapis - applyEdits()
• AttributeEditor sample
- check field data types - Data entry - Validation
Geometry Editing Sample
• Uses a “sketch” graphics layer - Uses MapOnTouchListener
- Implements tap and drag events
• Track local edit history yourself • Uses local GeometryEngine
- No server call
FeatureLayer.applyEdits() method
• Aynchronous method - CallbackListener / AsynTask - Callback tells success for each feature
• applyEdits(adds, deletes, updates, callback)
• Attribute updates - Graphic - only changed attributes & ID
Offline capabilities
What can you do offline today?
In memory feature layers
Query attributes offline
Store features in ArcGIS db
Base maps Geometry operations Message Processing
Advanced symbology
Sync offline data with server
Routing Geocoding
See the futures section at the end for news on this stuff!
Adding base maps
• As seen in part I • Local tiled layers
- compact caches – from 10.0 server - NOT 10.1 TPKs [yet]
- Fat32 4GB file size limit
baseMapLayer = new ArcGISLocalTiledLayer(”file:///mnt/sdcard/<CacheName>/Layers", false);
Offline features
A • Use in memory “feature collection” Feature Layer
- Feature set [array of features] - Layer definition [json from a feature service]
• Change features using: - addGraphic() / removeGraphic() methods - applyEdits() method [new in 1.1 for feature collection!]
• Write features to/from disk in json [new in 1.1!] B • Graphics layers
- Add/remove graphics C
• Advanced Symbology - Process messages
Offline features code examples
<!—strings.xml--> <string name="config.windturbine.layer.definition"> {\"currentVersion\":10.01,\"id\":0,\"name\":\"Wind Turbine\”… </string>
featureLayer.addGraphics(graphics); //or Graphic[] graphics = new Graphic[ g ]; featureLayer.applyEdits( //adds graphics, //updates, //deletes);
//Java class turbinesFeatureLayer = new ArcGISFeatureLayer(R.string. config.windturbine.layer.definition, FeatureSet, null);
Create the layer…
(Demo app is different, creates layer then loads json features, then adds features) Add/edit features…
to/fromJson
• Jackson JsonParser • Serialize to disk
- FeatureSet.toJson(); - String - JsonGenerator.writeRawValue();
• Read from disk - Passed to activity in a bundle - FeatureSet.fromJson(jsonParser, hasSpatialRef);
File jsonFile = bladeRunnerApp.getJSONFile(BladeRunnerApplication.teamAreasName); JsonFactory jsonFactory = new JsonFactory(); JsonParser jsonParser = jsonFactory.createJsonParser(jsonFile); FeatureSet featureSet = FeatureSet.fromJson(jsonParser, true);
Will Crick
Blade Runner demo
Message Processing
• Add features to the map via a message - Radio/UDP/wifi - Different actions, add/update/delete - Different message types - Requires an initialized group layer
• Support for advanced symbology - Based on symbol packages (dictionary .dat files) - 2525c Military symbology (new in 1.1) - Build your own custom dictionary (future release)
- Needs desktop support
Message Processor Workflow
• MessageProcessor processes a message from an external resource
• DictionaryType enum dictates message format • DictionaryType is backed by a resource bundle
- Dictionary data file - Message file types
• MessageProcessor bound to a Group Layer - Used to display, update, and remove MultilayerSymbol
Message Processing Code example
MapView map = (MapView)findViewById(R.id.map); final GroupLayer groupLayer = new GroupLayer(); map.addLayer(groupLayer); try { MessageProcessor processor = new MessageProcessor(DictionaryType.Mil2525C, groupLayer); } catch (FileNotFoundException e) { e.printStackTrace(); }
Create a MessageProcessor Object
Message Processing Code example
// Message creation Message lmessage = new Message(); UUID luuid = UUID.randomUUID(); lmessage.setID(luuid.toString()); lmessage.setProperty("_Type", "position_report"); lmessage.setProperty("_Action", "update"); String controlpoints = x1 + "," + y1; lmessage.setProperty("_Control_Points", controlpoints); lmessage.setProperty("sic", "SFGPUCRRL--E---"); lmessage.setProperty("_WKID", "3857"); lmessage.setProperty("UniqueDesignation", "2020"); // process message and add point processor.processMessage(lmessage);
Create a Message object Process it!
Update Graphics
• Get GraphicLayer from GroupLayer • Get Graphic from GraphicsLayer • Get Geometry from Graphic • Set Property with update • Process messsage
Message message = processor.createMessageFrom(gr); String controlPoints = (String)message.getProperty( MessageHelper.MESSAGE_2525C_CONTROL_POINTS_PROPERTY_NAME); if (targetcontrolpt !=null) { message.setProperty( MessageHelper.MESSAGE_2525C_CONTROL_POINTS_PROPERTY_NAME, targetcontrolpt.getX() + "," + targetcontrolpt.getY()); } message.setProperty("_Action", "update"); processor.processMessage(message);
Dan O’Neill
Message processing demo
Platform integration Will Crick
Using the GPS
• Wraps Android Location Service • Adds useful functions
- Symbol - Accuracy [changed at 1.1] - Auto pan
LocationService ls = map.getLocationService(); ls.setSymbol(symbol); ls.setAccuracyCircleOn(true); ls.setBearing(false);
(Demo app uses simulated location to make things easier!)
Compass sensor integration
• Use SensorManager to get access to sensors • Create Sensor object ( TYPE_ORIENTATION /
getOrientation() ) • Register SensorEventListener with SensorManager
public void onSensorChanged(SensorEvent event) { sensorValues = event.values; map.setRotationAngle(sensorValues[0]); }
Bluetooth devices
• Laser range finder to add a point using an offset
• Get BlueToothDevice from BlueToothAdapter(String address)
• Create a custom service (BlueToothSerialService) - reads bytes from a socket - send bytes in a message to MapViewActivity Handler
- Converts to string buffer - Reads LSR sentence
- Uses local method/ (maths) to create point from offset - PointFromOffset will be in future version of SDK
Blade Runner app code
ArcGIS Portal (new in 1.1)
Dan O’Neill
Portal API basics
• Organization - Part of portal created for specific entity - Configurable site - Invite and manage users
• Groups and Users - Collaboration with other portal users - Exchange content related to activities/projects
Accessing a Portal
• Portal Class - Entry point - Instantiate with credential or as guest - 2 cases
- 1. Organization account - 2. Portal
- If credential provided automatically connects to Organization account
Workflow
• Create a Portal • Get the feature group query list with portalinfo • Loop through the list of queries and retrieve each
group • For each group get the title and thumbnail • Update the View with the results
Portal connection
//set up portal portalUrl = "https://csf.maps.arcgis.com/"; credentials = new UserCredentials(); credentials.setUserAccount("mobile_org", "dev.team"); //create a new instance of portal Portal.newInstance(portalUrl, credentials, new PortalListener<Portal>() { @Override public void onError(Throwable e) { e.printStackTrace(); } @Override public void onCallback(Portal portal) { ... });
Create the portal with credentials and Portal URL
Search Portal
PortalQueryParams queryParams = new PortalQueryParams(); queryParams.setQueryForItemsInGroup(groupId); // You can also create your custom PortalQueryParams object PortalQueryParams queryParamS = new PortalQueryParams(); // Once you have the query parameter string, // you can make the query on the portal. portal.findItems(queryParams, portalListener);
• Construct query string - PortalQueryParams methods return query strings - findItemsWithQueryParams queries items and groups
• Find list of items in a group
Dan O’Neill
ArcGIS Portal demo
Best Practice
ArcGIS for Android Layer performance • Try to minimize traffic
- Requests are expensive - Processing of results cost
• ArcGISFeatureLayer - types - Snapshot / feature collection - On Demand - Selection
• TileLayer (ArcGIS, Bing) - Static - Also have dynamic access
• Dynamic map service layer - Image only
• ArcGISLocalTiledLayer - No network requests!
Combine together
The importance of the UI Thread
• Work with Views on the UI Thread • Async methods are common
- Run in other threads
• Options - AsyncTask
- Handler() – bound to creation thread - Processed in a queue - messages & runnables
- View.runOnUiThread(new runnable(){…})
- ExecutorService
- Threads
OS support
• 2.2 25%!
Device & OS support
• Single app deployment - UI = fragments/different views
• Compatibility libraries - Fragments 1.6+ - Action Bar 3.0+
• Some devices don’t have features - cameras/gps
• Deployment - Manifest settings are really important
• Localisation means global…
The future
Future releases
• Playing iOS catchup J - Open Streetmap layer - NAServer task - Wrap around - Navigation modes
• 10.1 server support - Editor tracking - Replica service
- Also local data storage and a sync api - Related tables!!!
• Online features - Wms/wmts/kml - Csv by ref
• Runtime…………..
Summary info
• Where to get more info - Resource centre - http://resources.arcgis.com/content/arcgis-
android/sdk - Blog -
http://blogs.esri.com/esri/arcgis/category/mobile/ - Forum - http://forums.arcgis.com/forums/139-ArcGIS-Runtime-SDK-for-
Android - Last resort [email protected]
• Where to get code - We will post demo app to arcgis online android group shortly - http://www.arcgis.com/home/group.html?owner=willcrick&title=Android
Questions??
• All yours….