ThinkGeo.com    |     Documentation    |     Premium Support

Determine ZoomLevel from within FeatureSource

Hey


I was wondering how to determine the zoomlevel from within the GetFeaturesInsideBoundingBoxCore method on a custom featuresource? My brain is not connecting the dots today, and I can't see the solution without passing the value in. I know there is a better approach that I haven't thought of.



Brendan, 
  
 Inside the FeaturesSource?  This object has no idea of a zoom level, it is one level too low.  If you mean the FeatureLayer I can help you.  If you mean the scale I can help with that also. 
  
 If you mean the FeatureLayer then you can call the ZoomLevelSet.GetScaleToDraw or something.  There is also a GetZoomLevelSet or something.  The first gets one for drawing and if you dont have any styles set it can pass back null.  The second will always give you a zoom level back even if it wont draw. 
  
 If you want to get the scale then you can use the ExtentHelper static class and there is some kinda method on it.  You need to pass in the extent, and I think the map unit along with the height and width of the map in pixels. 
  
 Hope this help.  If not let me know a little more about what you are doing. 
  
 David

Thanks for that. At least my eyes weren't deceiving me.  



Is there an event that I can tap into in the FeatureLayer that I can use to pass into my FeatureSource? I'm thinking that if I override the DrawCore event on the FeatureLayer, I can use that to set a property on the FeatureSource. DrawCore seems to fire not only for GetFeaturesInsideBoundingBoxCore, but that shouldn't hurt. the main point is that it seems to fire at least once before the GetFeaturesInsideBoundingBoxCore method. 



Background: I've created my own FeatureSource for my own data format (shape files couldn't quite cut it for the project requirements). With that, I needed to add some functionality based on the zoomlevel that the user is at when retrieving data in the GetFeaturesInsideBoundingBoxCore method.



Overriding the DrawCore method worked for me.

Brendan, 
  
   Yep the DrawCore of your specific FeatureLayer is the way to go.  The logic to look at the zoom levels and determine if you need to draw should go there.  In the FeatureSource you should just have logic to get the data.  The FeatureSource should not know or care about thinks like zoom level etc.  Think of it as a data provider.  The object that knows about zoom levels is the Layer.  This is where allot of you optimization should be that deals with the scale and if if the styles need to draw.  We separate them out this way because a FeatureSource by itself can be very useful as an engine to drive other things without being burdened by allot of drawing logic. 
  
 David

Thanks for the explanation.

Brendan, 
  
   My pleasure. 
  
 David