Map service ExportScaleBar method
Generates a scale bar image for a data frame (map) in an ArcGIS Server map service.
ExportScaleBar (ScaleBar ScaleBar, MapDescription MapDescription, ImageDisplay MapDisplay, Color BackGroundColor, ImageDescription ImageDescription)
Parameter |
Description |
---|---|
ScaleBar |
Used to set custom ScaleBar properties if necessary. If ScaleBar is Nothing/Null, a default scale bar will be generated. |
MapDescription |
Used to define map properties to determine scale. |
ImageDisplay |
Used to set map image properties, such as height, width, and DPI. Used in conjunction with MapDescriptionto determine scale. |
Color |
Used to set the background color of the scale bar. By default, the background color is black. |
ImageDescription |
Used to set scale bar image properties such as height, width, image format and return type. |
Return Value
An ImageResult that references to the display properties of the generate scale bar image, such as height, width, and URL, if applicable.
Examples
C#
MapService_MapServer mapservice = new MapService_MapServer();
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer";
// Define scale bar properties
AlternatingScaleBar scalebar = new AlternatingScaleBar();
// Define Unit label
scalebar.Units = esriUnits.esriMiles;
scalebar.UnitsSpecified = true;
TextSymbol unittextsymbol = new TextSymbol();
unittextsymbol.Size = 20;
unittextsymbol.FontName = "Arial";
scalebar.UnitLabelSymbol = unittextsymbol;
scalebar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar;
scalebar.UnitLabelPositionSpecified = true;
scalebar.UnitLabelGap = 10;
scalebar.UnitLabelGapSpecified = true;
// Define bar display
scalebar.BarHeight = 8;
scalebar.BarHeightSpecified = true;
scalebar.Divisions = 4;
scalebar.DivisionsSpecified = true;
scalebar.DivisionMarkHeight = 18;
scalebar.DivisionMarkHeightSpecified = true;
scalebar.Subdivisions = 10;
scalebar.SubdivisionsSpecified = true;
scalebar.MarkPosition = esriVertPosEnum.esriBottom;
scalebar.MarkPositionSpecified = true;
SimpleFillSymbol fillsymbol = new SimpleFillSymbol();
wsmap.RgbColor fillcolor = new wsmap.RgbColor();
fillcolor.Red = 255;
fillcolor.Green = 0;
fillcolor.Blue = 0;
fillsymbol.Color = fillcolor;
scalebar.FillSymbol1 = fillsymbol;
// Define division labels
TextSymbol textsymbol = new TextSymbol();
textsymbol.Size = 20;
textsymbol.FontName = "Arial";
textsymbol.TextDirection = esriTextDirection.esriTDAngle;
textsymbol.Angle = 45;
scalebar.LabelSymbol = textsymbol;
scalebar.LabelPosition = esriVertPosEnum.esriAbove;
scalebar.LabelPositionSpecified = true;
scalebar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisions;
scalebar.LabelFrequencySpecified = true;
// Define map properties (MapDescription and ImageDisplay)
MapServerInfo mapinfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName());
MapDescription mapdesc = mapinfo.DefaultMapDescription;
ImageDisplay imgdispmap = new ImageDisplay();
imgdispmap.ImageWidth = 500;
imgdispmap.ImageHeight = 500;
imgdispmap.ImageDPI = 96;
// Define scale bar image properties (ImageDescription)
ImageType imgtype = new ImageType();
imgtype.ImageFormat = esriImageFormat.esriImagePNG;
imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL;
ImageDisplay imgdispscalebar = new ImageDisplay();
imgdispscalebar.ImageHeight = 75; //pixels
imgdispscalebar.ImageWidth = 400; //pixels
ImageDescription imgdescscalebar = new ImageDescription();
imgdescscalebar.ImageDisplay = imgdispscalebar;
imgdescscalebar.ImageType = imgtype;
// Define background color
wsmap.RgbColor backcolor = new wsmap.RgbColor();
backcolor.Red = 255;
backcolor.Green = 255;
backcolor.Blue = 255;
// Create scale bar image
ImageResult imgresult = mapservice.ExportScaleBar(scalebar, mapdesc, imgdispmap, backcolor, imgdescscalebar);
VB.NET
Dim mapservice As MapService_MapServer = New MapService_MapServer()
mapservice.Url = "http://localhost:6080/arcgis/services/MapService/MapServer"
' Define scale bar properties
Dim scalebar As AlternatingScaleBar = New AlternatingScaleBar()
' Define Unit label
scalebar.Units = esriUnits.esriMiles
scalebar.UnitsSpecified = True
Dim unittextsymbol As TextSymbol = New TextSymbol()
unittextsymbol.Size = 20
unittextsymbol.FontName = "Arial"
scalebar.UnitLabelSymbol = unittextsymbol
scalebar.UnitLabelPosition = esriScaleBarPos.esriScaleBarAfterBar
scalebar.UnitLabelPositionSpecified = True
scalebar.UnitLabelGap = 10
scalebar.UnitLabelGapSpecified = True
' Define bar display
scalebar.BarHeight = 8
scalebar.BarHeightSpecified = True
scalebar.Divisions = 4
scalebar.DivisionsSpecified = True
scalebar.DivisionMarkHeight = 18
scalebar.DivisionMarkHeightSpecified = True
scalebar.Subdivisions = 10
scalebar.SubdivisionsSpecified = True
scalebar.MarkPosition = esriVertPosEnum.esriBottom
scalebar.MarkPositionSpecified = True
Dim fillsymbol As SimpleFillSymbol = New SimpleFillSymbol()
Dim fillcolor As wsmap.RgbColor = New wsmap.RgbColor()
fillcolor.Red = 255
fillcolor.Green = 0
fillcolor.Blue = 0
fillsymbol.Color = fillcolor
scalebar.FillSymbol1 = fillsymbol
' Define division labels
Dim textsymbol As TextSymbol = New TextSymbol()
textsymbol.Size = 20
textsymbol.FontName = "Arial"
textsymbol.TextDirection = esriTextDirection.esriTDAngle
textsymbol.Angle = 45
scalebar.LabelSymbol = textsymbol
scalebar.LabelPosition = esriVertPosEnum.esriAbove
scalebar.LabelPositionSpecified = True
scalebar.LabelFrequency = esriScaleBarFrequency.esriScaleBarDivisions
scalebar.LabelFrequencySpecified = True
' Define map properties (MapDescription and ImageDisplay)
Dim mapinfo As MapServerInfo = mapservice.GetServerInfo(mapservice.GetDefaultMapName())
Dim mapdesc As MapDescription = mapinfo.DefaultMapDescription
Dim imgdispmap As ImageDisplay = New ImageDisplay()
imgdispmap.ImageWidth = 500
imgdispmap.ImageHeight = 500
imgdispmap.ImageDPI = 96
' Define scale bar image properties (ImageDescription)
Dim imgtype As ImageType = New ImageType()
imgtype.ImageFormat = esriImageFormat.esriImagePNG
imgtype.ImageReturnType = esriImageReturnType.esriImageReturnURL
Dim imgdispscalebar As ImageDisplay = New ImageDisplay()
imgdispscalebar.ImageHeight = 75 'pixels
imgdispscalebar.ImageWidth = 400 'pixels
Dim imgdescscalebar As ImageDescription = New ImageDescription()
imgdescscalebar.ImageDisplay = imgdispscalebar
imgdescscalebar.ImageType = imgtype
' Define background color
Dim backcolor As wsmap.RgbColor = New wsmap.RgbColor()
backcolor.Red = 255
backcolor.Green = 255
backcolor.Blue = 255
' Create scale bar image
Dim imgresult As ImageResult = mapservice.ExportScaleBar(scalebar, mapdesc, imgdispmap, backcolor, imgdescscalebar)
Java
String serviceURL = "http://localhost:6080/arcgis/services/MapService/MapServer";
MapServerBindingStub mapService = new MapServerBindingStub(serviceURL);
//Define scale bar properties
AlternatingScaleBar scaleBar = new AlternatingScaleBar();
scaleBar.setUnits(EsriUnits.esriMiles);
//Define Unit label
TextSymbol unitTextSymbol = new TextSymbol();
unitTextSymbol.setSize(20);
unitTextSymbol.setFontName("Arial");
unitTextSymbol.setText("Mile");
unitTextSymbol.setMaskStyle(EsriMaskStyle.esriMSNone);
unitTextSymbol.setTextDirection(EsriTextDirection.esriTDHorizontal);
unitTextSymbol.setTextCase(EsriTextCase.esriTCNormal);
unitTextSymbol.setTextPosition(EsriTextPosition.esriTPNormal);
unitTextSymbol.setHorizontalAlignment(EsriTextHorizontalAlignment.esriTHACenter);
unitTextSymbol.setVerticalAlignment(EsriTextVerticalAlignment.esriTVATop);
scaleBar.setUnitLabelSymbol(unitTextSymbol);
scaleBar.setUnitLabelPosition(EsriScaleBarPos.esriScaleBarAfterBar);
scaleBar.setUnitLabelGap(10.0);
//Define bar display
scaleBar.setBarHeight(8.0);
scaleBar.setDivision(4.0);
scaleBar.setDivisionMarkHeight(18.0);
scaleBar.setSubdivisions((short)10);
scaleBar.setMarkPosition(EsriVertPosEnum.esriBottom);
SimpleFillSymbol fillSymbol = new SimpleFillSymbol();
RgbColor fillColor = new RgbColor();
fillColor.setRed((short)255);
fillColor.setGreen((short)(0));
fillColor.setBlue((short)(0));
fillSymbol.setColor(fillColor);
fillSymbol.setStyle(EsriSimpleFillStyle.esriSFSSolid);
scaleBar.setFillSymbol1(fillSymbol);
//Define division labels
TextSymbol textSymbol = new TextSymbol();
textSymbol.setSize(20.0);
textSymbol.setFontName("Arial");
textSymbol.setTextDirection(EsriTextDirection.esriTDAngle);
textSymbol.setAngle(45.0);
textSymbol.setText("|");
textSymbol.setMaskStyle(EsriMaskStyle.esriMSNone);
textSymbol.setTextCase(EsriTextCase.esriTCNormal);
textSymbol.setTextPosition(EsriTextPosition.esriTPNormal);
textSymbol.setHorizontalAlignment(EsriTextHorizontalAlignment.esriTHACenter);
textSymbol.setVerticalAlignment(EsriTextVerticalAlignment.esriTVATop);
scaleBar.setLabelSymbol(textSymbol);
scaleBar.setLabelPosition(EsriVertPosEnum.esriAbove);
scaleBar.setLabelFrequency(EsriScaleBarFrequency.esriScaleBarDivisions);
//Define map properties (MapDescription and ImageDisplay)
String mapName = mapService.getDefaultMapName();
MapServerInfo mapInfo= mapService.getServerInfo(mapName);
MapDescription mapDesc = mapInfo.getDefaultMapDescription();
ImageDisplay imgDispMap = new ImageDisplay();
imgDispMap.setImageWidth(500); //Height of the image in pixels
imgDispMap.setImageHeight(500); //Width of the image in pixels
imgDispMap.setImageDPI(96);
//Define scale bar image properties (ImageDescription)
ImageType imgType = new ImageType();
imgType.setImageFormat(EsriImageFormat.esriImagePNG);
imgType.setImageReturnType(EsriImageReturnType.esriImageReturnURL);
ImageDisplay imgDispScalebar = new ImageDisplay();
imgDispScalebar.setImageHeight(75); //Height of the image in pixels
imgDispScalebar.setImageWidth(400); //Width of the image in pixels
ImageDescription imgDescScalebar = new ImageDescription();
imgDescScalebar.setImageDisplay(imgDispScalebar);
imgDescScalebar.setImageType(imgType);
//Define background color
RgbColor backColor = new RgbColor();
backColor.setRed((short)(255));
backColor.setGreen((short)(255));
backColor.setBlue((short)(255));
//Create scale bar image
ImageResult imgResult = mapService.exportScaleBar(scaleBar, mapDesc, imgDispMap, backColor, imgDescScalebar);
System.out.println("Image URL: " + imgResult.getImageURL());