Class CityPointRenderer
GeoJsonCityLoader.CityFeature instances as
marker dots and optional text labels using an IMapProjection,
MapTheme, and IContainer.
Coordinate conventions
City coordinates stored in GeoJsonCityLoader.CityFeature are in
radians (λ = longitude, φ = latitude), as required by
IMapProjection.latLonToXY(java.awt.geom.Point2D.Double, java.awt.geom.Point2D.Double). All coordinate intermediate values use
the same x = λ, y = φ convention.
Filtering
Two independent filter levels control what is drawn:
- Point filter — controlled by
setMinPopulation(long)andsetMaxScalerank(int). Cities that fail this filter are not drawn at all. - Label filter — an additional scalerank threshold controlled by
setMaxLabelScalerank(int). Cities that pass the point filter but not the label filter still get a dot, but no text label.
Picking
pickCity(Point, IContainer) performs a brute-force linear scan
over all visible cities to find the nearest one within a small pick radius.
This is called on every mouse-move event via the feedback mechanism, so the
city list should remain small (the default population filter achieves this
in practice). Unlike CountryRenderer, city picking does not depend
on a previous render call — it reprojects cities on demand.
Thread safety
This class is not thread-safe. All method calls must be made on the Event Dispatch Thread.
City list ownership
The city list passed to the constructor is stored by reference without
defensive copying. Callers must ensure that the list is effectively
immutable after construction (or is not modified while rendering is in
progress). The list returned by GeoJsonCityLoader is already
unmodifiable, so in normal usage this is safe.
-
Constructor Summary
ConstructorsConstructorDescriptionCityPointRenderer(List<GeoJsonCityLoader.CityFeature> cities, IMapProjection projection) Creates a renderer for the given cities and projection. -
Method Summary
Modifier and TypeMethodDescriptionvoidcopyStyleFrom(CityPointRenderer source) Copies user-configurable rendering settings from another city renderer.Returns the effective city-label color.Returns the city-label font.intReturns the maximum scalerank for city labels.intReturns the maximum city scalerank.longReturns the minimum population threshold.Returns the effective city-marker color.doubleReturns the city-marker radius.booleanReturns whether city labels are enabled.booleanReturns whether antialiasing is enabled.pickCity(Point mouseLocal, IContainer container) Returns the closest visible city within a small picking radius of the given screen position, ornullif no city is nearby.voidrender(Graphics2D g2, IContainer container) Renders all cities that pass the current filters.voidsetDrawLabels(boolean drawLabels) Enables or disables drawing of city name labels.voidsetLabelColor(Color color) Sets a custom city-label color.voidsetLabelFont(Font font) Sets the font used for city name labels.voidsetLabelFontSize(float size) Sets the city-label font size while preserving its family and style.voidsetMaxLabelScalerank(int maxLabelScalerank) Sets the maximum scalerank for which a label is drawn, in addition to the point filter (setMaxScalerank(int)).voidsetMaxScalerank(int maxScalerank) Sets the maximum scalerank for a city to be drawn.voidsetMinPopulation(long minPopulation) Sets the minimum population required for a city to be drawn.voidsetPointColor(Color color) Sets a custom city-marker color.voidsetPointRadius(double pointRadius) Sets the radius of city marker dots in screen pixels.voidsetUseAntialias(boolean useAntialias) Enables or disables antialiased rendering.voidRestores theme-controlled city colors.
-
Constructor Details
-
CityPointRenderer
Creates a renderer for the given cities and projection.The city list is stored by reference; see the class-level note on list ownership for thread-safety considerations.
- Parameters:
cities- the city features to render; must not benull; should be effectively immutable after this callprojection- the map projection; must not benull
-
-
Method Details
-
setDrawLabels
public void setDrawLabels(boolean drawLabels) Enables or disables drawing of city name labels.- Parameters:
drawLabels-trueto draw labels;falseto draw dots only
-
setUseAntialias
public void setUseAntialias(boolean useAntialias) Enables or disables antialiased rendering.- Parameters:
useAntialias-trueto enable antialiasing
-
setMinPopulation
public void setMinPopulation(long minPopulation) Sets the minimum population required for a city to be drawn.- Parameters:
minPopulation- minimum population, or zero to disable filtering
-
setMaxScalerank
public void setMaxScalerank(int maxScalerank) Sets the maximum scalerank for a city to be drawn.Cities with
scalerank > maxScalerankare hidden. Set to a negative value to disable scalerank filtering. Scalerank 0 denotes the largest / most prominent cities; higher values denote progressively less prominent ones.- Parameters:
maxScalerank- maximum scalerank (inclusive), or negative to disable
-
setMaxLabelScalerank
public void setMaxLabelScalerank(int maxLabelScalerank) Sets the maximum scalerank for which a label is drawn, in addition to the point filter (setMaxScalerank(int)).A city that passes the point filter but has
scalerank > maxLabelScalerankstill receives a dot but no label. Set to a negative value to disable this additional label filter so that every drawn city also receives a label.- Parameters:
maxLabelScalerank- maximum scalerank for labels (inclusive), or negative to disable label scalerank filtering
-
setPointRadius
public void setPointRadius(double pointRadius) Sets the radius of city marker dots in screen pixels.- Parameters:
pointRadius- dot radius in pixels; clamped to a minimum of 0.5
-
setLabelFont
Sets the font used for city name labels.- Parameters:
font- label font; ifnullthe default city-label font is used
-
setLabelFontSize
public void setLabelFontSize(float size) Sets the city-label font size while preserving its family and style.- Parameters:
size- font size in points; clamped to[6, 36]
-
render
Renders all cities that pass the current filters.For each visible city that passes
passesFilters(edu.cnu.mdi.mapping.loader.GeoJsonCityLoader.CityFeature):- The geographic coordinates are projected to world space and then to screen space.
- A circular dot is drawn at the screen position using the city color from the theme.
- If
drawLabelsistrueand the city also passeslabelPassesScalerank(edu.cnu.mdi.mapping.loader.GeoJsonCityLoader.CityFeature), the city name is drawn to the right of the dot.
The graphics state (color, font, antialiasing hint) is saved before rendering and restored on return, even if an exception occurs.
- Parameters:
g2- graphics context to draw into; must not benullcontainer- container providing the world-to-local transform; must not benull
-
copyStyleFrom
Copies user-configurable rendering settings from another city renderer.City data and projection state are deliberately not copied.
- Parameters:
source- renderer whose settings should be copied
-
pickCity
Returns the closest visible city within a small picking radius of the given screen position, ornullif no city is nearby.Unlike
CountryRenderer.pickCountry(java.awt.Point, edu.cnu.mdi.container.IContainer), this method does not rely on any cached state from a previous render call. It reprojects every city from scratch on each invocation, which is acceptable because the population filter keeps the number of visible cities small.The pick radius is
pointRadius+ 2 pixels. If multiple cities fall within that radius the one closest to the cursor is returned.- Parameters:
mouseLocal- mouse position in the container's local (screen) coordinate space; must not benullcontainer- container providing the world-to-local transform; must not benull- Returns:
- the nearest city within the pick radius, or
null
-
isDrawLabels
public boolean isDrawLabels()Returns whether city labels are enabled.- Returns:
truewhen city labels are drawn
-
isUseAntialias
public boolean isUseAntialias()Returns whether antialiasing is enabled.- Returns:
truewhen antialiasing is enabled
-
getMinPopulation
public long getMinPopulation()Returns the minimum population threshold.- Returns:
- minimum population, or a nonpositive value when disabled
-
getMaxScalerank
public int getMaxScalerank()Returns the maximum city scalerank.- Returns:
- maximum scalerank, or a negative value when disabled
-
getMaxLabelScalerank
public int getMaxLabelScalerank()Returns the maximum scalerank for city labels.- Returns:
- maximum label scalerank, or a negative value when disabled
-
getPointRadius
public double getPointRadius()Returns the city-marker radius.- Returns:
- marker radius in pixels
-
getLabelFont
Returns the city-label font.- Returns:
- label font
-
getPointColor
Returns the effective city-marker color.- Returns:
- custom marker color when set; otherwise the theme marker color
-
setPointColor
Sets a custom city-marker color.- Parameters:
color- custom color, ornullto use the map theme
-
getLabelColor
Returns the effective city-label color.- Returns:
- custom label color when set; otherwise the theme label color
-
setLabelColor
Sets a custom city-label color.- Parameters:
color- custom color, ornullto use the map theme
-
useThemeColors
public void useThemeColors()Restores theme-controlled city colors.
-