Search code examples
androidgeoserver

I want to publish geosever layer in android app, using arcgis SDK, i have done code but it is not working, please tell me what i am doing wrong?


I am doing Android programming for the first time, I want to display a GeoServer layer using the ArcGis SDK map layer. I have done the code but it is not working, please tell me what i am doing wrong.

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.subrata.mymap.MainActivity">

<com.esri.android.map.MapView
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapoptions.MapType="Aerial"
    mapoptions.center="28, 77"
    mapoptions.ZoomLevel="10">
</com.esri.android.map.MapView>
</RelativeLayout>

mainactivity.java

package com.example.subrata.mymap;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import com.esri.android.map.MapView;
import com.esri.android.map.ogc.WMSLayer;


public class MainActivity extends AppCompatActivity {
MapView mMapView;
WMSLayer wmsLayer;
String wmsURL;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mMapView = (MapView)findViewById(R.id.map);

    wmsURL = "http://localhost:8081/geoserver/NFR-SR/wms";
    wmsLayer = new WMSLayer(wmsURL);
    wmsLayer.setImageFormat("application/openlayers");
    // available layers
    String[] visibleLayers = {"NFR-SR:Ridgeline_SR"};
    wmsLayer.setVisibleLayer(visibleLayers);
    wmsLayer.setOpacity(0.5f);
    mMapView.addLayer(wmsLayer);


    mMapView.setEsriLogoVisible(false);
    mMapView.enableWrapAround(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
}

Solution

  • Can't really tell what you mean by not working without any log or explanation. Here are some possible reason:

    1. cannot reach server at url http://localhost:8081/geoserver/NFR-SR/wms
    2. layer name NFR-SR:Ridgeline_SR not found
    3. map service doesn't support application/openlayers
    4. It could even be it is working but you are viewing the map extent which does not contain any data.