Callback listener when certain layers come into view in MapView

2261
1
12-05-2013 01:29 AM
SimKern_Cheh
New Contributor
Hi,

I was looking for some form of callback when a certain layer is in view on the mapView (i.e the user pans to the place where the layer is). However, I could not find something similar in the API reference.

The motivation behind such a callback is to dynamically change the UI based on whats being shown on the mapView. I would like to enquire if such a thing exists, and did I miss out something. Otherwise, any advice on how to go about implementing it will be greatly appreciated 🙂

Thank you!
0 Kudos
1 Reply
JasonKnisley
Occasional Contributor
I don't believe anything like that is currently baked into the API, but the building blocks for it are certainly in place. There is an isVisible() method that you can use to know when a layer is visible, but I haven't done much testing to know if this value updates automatically based on MapView scale changes or if it only updates based on programmatic changes. You'd have to test to see what gets returned with a layer is set to visible but outside of its scale range. That said, I doubt that it considers the extent at all (but I could be wrong). For that, you have a couple methods you can use. For an ArcGISDynamicMapServiceLayer, you'll want to look at getMapServiceInfo(). The MapServiceInfo object contains information about the extent of the service as well as the min and max scale at which it is visible. For an ArcGISFeatureLayer the corresponding method is getLayerServiceInfo(), which returns a LayerServiceInfo object with similar properties.

On your MapView you can then set pan and zoom listeners to iterate through your layers to see which ones are visible using a combination of isVisible() and the properties from your MapServiceInfo/LayerServiceInfo objects.
0 Kudos