ESRI.ArcGIS.ADF.IMS
MaxScale Property
See Also  Example
ESRI.ArcGIS.ADF.IMS.Carto.Layer Namespace > Layer Class : MaxScale Property




Gets or sets the maximum scale at which the layer displays.

Syntax

Visual Basic (Declaration) 
Public Overridable Property MaxScale As String
Visual Basic (Usage)Copy Code
Dim instance As Layer
Dim value As String
 
instance.MaxScale = value
 
value = instance.MaxScale
C# 
public virtual string MaxScale {get; set;}

Example

The following example checks whether a layer is visible at the current map scale. If it is not visible, the map is set to match one of either the MinScale or MaxScale, and a map image is drawn and displayed in an image web control. This code assumes an existing MapView.
C#Copy Code
FeatureLayer citiesLayer = (FeatureLayer) mapView.Layers.FindByName("Cities"); 

mapView.Extent = new Envelope(-160, -80, 160, 80); 

  

// If layer is not visible at current scale,  

//  change extent to one of the scale factors 

if (!citiesLayer.IsVisibleAtScale) 



    // At least one of MinScale/MaxScale will be set if layer not visible at this scale 

    //  Note: Conversions assume scales are already in map units/pixel format 

    //  (will fail for dynamic layers if scale set with relative RF format) 

    double newScale = 0; 

    if (citiesLayer.MinScale != String.Empty) 

        newScale = Convert.ToDouble(citiesLayer.MinScale); 

    else 

        newScale = Convert.ToDouble(citiesLayer.MaxScale); 

  

     // Zoom the map to the new scale by calculating an envelope at this scale 

     double newWidth = newScale * mapView.ImageDescriptor.Width; 

     double newHeight = newScale * mapView.ImageDescriptor.Height; 

     double mapCenterX = (mapView.Extent.XMax + mapView.Extent.XMin) / 2; 

     double mapCenterY = (mapView.Extent.YMax + mapView.Extent.YMin) / 2; 

     mapView.Extent = new Envelope(mapCenterX - newWidth / 2, mapCenterY - newHeight / 2, 

        mapCenterX + newWidth / 2, mapCenterY + newHeight / 2); 



  

Image1.ImageUrl = mapView.Draw().Url; 

    
Visual BasicCopy Code
Dim citiesLayer As FeatureLayer = CType(mapView.Layers.FindByName("Cities"), FeatureLayer)

mapView.Extent = New Envelope(-160, -80, 160, 80)



' If layer is not visible at current scale,

' change extent to one of the scale factors

If Not citiesLayer.IsVisibleAtScale



    ' At least one of MinScale/MaxScale will be set if layer not visible at this scale

    ' Note: Conversions assume scales are already In map units/pixel Format

    ' (will fail For dynamic layers if scale set with relative RF Format)

    Dim newScale As Double = 0

    If citiesLayer.MinScale <> String.Empty Then

        newScale = Convert.ToDouble(citiesLayer.MinScale)

    Else

        newScale = Convert.ToDouble(citiesLayer.MaxScale)

    End If



    ' Zoom the map to the new scale by calculating an envelope at this scale

    Dim newWidth As Double = newScale * mapView.ImageDescriptor.Width

    Dim newHeight As Double = newScale * mapView.ImageDescriptor.Height

    Dim mapCenterX As Double = (mapView.Extent.XMax + mapView.Extent.XMin) / 2

    Dim mapCenterY As Double = (mapView.Extent.YMax + mapView.Extent.YMin) / 2

    mapView.Extent = New Envelope(mapCenterX - newWidth / 2, mapCenterY - newHeight / 2, _

        mapCenterX + newWidth / 2, mapCenterY + newHeight / 2)

End If



Image1.ImageUrl = mapView.Draw().Url

Remarks

This is the scale at which, as you zoom in, the layer will display. This property is usually used to hide detailed layers until the user reaches a specified zoomed-in scale.

If neither MaxScale nor MinScale are set, the layer will display at all scales. Note that scale can be set for renderers in a FeatureLayer by using ScaleDependentRenderer.

This property can be set only for dynamic layers. The ArcIMS server does not allow changing the scale factors for layers in the map service. An exception will be thrown if you attempt to set the MaxScale or MinScale for layers in the map service, or selection/buffer layers based on layers in the map service.

Scales can be set using a relative scale or by calculating the number of map units per pixel. A relative scale represents the scale in a ratio such as 1:24000. In this example, 1 meter equals 24000 meters, or 1 inch equals 24000 inches. When using relative scale, always use a colon (:) between the two values.

Map units per pixel refers to the number of meters, feet, or decimal degrees represented by one pixel in a map. To convert from a relative scale to map units per pixel, the size of a pixel must first be calculated. The formula for finding the number of meters in a pixel is 0.0254 / dpi. The value 0.0254 is the number of meters in an inch, and dpi is the dpi set in the ArcIMS service or request. If no dpi is set in the service or request, the dpi is assumed to be 96. As an example of pixel size, if the dpi is 96, the pixel size is 0.0254 / 96 or 0.000265 m. To convert from a relative scale to map units per pixel:

  • If the scale is in meters. To calculate the number of meters per pixel, take the relative scale and multiply by 0.000265. For example, if the relative scale is 1:24000, then the number of meters per pixel is 24000 * 0.000265, or 6.36 meters.
  • If the scale is in feet. Do the calculation for meters (#1). Multiply the result by 3.28 (the number of feet in a meter). For example, if the number of meters per pixel is 6.36, the number of feet is 6.36 * 3.28, or 20.86 feet.
  • If the scale is in decimal degrees. For these calculations, the Earth is assumed to be an exact sphere with a circumference of 40030.174 km. One degree is 111.195 km (40030.174/360 degrees), or 111195 meters. To calculate the number of degrees, first do the calculation for meters (#1). Next, divide the result by 111195. For example, if the number of meters per pixel is 6.36, the number of degrees is 6.36 / 111195, or 0.0000571968.

Note that for decimal degrees, the scale above will be increasingly inaccurate in the horizontal (x) dimension toward the poles. The length of a degree of longitude decreases toward the poles by the cosine of the latitude. If you want to adjust the horizontal scale for latitude, take the cosine of the latitude and multiply it times 111195. Then use this number to divide the number of meters per pixel. For example, at 40 degrees latitude north or south, the meters per degree is cos(40 degrees) * 111195 = 0.766044 * 111195 = 85180.3. If the number of meters per pixel is 6.36, the number of degrees per pixel is 6.36 / 85180.3, or 0.000074665. The scale in the vertical (y) dimension will remain at the value calculated with 111195 as above at all latitudes.

See Also

© 2010 All Rights Reserved.