Select to view content in your preferred language

How to change feature order in layer

902
2
10-25-2018 12:40 AM
MichaelMoor
New Contributor II

Hi!

i have a Feature Layer witch can contain overlapping features (all the same colour).

When the user tapps on the features i'll show him a "feature chooser" to select only one feature.

But if the selected feature is smaller than an overlapping one and is beneath the bigger feature, the user can't see the selected feature at all.

How can i lift the selected feature higher? (See "SelectedFeature.png")

Thanks for your help!

0 Kudos
2 Replies
JakeShapley
New Contributor III

Hi Michael,

We have a similar scenario on a project we're working on. I'm just using an AGSGraphicLayer, rendered on top of the feature layer, to copy the selected feature into temporarily. In your case, once user has selected feature they want:

1) Create either AGSSimpleRenderer or just symbol to make the feature a different color, etc. Here are a couple examples of renderers that illustrate how to do either:

   

var municipalityPointRenderer: AGSSimpleRenderer {

        let symbol = AGSPictureMarkerSymbol(image:  imageLiteral(resourceName: "townSymbol"))

        symbol.height = 10.0

        symbol.width = 10.0

        let renderer = AGSSimpleRenderer(symbol: symbol)

        return renderer

    }

    

var municipalityPolyRenderer: AGSSimpleRenderer {

        let lineSymbol = AGSSimpleLineSymbol(style: .solid, color: UIColor(red: 51/255, green: 51/255, blue: 51/255, alpha: 0.0), width: 1)

        let fillSymbol = AGSSimpleFillSymbol(style: .solid, color: UIColor.clear, outline: lineSymbol)

        let renderer = AGSSimpleRenderer(symbol: fillSymbol)

        return renderer

    }

2) Create a new AGSGraphic from feature. Here is an example, where feature is AGSArcGISFeature from AGSIdentifyLayerResult. Note, that you could assign a symbol here if you weren't using a renderer:

let selectedFeature = AGSGraphic(geometry: feature.geometry, symbol: nil, attributes: feature.attributes as? [String : Any])

3) Create a new AGSGraphicsOverlay, add the graphic from step 2 to it, assign the renderer and add it to the mapView:

let selectedLayer = AGSGraphicsOverlay()

selectedLayer.graphics.add(selectedFeature)

selectedLayer.renderer = EsriUtil.municipalityPointRenderer

self.mapView.graphicsOverlays.add(selectedLayer)

4) Remove the overlay when user deselects, or selects another. If you have a single overlay, you can simply remove them all. You will need to adjust based on how your mapView, and overlay are referenced:

self?.mapView.graphicsOverlays.removeAllObjects()

Hope this helps. Let me know if you have any questions.

Cheers,

Jake

MichaelMoor
New Contributor II

Hi Jake!

it works perfectly! thank you for your detailed answer!

Cheers,

Mike

0 Kudos