Select to view content in your preferred language

Centering a map on android device

2911
1
07-14-2014 06:22 AM
EddiePabon_Vazquez
Deactivated User

I'm creating an android application based on ArcGIS but dont know why the application does not open the data centered on the screen (map is not in the center of screen). Do you have any suggestions? Thanks

0 Kudos
1 Reply
LukeCatania
Occasional Contributor

call  initializeLayerOnStatusChangedListener(mapArcGISLocalTiledLayer) in your onCreate method passing the layer you want to center on your screen.  Set the mapView extent to that layer's full extent in the conditional block that checks to make show the map is loaded.

    void initializeLayerOnStatusChangedListener(final Layer arcGISLocalTiledLayer) {

        /*

         * Use OnStatusChangedListener to listen to

         * events such as change of status. This event allows developers to

         * check if layer is indeed initialized and ready for use, and take

         * appropriate action.

         */

        OnStatusChangedListener onStatusChangedListener = new OnStatusChangedListener() {

            private static final long serialVersionUID = 1L;

            /*

             * This callback method will be invoked when status of layer changes

             */

            public void onStatusChanged(Object arg0, STATUS status) {

                /*

                 * Check if layer's new status = INITIALIZED. If it is,

                 * set the extent.

                 */

                if (status.equals(OnStatusChangedListener.STATUS.INITIALIZED)) {

                    mapView.setExtent(arcGISLocalTiledLayer.getFullExtent());

                }

            }

        };

        arcGISLocalTiledLayer.setOnStatusChangedListener(onStatusChangedListener);

    }

0 Kudos