Layer Min/Max scale

3484
4
Jump to solution
08-29-2013 08:32 AM
JohnWass
New Contributor III
The ability to set a min/max scale range for a layer appears to be limited to only the GraphicsLayer implementations.  Is there any plan to expand this capabiltiy to any other layers?  If so is there any estimate on when?

I suppose this is something that could be listented for and done manually with setVisible... Would be more elegant to have the setting on Layer (IMO).

Edit:  I just noticed this comment in the docs on getMin/MaxScale:  ... For service layers this is defined by the service. For a GraphicsLayer there is no minimum/maximum scale.

So maybe this doesnt work at all... havent tried it yet.
0 Kudos
1 Solution

Accepted Solutions
MarkBaird
Esri Regular Contributor
You are correct about the service layer, the min and max scale is defined by the service and at the moment you can't override the values.

GraphicLayer however should work.  I've just tried it using the following code:


        //add graphics layer with graphics
        gLayer = new GraphicsLayer();
        gLayer.setMinScale(1.4791436103807428E8);
        gLayer.setMaxScale(1.8489307722593345E7);
       
        map.getLayers().add(gLayer);
       
        //graphic
        Point pt = new Point(0,0);
        SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.red, 10, Style.CIRCLE);
        Graphic gr = new Graphic(pt, sms);
       
        gLayer.addGraphic(gr);


When I zoom in and out I can see the red marker symbol in the  graphics layer appear and disappear.

Does this help?

Mark

View solution in original post

4 Replies
MarkBaird
Esri Regular Contributor
You are correct about the service layer, the min and max scale is defined by the service and at the moment you can't override the values.

GraphicLayer however should work.  I've just tried it using the following code:


        //add graphics layer with graphics
        gLayer = new GraphicsLayer();
        gLayer.setMinScale(1.4791436103807428E8);
        gLayer.setMaxScale(1.8489307722593345E7);
       
        map.getLayers().add(gLayer);
       
        //graphic
        Point pt = new Point(0,0);
        SimpleMarkerSymbol sms = new SimpleMarkerSymbol(Color.red, 10, Style.CIRCLE);
        Graphic gr = new Graphic(pt, sms);
       
        gLayer.addGraphic(gr);


When I zoom in and out I can see the red marker symbol in the  graphics layer appear and disappear.

Does this help?

Mark
JohnWass
New Contributor III
Hey Mark thanks for the reply.  Yes that should do the trick. 

My original worry was caused because I thought I would have to check instanceof on several different Layer subclasses to know who to set a min/max on.  That was going to lead to a question about interfaces (or rather the lack of), but since GraphicsLayer is the only one that supports setting min/max scale we can push that off for another day.  GraphicsLayer will cover 95% of my use cases involving min/max scale for now so I should be good to go.

Thanks again
0 Kudos
CarlosColón-Maldonado
Occasional Contributor III
GraphicLayer however should work ...


How about MessageGroupLayer types? Currently, the only way to do this is via the json files and it's per session (requires restart).
0 Kudos
MarkBaird
Esri Regular Contributor
Yes this had been added for 10.2.  You can now write code like this:

        mgl = new MessageGroupLayer(DictionaryType.Mil2525C);
       
        mgl.setMaxScale(maxScale);
        mgl.setMinScale(minScale);

And also relating to your json file, we've also added API to alter the scale factor.  This is an overloaded constructor as altering the scale factor at runtime isn't sensible (very processor intensive).

Mark
0 Kudos