Solved! Go to Solution.
The ArcGIS Runtime sample "Datasources > Add Shapefile" provide source code to select a shapefile and add it to the map based on a blank MPK (Map Package) and a map service (on the LocalServer).
From that, I would like to be able to get the Full Extent of this layer (from menu "Zoom To Layer").
In my case, I have a World wide blank MPK, so any kind of Shapefile will be loaded. basically, from 2 identical blank MPK, I can load 2 different Shapefile, one with European countries, another with USA countries.
I need to be able to zoom to first Layer on "Europe" or to second layer on "USA" !
But my issue is :
- if I try to get the full extent from the Dynamic Layer, with getFullExtent(), I will get the Envelope from the MPK which is always the World extent.
- How can I get the Full Extent from sub-layers of the dynamic layer to only get the Envelope of my Shapefile (sublayer[0]) ??
The ArcGIS Runtime sample "Datasources > Add Shapefile" provide source code to select a shapefile and add it to the map based on a blank MPK (Map Package) and a map service (on the LocalServer).
From that, I would like to be able to get the Full Extent of this layer (from menu "Zoom To Layer").
In my case, I have a World wide blank MPK, so any kind of Shapefile will be loaded. basically, from 2 identical blank MPK, I can load 2 different Shapefile, one with European countries, another with USA countries.
I need to be able to zoom to first Layer on "Europe" or to second layer on "USA" !
But my issue is :
- if I try to get the full extent from the Dynamic Layer, with getFullExtent(), I will get the Envelope from the MPK which is always the World extent.
- How can I get the Full Extent from sub-layers of the dynamic layer to only get the Envelope of my Shapefile (sublayer[0]) ??
private Envelope requestHttpExtent(final DynamicLayerInfo layerInfo, final String urlMapService) { Envelope envelope = null; try { String layerParam = layerInfo.toJson(); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(urlMapService + "/dynamicLayer?"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("layer", layerParam)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); JsonNode extentNode = parseJson(rd).findValue("extent"); if (extentNode != null) { double xMin = extentNode.findValue("xmin").asDouble(); double yMin = extentNode.findValue("ymin").asDouble(); double xMax = extentNode.findValue("xmax").asDouble(); double yMax = extentNode.findValue("ymax").asDouble(); envelope = new Envelope(xMin, yMin, xMax, yMax); } } catch (Exception e) { // do nothing envelope = null; } return envelope; }
thanks Sachin, it's working fine ! 😉
Actually, I already had part of the solution because I'm getting the Geometry Type of shapefiles the same way, but I'm still new to http request and JSon.
here's my code :private Envelope requestHttpExtent(final DynamicLayerInfo layerInfo, final String urlMapService) { Envelope envelope = null; try { String layerParam = layerInfo.toJson(); HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(urlMapService + "/dynamicLayer?"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("layer", layerParam)); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(post); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); JsonNode extentNode = parseJson(rd).findValue("extent"); if (extentNode != null) { double xMin = extentNode.findValue("xmin").asDouble(); double yMin = extentNode.findValue("ymin").asDouble(); double xMax = extentNode.findValue("xmax").asDouble(); double yMax = extentNode.findValue("ymax").asDouble(); envelope = new Envelope(xMin, yMin, xMax, yMax); } } catch (Exception e) { // do nothing envelope = null; } return envelope; }
... However, the results from the REST API query do not have the geometries (features) included. I tried to set "returnGeometry" as "true",
nameValuePairs.add(new BasicNameValuePair("returnGeometry", "true"));
but still not working.
I used StringBuilder to get the content from the BufferedReader rd
StringBuilder builder = new StringBuilder();
for (String line = null; (line = rd.readLine()) != null;) {
builder.append(line).append("\n");
}
The builder output has all the spatial reference information and fields, but no features.
Can anyone let me know how to set the parameters correctly in this case?
HttpPost post = new HttpPost(localMapService.getUrlMapService() + "/dynamicLayer/query?"