Select to view content in your preferred language

Trouble to access contents of a feature

1241
5
03-04-2020 12:45 PM
JulienHaccoun
Emerging Contributor

Hello,

I am using Java Runtime 100.7.

I have trouble with the WebMap which ID is ca8a15ea0bc2413396c322198d50fd1e. 
I can access it via AuthenticationManager. I am trying to see the selected feature when I click on a layer, but it seems the IdentifyLayerResult of his particular WebMap do not have the GeoElement necessary to read informations.
Specifically I am trying to get access to this kind of informations:
To access to the GeoElement, I am using this code:
mapView.setOnMouseClicked(event -> {
// check for primary or secondary mouse click
if (event.isStillSincePress() && event.getButton() == MouseButton.PRIMARY) {
// create a point from where the user clicked
Point2D point = new Point2D(event.getX(), event.getY());

// identify the clicked features
final ListenableFuture<List<IdentifyLayerResult>> results = mapView.identifyLayersAsync(point, 10,
false, 10);
results.addDoneListener(() -> {

// System.out.println("Listener");

try {

List<IdentifyLayerResult> ListLayer = results.get();
int j = 0;
for (IdentifyLayerResult layer : ListLayer) {

// search the layers for identified features
List<Feature> features = layer.getElements().stream()
.filter(geoElement -> geoElement instanceof Feature).map(g -> (Feature) g)
.collect(Collectors.toList());

// select features
int FeaturesSize = features.size();
for (int i = 0; i < FeaturesSize; i++) {
Feature f = features.get(i);
// printFeature_Info(f);
String attributeNamePopUp = "";
try {
attributeNamePopUp = layer.getLayerContent().getName();
} catch (java.lang.NullPointerException e) {
}
new ArcGIS_Information_Frame_For_Layer(f.getAttributes(), attributeNamePopUp);

setupGraphicsOverlay();
List<Graphic> graphics = new ArrayList<>();
graphics.add(new Graphic(f.getGeometry()));
graphicsOverlay.getGraphics().addAll(graphics);
}
}

} catch (Exception e) {
e.printStackTrace();
}
});
}
});

Thank you for your help,

Adrien.

0 Kudos
5 Replies
GayleYoung
Esri Contributor

Hi Adrien, thanks for your question.

It sounds like you have sucessfully Identified the Feature(s) you need. However, I'm not clear if this is a problem with this specifc Webmap or a problem with the type of Fields in the Feature. Do you have your code working for FeatureLayers in other Webmaps? Have a look at `com.esri.arcgisruntime.mapping.view.IdentifyLayerResult.getPopups()` which returns a 'List<Popup>'. This information can be used to create your UI..  If you need more control of the specifc popup fields then consider using something like:

```
 Popup popup = new Popup(geoElement);
 List<PopupField> fields = popup.getPopupDefinition().getFields();

```

0 Kudos
JulienHaccoun
Emerging Contributor

Hello Gayle,

Thank you for your answer.

My code does work for other WebMap.

I have checked, there are no popups affiliated with this WebMap.

I have used your method to check popups and it gave me no pop up for this webmap and for its sublayers.

0 Kudos
GayleYoung
Esri Contributor

Hi,

you'd have to check that the Fields of those Layers are as your code expects. You can see the source of the data if you go to Item Details->Layers then access the link displayed. That is https://demographics9.arcgis.com/arcgis/rest/services/USA_Demographics_and_Boundaries_2019/MapServer...

You can see that this service has 4 layers called BlockGroup. You will find the Median Houseold income listed there. The other data you see in the ArcGISOnline Popup may be configured specifically for that application and may not be part of the service data.

Regards,

Gayle.

0 Kudos
JulienHaccoun
Emerging Contributor

Thank you for your answer.

How do you go to Item Details->Layers? Is it a website? or attribute of an object?

And, in the link the gave me, I see this is a MapServer.

With this MapServer, I see, following your direction I can have access to Feature Layer. How do I get the ArcGISMap of these feature layer? Is there a PortalID?

Adrien

0 Kudos
GayleYoung
Esri Contributor

I'm assuming you can use https://www.arcgis.com/home/webmap/viewer.html?webmap=ca8a15ea0bc2413396c322198d50fd1e in ArcGISOnline. There you can see About->More Details  which takes you to the WebMap Item in ArcGISOnline; this is https://www.arcgis.com/home/item.html?id=ca8a15ea0bc2413396c322198d50fd1e. Here you will get a link to the Layers that make up the WebMap.

0 Kudos