[mapguide-users] Layer Scale and Map Rendering

TravisBrannon tbrannon at geotechsystems.com
Wed Apr 1 09:25:18 EDT 2009


Hi folks,

I am writing an application with a custom viewer to an MGOS backend, and I am having some problems with the ScaleRange with layers - the Roads layer in the Sheboygan map specifically, as this is the map I am using to test and develop with.

When I first intialize the map, I check the scale range settings in the LayerDefinition XML.  For the Roads layer the MaxScale setting is 10000.  Intuitively, I am assuming that this value is compared to the scale of the map when I call GETMAPIMAGE via the MapAgent.  For instance, if the calculated scale of the map image is 15000, then logically the Roads layer should not render.  This however is not the behavior.   

I cheked the sample viewer (not tiled) and compared the rendering behavior of the Roads layer with the scale entered in the scale section of the status bar of the sample viewer UI.  The Roads layer will render anywhere below ~1:23950.  This is a long way from 10000.  Obviously my reasoning is erroneous.    Can someone point me in the right direction please?  As a matter of convenience, I am including the code that I use to calculate the map scale before rendering the map image.  This code was adapted from the source in the OS release, so it should be fine (I think).

Thanks a bunch and I thank all of you in advance and Kenneth and Jackie who have already helped me in the recent past.  :)

Travis

public static MapGuideExtentResponse SetMapExtent(string SessionId, MgRenderingService RenderingService, MgMap Map, MgEnvelope Envelope, int Width, int Height)
        {
            MgGeometryFactory factory = new MgGeometryFactory();
            double upperRightX = Envelope.UpperRightCoordinate.GetX();
            double lowerLeftX = Envelope.LowerLeftCoordinate.GetX();
            double upperRightY = Envelope.UpperRightCoordinate.GetY();
            double lowerLeftY = Envelope.LowerLeftCoordinate.GetY();
            double x = lowerLeftX + (Math.Abs(upperRightX - lowerLeftX) / 2);
            double y = upperRightY - (Math.Abs(upperRightY - lowerLeftY) / 2);
            MgCoordinate center = factory.CreateCoordinateXY(x, y);
            MgCoordinateSystemFactory csFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem cs = csFactory.Create(Map.GetMapSRS());
            double metersPerUnit = cs.ConvertCoordinateSystemUnitsToMeters(1.0);
            int dpi = Map.GetDisplayDpi();
            double metersPerPixel = 0.0254 / dpi;
            double scale = 0.0;
            if (Height * (upperRightX - lowerLeftX) > Width * (upperRightY - lowerLeftY))
            {
                scale = ((upperRightX - lowerLeftX) * metersPerUnit) / (Width * metersPerPixel);
            }
            else
            {
                scale = ((upperRightY - lowerLeftY) * metersPerUnit) / (Height * metersPerPixel);
            }
            Envelope  env = UtilitiesCommandEngine.GetCurrentMapExtent(SessionId, Map.Name, Width, Height, dpi, x, y, scale);
            env.CurrentMapScale = scale;




-- 
View this message in context: http://n2.nabble.com/Layer-Scale-and-Map-Rendering-tp2568972p2568972.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list