Shapefile not visible after add to the map

3406
2
07-03-2015 02:02 AM
kkkk1
by
New Contributor II

I tried to add some local shapefile data to the map, and I use the ShapefileFeatureTable, however it does not work, core codes:

mMap = (MapView) root.findViewById(R.id.mapView);

try {
  ShapefileFeatureTable sft = new ShapefileFeatureTable(path);
  Renderer renderer = RendererHelper.getRender(sft.getTableName(), sft.getGeometryType());
  FeatureLayer featureLayer = new FeatureLayer(sft);
  featureLayer.setRenderer(renderer);
   mMap.addLayer(featureLayer);
} catch (Exception e) {
  Toast.makeText(getActivity(), "Error:" + e.getMessage(), Toast.LENGTH_LONG).show();
}

public class RendererHelper {
   public static Renderer getRender(String tableName, Geometry.Type type) {
  List<Symbol> list = new ArrayList<>();
   switch (type) {
   case POINT:
   case MULTIPOINT:
  SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.RED, 20, SimpleMarkerSymbol.STYLE.CIRCLE);
  list.add(sms);
   break;
   case LINE:
   case POLYLINE:
  SimpleLineSymbol sls = new SimpleLineSymbol(Color.RED, 5, SimpleLineSymbol.STYLE.DOT);
  list.add(sls);
   break;
   case POLYGON:
  SimpleFillSymbol ps = new SimpleFillSymbol(Color.RED, SimpleFillSymbol.STYLE.SOLID);
  SimpleLineSymbol pl = new SimpleLineSymbol(Color.RED, 1, SimpleLineSymbol.STYLE.DOT);
  list.add(ps);
  list.add(pl);
   break;
  }

   return new SimpleRenderer(new SimpleFillSymbol(Color.RED, SimpleFillSymbol.STYLE.SOLID));
  }
}

Now I meet  two problems:

1 The shapfile is not visible in the map

2 As shown the simpleRenderer does not support the compositesymbol(it will show the json erro)

What's going on?

Tags (1)
0 Kudos
2 Replies
CamiloMedina
New Contributor

Hey buddy... Did you manage to get it work loading the ShapeFile?kk kk

0 Kudos
WillCrick
Occasional Contributor

Can you confirm what spatial reference your mapview is in (its based on the first layer you add, typically the basemap layer) and the spatial reference of the shapefile? They will need to match for this to work, we do not re-project shapefiles due to performance issues.

0 Kudos