private void initializeLayers() {

        switchTileLayer(Settings.getMapSource());

        // History Layer
        this.historyLayer = new HistoryLayer(trailHistory);
        this.mapView.getLayerManager().getLayers().add(this.historyLayer);

        // RouteLayer
        this.routeLayer = new RouteLayer(realRouteDistance -> {
            if (null != this.distanceView) {
                this.distanceView.setRouteDistance(realRouteDistance);
            }
        }, this.mapHandlers.getTapHandler(), mapView.getLayerManager());
        this.mapView.getLayerManager().getLayers().add(this.routeLayer);

        //GeoobjectLayer
        this.geoObjectLayer = new GeoObjectLayer();
        this.mapView.getLayerManager().getLayers().add(this.geoObjectLayer);

        // TrackLayer
        this.trackLayer = new TrackLayer();
        this.mapView.getLayerManager().getLayers().add(this.trackLayer);

        // NavigationLayer
        Geopoint navTarget = lastNavTarget;
        if (navTarget == null) {
            navTarget = mapOptions.coords;
            if (navTarget == null && StringUtils.isNotEmpty(mapOptions.geocode)) {
                final Viewport bounds = DataStore.getBounds(mapOptions.geocode);
                if (bounds != null) {
                    navTarget = bounds.center;
                }
            }
        }
        this.navigationLayer = new NavigationLayer(navTarget, realDistance -> {
            if (null != this.distanceView) {
                this.distanceView.setRealDistance(realDistance);
            }
        });
        this.mapView.getLayerManager().getLayers().add(this.navigationLayer);

        // GeoitemLayer
        GeoitemLayer.resetColors();

        // Coords marker
        this.coordsMarkerLayer = new CoordsMarkerLayer();
        coordsMarkerLayer.setCoordsMarker(coordsMarkerPosition);
        this.mapView.getLayerManager().getLayers().add(this.coordsMarkerLayer);

        // TapHandler
        this.tapHandlerLayer = new TapHandlerLayer(this.mapHandlers.getTapHandler(), this);
        this.mapView.getLayerManager().getLayers().add(this.tapHandlerLayer);

        // Caches bundle
        if (mapOptions.searchResult != null) {
            this.caches = new CachesBundle(this, mapOptions.searchResult, this.mapView, this.mapHandlers);
        } else if (StringUtils.isNotEmpty(mapOptions.geocode)) {
            if (mapOptions.mapMode == MapMode.COORDS && mapOptions.coords != null) {
                this.caches = new CachesBundle(this, mapOptions.coords, mapOptions.waypointType, mapOptions.waypointPrefix, this.mapView, this.mapHandlers, mapOptions.geocode);
            } else {
                this.caches = new CachesBundle(this, mapOptions.geocode, this.mapView, this.mapHandlers);
            }
        } else if (mapOptions.coords != null) {
            this.caches = new CachesBundle(this, mapOptions.coords, mapOptions.waypointType, mapOptions.waypointPrefix, this.mapView, this.mapHandlers, null);
        } else {
            caches = new CachesBundle(this, this.mapView, this.mapHandlers);
        }

        // Stored enabled map
        caches.handleStoredLayers(this, mapOptions);
        // Live enabled map
        caches.handleLiveLayers(this, mapOptions);
        caches.setFilterContext(mapOptions.filterContext);

        // Position layer
        this.positionLayer = new PositionLayer();
        this.mapView.getLayerManager().getLayers().add(positionLayer);

        //Distance view
        this.distanceView = new DistanceView(findViewById(R.id.distanceinfo), navTarget, Settings.isBrouterShowBothDistances());

        //Target view
        this.targetView = new TargetView(findViewById(R.id.target), StringUtils.EMPTY, StringUtils.EMPTY);
        final Geocache target = getCurrentTargetCache();
        if (target != null) {
            targetView.setTarget(target.getShortGeocode(), target.getName());
        }

        // resume location access
        resumeDisposables.add(geoDirUpdate.start(GeoDirHandler.UPDATE_GEODIR));
    }
Get the current map state from the map view if it exists or from the mapStateIntent field otherwise.

@return the current map state as an array of int, or null if no map state is available
main/src/main/java/cgeo/geocaching/maps/mapsforge/v6/NewMap.java