AnsweredAssumed Answered

Shapefile isnt displayed on Map

Question asked by nikolas93b on Dec 19, 2016
Latest reply on Jan 16, 2017 by nikolas93b

Hello all i am trying to develop  a simple map in an Android app and add a shapefile on it using featurelayer. i have done that and is working perfect but the problem is that shapefile(featurelayer)isnt shown in map except if i delete the mapoption.Maptype  from xml File,shapefile is being displayed correctly. I hope someone have a solution for it!!

Thank you in advance

 

My Code

Java File:

public class MainActivity extends AppCompatActivity {
    MapView mMapView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // after the content of this activity is set
        // the map can be accessed from the layout
        mMapView = (MapView)findViewById(R.id.map);
        TextView test=(TextView)findViewById(R.id.textView);
        ShapefileFeatureTable shapefileFeatureTable=null;

        try {
            shapefileFeatureTable = new ShapefileFeatureTable(Environment.getExternalStorageDirectory().getPath()+"/test.shp");

        } catch (FileNotFoundException ex) {
            Toast.makeText(this, "File: not found!", Toast.LENGTH_LONG).show();
            ex.printStackTrace();
            return;
        }
        FeatureLayer featureLayer = new FeatureLayer(shapefileFeatureTable);
        featureLayer.setRenderer(new SimpleRenderer(new SimpleFillSymbol(
                getResources().getColor(android.R.color.holo_green_dark),
                SimpleFillSymbol.STYLE.SOLID)));
        if (featureLayer.getSpatialReference()==mMapView.getSpatialReference())
            test.setText("Correct Spatial Reference");
        else
            test.setText("Incorrect Spatial Reference");
        mMapView.addLayer(featureLayer);

    }
}

XML File:

<com.esri.android.map.MapView
    android:id="@+id/map"
    mapoptions.center="35, 34"
    mapoptions.ZoomLevel="10"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapoptions.MapType="oceans">
</com.esri.android.map.MapView>

Outcomes