Search code examples
androidesriesri-maps

Changing icons for markers in a ESRI feature layer based on attribute values


I have an esri feature layer with multiple attributes in it.

i need to set different icons to its marker based on one of the attribute value,

is it possible to have multiple renderers for the same layer based on some codition ?

this is what i have tried

QueryParameters parameters = new QueryParameters();
    parameters.setWhere("1=1");
    parameters.setReturnGeometry(true);
    parameters.setOutFields(mHafilatLayerOptions.outFields);
    parameters.setOutSpatialReference(_mapView.getSpatialReference());

    try {
        QueryTask queryTask = new QueryTask(mHafilatLayer.getUrl(),Utilities.getUserCredentials());
        queryTask.execute(parameters, new CallbackListener<FeatureResult>() {
            @Override
            public void onCallback(FeatureResult objects) {
                for (Object currentElem : objects) {
                    if (currentElem instanceof Feature) {
                        Feature currentFeature = (Feature) currentElem;

                        Point point = GeometryEngine.project(((Point)currentFeature.getGeometry()).getX(),
                                ((Point)currentFeature.getGeometry()).getY(), _mapView.getSpatialReference());
                        String deviceType = (String) currentFeature.getAttributes().get("DEVICE");

                        switch (deviceType) {
                            case "TVM":
                                mHafilatLayer.addGraphic(new Graphic(point,Utilities.createPictureMarkerSymbol(getPointOfInterestIcon(AppConstants.LayerConstants.PARKING_HANDICAP, true),false)));
                                break;
                            case "BBR":
                                mHafilatLayer.addGraphic(new Graphic(point,Utilities.createPictureMarkerSymbol(getPointOfInterestIcon(AppConstants.LayerConstants.HafilatKiosks, true),false)));
                                break;
                            case "TOM":
                                mHafilatLayer.addGraphic(new Graphic(point,Utilities.createPictureMarkerSymbol(getPointOfInterestIcon(AppConstants.LayerConstants.HafilatKiosks, true),false)));
                                break;
                            default:
                                mHafilatLayer.addGraphic(new Graphic(point,Utilities.createPictureMarkerSymbol(getPointOfInterestIcon(AppConstants.LayerConstants.HafilatKiosks, true),false)));
                        }
                    }
                }
            }

            @Override
            public void onError(Throwable throwable) {

            }
        });
    } catch (EsriSecurityException e) {
        e.printStackTrace();
    } 
    mHafilatLayer.setRenderer(new SimpleRenderer(Utilities.createPictureMarkerSymbol(getPointOfInterestIcon(AppConstants.LayerConstants.HafilatKiosks, true), false)));

this doesnt work,any help is highly appreciated .


Solution

  • Set different icons to its marker based on one of the attribute value - Yes possible.

    ArcGIS has option to render based on the attribute in featurelayer, Eg : Unique Value renderer

    Check out the link : https://developers.arcgis.com/android/latest/guide/symbols-and-renderers.htm#ESRI_SECTION1_93757B8F4FBF45CB8D0ED7DCCE53D929