Select to view content in your preferred language

Problem Switching between ArcGISTiledMapServiceLayer, first one always loads.

6127
10
Jump to solution
03-05-2015 09:52 PM
omega_cancer
Frequent Contributor

I want to add two ArcGISTiledMapServiceLayer in my mapView. It seems that only one that gets added first to mapView is loading, later one does not get displayed.

Do anybody face problem switching between two ArcGISTiledMapServiceLayers.

Is there any limit to have only one ArcGISTiledMapServiceLayer in map.  I have tried removing the layer too.

Here is what I am doing

 Button b1 =null;
    Button b2 =null;
    MapView mMapView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mMapView = (MapView)findViewById(R.id.map);
        b1 =(Button) findViewById(R.id.button);
        b1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMapView.removeAll();
                ArcGISTiledMapServiceLayer tileLayer1 = new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/ESRI_StreetMap_World_2D/MapServer");
                mMapView.addLayer(tileLayer1);
                mMapView.setMaxExtent(tileLayer1.getFullExtent());
                mMapView.setMinScale( tileLayer1.getMinScale());
                mMapView.setMaxScale(tileLayer1.getMaxScale());
            }
        });
        b2 =(Button) findViewById(R.id.button2);
        b2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMapView.removeAll();
                ArcGISTiledMapServiceLayer tileLayer = new ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer");
                mMapView.addLayer(tileLayer);
                mMapView.setMaxExtent(tileLayer.getFullExtent());
                mMapView.setMinScale( tileLayer.getMinScale());
                mMapView.setMaxScale(tileLayer.getMaxScale());
            }
        });
}

<!-- MapView -->
    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="tileLayer1"
        android:id="@+id/button"
        android:layout_gravity="bottom" />
    <com.esri.android.map.MapView
        android:id="@+id/map"
        android:layout_width="134dp"
        android:layout_height="405dp"
        android:layout_weight="4" />
    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="tileLayer"
        android:id="@+id/button2"
        android:layout_gravity="bottom" />

tileLayer does not get loaded and tileLayer1 always gets loaded when I click on tileLayer button and vice versa.

Please guide me.

1 Solution

Accepted Solutions
ShellyGill1
Esri Contributor

Hi,

I can see from the rest endpoints that the two services in your example have different spatial references. Tiled layers cannot be reprojected, and the MapView cannot change it's spatial reference once it's set, so I am guessing that's why you cannot see the second layer. So if switching fragments does not work for you, you could try replacing the MapView entirely if you want to make a change like this one, or maybe you can use services which support the same spatial reference?

View solution in original post

10 Replies
ÅsaWegelius
Deactivated User

I dont know if it works (have not tried it myself) or if it helps you but they have an example that shows how to switch maps:

https://developers.arcgis.com/android/sample-code/switch-maps/

0 Kudos
ÅsaWegelius
Deactivated User

You could also try if mapoptions like they explains here works: MapView | ArcGIS Android 10.2.5 API

MapOptions streets = new MapOptions(MapType.STREETS);
mapView
.setMapOptions(streets);

omega_cancer
Frequent Contributor

I want to use my own server, then what?

0 Kudos
omega_cancer
Frequent Contributor

Yes it works, I have tested it, but in that examples whole fragment is being replaced with newer one rather than changing just URL.

ÅsaWegelius
Deactivated User

Im curious, If I should have tried the same I too would have assumed that removeAll() and then addLayer() would do the trick. So the question is... what do you use removeAll() to?

0 Kudos
ShellyGill1
Esri Contributor

Hi,

I can see from the rest endpoints that the two services in your example have different spatial references. Tiled layers cannot be reprojected, and the MapView cannot change it's spatial reference once it's set, so I am guessing that's why you cannot see the second layer. So if switching fragments does not work for you, you could try replacing the MapView entirely if you want to make a change like this one, or maybe you can use services which support the same spatial reference?

imritanshu
Regular Contributor

Hii Shelly Gill,

I am also getting one error please help me to resolve this problem. I am using ArcGIS Android SDK 10.2.4.

I have added a feature layer on my map. and i am trying to get popupinfo for this layer.

But this method always give me null value.

while if i am using same method for webmap it gives me proper value.

Please help me to solve this problem.

Your help will be most appreciate.

Waiting for your reply.

Thank you,

Regards

0 Kudos
RobertBares
Deactivated User

Could you please clarify where/whether this is described in the actual documentation.

0 Kudos
HassanJamil
Deactivated User

I am also facing the similar issue. In my case, I am using Fragments which contain MapViews in their xml layouts of different screen dimension according to my app's design.
Only the MapView is working for the fragment which is loaded first. Other Fragment's MapViews (when initiated) are just showing the reflection of initiated MapView (of firstly loaded fragment). But when I get my app's resume state back after having its pause the MapView of the other fragment (top fragment of back stack) is working fine as it should be.

Tried alot to come over this issue but still having it, can you/anybody please help me out?
It will be more than appreciated.


MapView's second xml layout is not working properly when adding its fragment

0 Kudos