In this topic
- Populate IGridLabel properties
- Create a DMS grid label
- Create a formatted grid label
- Create a mixed font grid label
- Populate IIndexGridTabStyle
- Create button tab style labels
- Create continuous tab style labels
- Create rounded tab style labels
- Create round box style labels
The following code demonstrates how you would populate the attributes exposed by IGridLabel for a newly created GridLabel:
[Java]
public void setGridLabelProperties()throws IOException{
// Set font and color
StdFont standardFont = new StdFont();
Font font = (Font)standardFont;
font.setName("Arial");
//The size should be specified in multiples of 10,000
font.setSize(12 * 10000);
// Create grid label
IGridLabel gridLabel = new DMSGridLabel();
gridLabel.setFont(font);
gridLabel.setColor(buildRGB(255, 255, 128));
//Specify Vertical Labels
gridLabel.setLabelAlignment(esriGridAxisEnum.esriGridAxisLeft, false);
gridLabel.setLabelAlignment(esriGridAxisEnum.esriGridAxisRight, false);
gridLabel.setLabelOffset(6.0);
/*
* Create the grid
*You would then set the properties specific to the type of grid label you are creating.
*You would associate the newly created grid label to the grid using the grid’s
*IMapGrid.setLabelFormat() method:
*
*/
IMapGrid mapGrid = new Graticule();
mapGrid.setName("Map Grid");
mapGrid.setLabelFormat(gridLabel);
mapGrid.setVisible(true);
}
//method to create required RGBColor ArcObject
public IColor buildRGB(int red, int green, int blue)throws IOException{
IRgbColor rgbColor = new RgbColor();
rgbColor.setRed(red);
rgbColor.setGreen(green);
rgbColor.setBlue(blue);
rgbColor.setUseWindowsDithering(true);
return rgbColor;
}
The following code demonstrates how to create a DMS grid
label:
[Java]
public void createDMSGridLabel()throws Exception{
//Create a DMS grid label
IDMSGridLabel dmsGridLabel = new DMSGridLabel();
//Set IDMSGridLabel properties
dmsGridLabel.setLabelType(esriDMSGridLabelType.esriDMSGridLabelStandard);
dmsGridLabel.setShowZeroMinutes(true);
dmsGridLabel.setShowZeroSeconds(true);
ILatLonFormat latLonFormat = new LatLonFormat();
latLonFormat.setShowDirections(true);
dmsGridLabel.setLatLonFormat(latLonFormat);
Font font = new StdFont();
font.setBold(false);
font.setName("Arial");
font.setItalic(false);
font.setUnderline(false);
//The size should be specified in multiples of 10,000
font.setSize(12 * 10000);
dmsGridLabel.setMinutesFont(font);
dmsGridLabel.setMinutesColor(buildRGB(0, 0, 0));
dmsGridLabel.setSecondsFont(font);
dmsGridLabel.setSecondsColor(buildRGB(0, 0, 0));
}
The following code illustrates the creation of a
formatted grid label:
[Java]
public IFormattedGridLabel createFormattedGridLabel()throws IOException{
INumericFormat numericFormat = new NumericFormat();
numericFormat.setAlignmentOption(esriNumericAlignmentEnum.esriAlignRight);
numericFormat.setRoundingOption(esriRoundingOptionEnum.esriRoundNumberOfDecimals)
;
numericFormat.setRoundingValue(2);
numericFormat.setShowPlusSign(false);
numericFormat.setUseSeparator(true);
numericFormat.setZeroPad(true);
//Create the label and set IFormattedGridLabel properties
IFormattedGridLabel formattedGridLabel = new FormattedGridLabel();
formattedGridLabel.setFormat((INumberFormat)numericFormat);
return formattedGridLabel;
}
}
The following code illustrates how you can create a
mixed font grid label:
[Java]
public void createMixedFontGridLabel()throws IOException{
//Set the Font Size
StdFont stdFont = new StdFont();
Font font = (Font)stdFont;
font.setBold(false);
font.setName("Arial");
font.setItalic(false);
font.setUnderline(false);
//Size need to be a multiple of 10,000
font.setSize(12 * 10000);
//Create the label and set IMixedFontGridLabel properties
IMixedFontGridLabel mixedFontGridLabel = new MixedFontGridLabel();
mixedFontGridLabel.setSecondaryFont(font);
mixedFontGridLabel.setSecondaryColor(buildRGB(0, 0, 128));
mixedFontGridLabel.setNumGroupedDigits((short)6); //-1 if not being used
//Set the numeric properties
INumericFormat numericFormat = new NumericFormat();
numericFormat.setAlignmentOption(esriNumericAlignmentEnum.esriAlignRight);
numericFormat.setRoundingOption(esriRoundingOptionEnum.esriRoundNumberOfDecimals)
;
numericFormat.setRoundingValue(2);
numericFormat.setShowPlusSign(true);
numericFormat.setUseSeparator(false);
numericFormat.setZeroPad(true);
//Set IFormattedGridLabel properties
IFormattedGridLabel formattedGridLabel = (IFormattedGridLabel)mixedFontGridLabel;
formattedGridLabel.setFormat((INumberFormat)numericFormat);
}
//method to create required RGBColor ArcObject
public IColor buildRGB(int red, int green, int blue)throws IOException{
IRgbColor rgbColor = new RgbColor();
rgbColor.setRed(red);
rgbColor.setGreen(green);
rgbColor.setBlue(blue);
rgbColor.setUseWindowsDithering(true);
return rgbColor;
}
The code illustrates how to populate the properties exposed by the IIndexGridTabStyle interface after you create the label:
[Java]
public void populateIIndexGridTabStyle()throws IOException{
// Create colors
IColor foregroundColor = new RgbColor();
foregroundColor.setRGB(0XECDEFE); // -> Pink
IColor outlineColor = new RgbColor();
outlineColor.setRGB(0XBBBBBB); // -> Gray
//Set IIndexGridTabStyle properties
IIndexGridTabStyle indexGridTabStyle = new BackgroundTabStyle();
indexGridTabStyle.setForegroundColor(foregroundColor);
indexGridTabStyle.setOutlineColor(outlineColor);
indexGridTabStyle.setThickness(20);
}
Button tab style labels are rectangular buttons, each
the width of the grid cell that it borders. The
following code shows you how to create a button tab
style grid label.
[Java]
public void createButtonTabStyleGridLabel()throws IOException{
//Create the label
IIndexGridTabStyle indexGridTabStyle = new ButtonTabStyle();
}
Continuous tab style labels form a continuous band
around the map grid. The example below shows how you can
create a label of this kind:
[Java]
public void createContinuousTabStyleGridLabel()throws IOException{
IIndexGridTabStyle indexGridTabStyle = new ContinuousTabStyle();
}
Rounded tab style labels are rounded rectangles; each
one is the width of the grid cell it borders. Using the
example below, you can create your rounded tab style
grid label.
[Java]
public void createRoundedTabStyleGridLabel()throws IOException{
IIndexGridTabStyle indexGridTabStyle = new RoundedTabStyle();
}
The example below illustrates how you can create a
background tab style label that uses round boxes to
label a map grid.
[Java]
public void createRoundBoxTabStyleGridLabel()throws IOException{
IIndexGridTabStyle indexGridTabStyle = new BackgroundTabStyle();
// Set IBackgroundTabStyle properties
IBackgroundTabStyle backgroundTabStyle = (IBackgroundTabStyle)indexGridTabStyle;
backgroundTabStyle.setBackgroundType
(esriBackgroundTabType.esriBackgroundTabRound);
}
See Also:
How to create map gridsIMapGrid interface
About map grids
Development licensing | Deployment licensing |
---|---|
Engine Developer Kit | ArcView |
ArcEditor | |
ArcInfo | |
Engine Runtime |