public final class MgrsGrid extends Object implements AutoCloseable
It combines one or more settings which determine which MGRS levels are displayed and how they are styled.
MgrsGridLayer mgrsGridLayer = MgrsGridLayer.newBuilder().build();
map.getLayerList().add(mgrsGridLayer);
Color primaryColor = Color.valueOf(Color.WHITE);
Color secondaryColor = Color.valueOf(Color.GREEN);
Color tertiaryColor = Color.valueOf(Color.BLUE);
TextStyle primaryLabelStyle = TextStyle.newBuilder()
.fontSize(12)
.fontName("monospace")
.textColor(primaryColor)
.haloWidth(1)
.haloColor(Color.valueOf(Color.BLACK))
.build();
TextStyle secondaryLabelStyle = TextStyle.newBuilder()
.fontSize(14)
.fontName("monospace")
.textColor(secondaryColor)
.haloWidth(1)
.haloColor(Color.valueOf(Color.BLACK))
.build();
TextStyle tertiaryLabelStyle = TextStyle.newBuilder()
.fontSize(16)
.fontName("monospace")
.textColor(tertiaryColor)
.haloWidth(1)
.haloColor(Color.valueOf(Color.BLACK))
.build();
MgrsGrid mgrsGrid = MgrsGrid.newBuilder()
.primaryLineStyle(LineStyle.newBuilder()
.color(primaryColor)
.width(1.0)
.build())
.primaryLabelStyle(primaryLabelStyle)
.secondaryLineStyle(LineStyle.newBuilder()
.color(secondaryColor)
.width(2.0)
.build())
.secondaryLabelStyle(secondaryLabelStyle)
.tertiaryLineStyle(LineStyle.newBuilder()
.color(tertiaryColor)
.width(3.0)
.build())
.tertiaryLabelStyle(tertiaryLabelStyle)
.scaleMultiplier(1.5) // make the grid more coarse
.build();
MgrsGridLayer mgrsGridLayer = MgrsGridLayer.newBuilder().grid(mgrsGrid).build();
map.getLayerList().add(mgrsGridLayer);
// Styling with completely custom scale ranges and styles
TextStyle labelStyle = TextStyle.newBuilder() // Label style used on all levels
.fontSize(20)
.fontName("monospace")
.textColor(Color.valueOf(Color.WHITE))
.haloColor(Color.valueOf(Color.BLACK))
.haloWidth(1)
.build();
// Always show grid zones with thick red lines, regardless of the zoom level
MgrsGridSetting gridZoneSetting = MgrsGridSetting.newBuilder()
.level(MgrsLevel.GridZones)
.scaleRange(MapScale.MaxZoomedOut, MapScale.MaxZoomedIn)
.lineStyle(LineStyle.newBuilder()
.color(Color.valueOf(Color.RED))
.width(5.0)
.build())
.labelStyle(labelStyle)
.build();
// When zoomed in far enough, show 100km grid squares in yellow.
// Hide them when zoomed in beyond the 10km grid square scale range start
MapScale startScale100Km = MapScale.fromDenominator(3_000_000.0);
MapScale startScale10Km = MapScale.fromDenominator(750_000.0);
MgrsGridSetting square100KmSetting = MgrsGridSetting.newBuilder()
.level(MgrsLevel.Squares100Km)
.scaleRange(startScale100Km, startScale10Km)
.lineStyle(LineStyle.newBuilder()
.color(Color.valueOf(Color.YELLOW))
.width(3.0)
.build())
.labelStyle(labelStyle)
.build();
// When zoomed in beyond the 100km squares, show 10km squares in green
MgrsGridSetting square10KmSetting = MgrsGridSetting.newBuilder()
.level(MgrsLevel.Squares10Km)
.scaleRange(startScale10Km, MapScale.MaxZoomedIn)
.lineStyle(LineStyle.newBuilder()
.color(Color.valueOf(Color.GREEN))
.width(2.0)
.build())
.labelStyle(labelStyle)
.build();
// Don't show any lower MGRS levels (Squares1Km, Squares100M, Squares10M and Squares1M)
MgrsGrid mgrsGrid = MgrsGrid.newAdvancedBuilder()
.setting(gridZoneSetting) // grid zones
.setting(square100KmSetting) // 100km squares
.setting(square10KmSetting) // 10km squares
.build();
MgrsGridLayer mgrsGridLayer = MgrsGridLayer.newBuilder().grid(mgrsGrid).build();
map.getLayerList().add(mgrsGridLayer);
Modifier and Type | Class and Description |
---|---|
static class |
MgrsGrid.AdvancedBuilder
Advanced builder for a MGRS grid.
|
static class |
MgrsGrid.Builder
Builder for a MGRS grid.
|
Modifier and Type | Method and Description |
---|---|
void |
close() |
protected void |
finalize() |
List<MgrsGridSetting> |
getSettings() |
static MgrsGrid.AdvancedBuilder |
newAdvancedBuilder()
Creates a new builder with the default values.
|
static MgrsGrid.Builder |
newBuilder()
Creates a new builder with the default values.
|
public MgrsGrid(@NotNull MgrsGrid other)
public void close()
close
in interface AutoCloseable
@NotNull public static MgrsGrid.Builder newBuilder()
This builder comes with pre-defined settings for MGRS levels, types, and scale ranges. It allows you to customize the styling, for example the line style to use.
@NotNull public static MgrsGrid.AdvancedBuilder newAdvancedBuilder()
This builder allows you to configure the MGRS grid styling for every level, type, and scale range.
@NotNull public List<MgrsGridSetting> getSettings()