Select to view content in your preferred language

FeatureLayer MaxAllowableOffset: Making it dynamic and making it work

3638
2
11-15-2011 11:17 AM
deleted-user-Ohz6rwd1kavx
Deactivated User
Hi All,

I've put in quite a few hours trying to use the ESRI SL 2.2 api FeatureLayer with MaxAllowableOffset to simplify the geometry of a client-side polygon layer.

My question is: how can I make this work dynamically so that I can re-calc MaxAllowableOffset for given map extent/resolution.

Details:

I'm trying to follow the work of others including Dereck Swingley (ESRI) and Stephen Lead to change FeatureLayer.MaxAllowableOffset based on the current map extent. I fully understand the _idea_, but I can't make it work. Nobody has posted SL specific guidelines/working example that I have found.

I can make this work with a fixed value, but I want to make it dynamic based on current Map.Extent (or Map.Resolution).

The specific problem with my dynamic solution is: layer doesn't update after I set a new value for MaxAllowableOffset. Once it draws with some level of detail, it just stays that way.

My questions:

1) What event should I listen to set new value for MaxAllowableOffset?

I have tired Map.ExtentChanged as well as Map.ExtentChanging.

Neither of these worked perfectly. The latter seems really "chatty", firing a dozen or so times during a zoom.

Is there a layer event I can listen to, perhaps UpdateCompleted?

2) What featurelayer method(s) do I need to call after setting MaxAllowableOffset. Refresh? Initialize? None?

3) FeatureLayer.Mode

I have tried both .OnDemand and .Snapshot for this member without success.

4) FeatureLayer.OnDemandCacheSize

I have tried several values here including a large value like 10,000 as well as 0. They don't seem to have any effect.

5) Other than a) picking one MaxAllowableOffset for my layer or b) generalizing my source data to different levels of detail in the underlying map service, is another approach out there that I'm missing?

Reference

http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2011/06/13/Feature-layers-can-generalize-geomet...
0 Kudos
2 Replies
deleted-user-Ohz6rwd1kavx
Deactivated User
Hi All

I was able to make this work.

Here's what I did:

1) When creating FeatureLayer
-set Mode = OnDemand
-set MaxAllowableOffset to initial value based on Map.Resolution

2) Listen to Map.ExtentChanged

3) On MapExtentChanged

featureLayer.ClearGraphics();
featureLayer.MaxAllowableOffset = maxOffset; // new value calculated from Map.Resolution
featureLayer.Initialize(); // is this necessary?


The above works.

A few additional tips:
-here is my GetMaxOffset

public static double GetMaxOffset(double mapResolution, double pixelTolerance)
        {
            // alternate algorithm where map is ESRI map control
            //maxOffset = Math.Floor(map.Extent.Width / map.ActualWidth) * pixelTolerance;
            
            return mapResolution * pixelTolerance; // means n pixels between vertices?
        }


-In OnExtetChanged, I don't recalc/reset maxoffset if the map scale hasn't changed. Use ESRI ExtentEventArgs to help you with this.

-Also, I found that I didn't want to recacl maxoffset on every single scale change. I "smoothed" the infinite number of resolutions to a fixed number of resolutions (think scale bands in a multi-scale map service). This resulted in less re-querying of data from the server... as with anything, it seems there's a balance between providing many levels of detail to user (nice to look at), and querying data (not nice to wait for).

Hope this helps someone.

-Cory
0 Kudos
PeterCornelius
Deactivated User
Hi Cory,
I was struggling to make this work for the last few hours and then found your post. I've got it working now too, so thankyou. I didn't need the initialise event. As you say, I'll need to work out what ranges to apply so it doesn't change the offset on every extent change, but otherwise it does the job and and is the easiest way of doing generalised boundaries that I've seen so far.

Peter
0 Kudos