Class OSMLayer

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
com.bbn.openmap.Layer
org.ka2ddo.yaac.gui.osm.OSMLayer
All Implemented Interfaces:
com.bbn.openmap.event.MapMouseListener, com.bbn.openmap.event.ProjectionListener, com.bbn.openmap.ProjectionPainter, com.bbn.openmap.PropertyConsumer, ActionListener, ComponentListener, ImageObserver, MenuContainer, BeanContextChild, BeanContextMembershipListener, Serializable, Runnable, EventListener, FlushableLayer

public class OSMLayer extends com.bbn.openmap.Layer implements Runnable, ComponentListener, com.bbn.openmap.event.MapMouseListener, FlushableLayer
This class implements a rendering Layer for OpenMap that draws street maps on the MapBean based on the binary tiled map data extracted from the OpenStreetMap database.
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Field Details

    • DEFAULT_BUILDING_COLOR

      public static final Color DEFAULT_BUILDING_COLOR
      The default color used for filling building outlines on the OpenStreetMap layer of the map.
    • MAX_NODE_ZOOM

      public static final float MAX_NODE_ZOOM
      Maximum value of map scale for rendering Nodes without either matching a searched-for AmenityType or having an expanded zoom level (due to being a Place).
      See Also:
    • MAX_NODE_LABEL_ZOOM

      public static final float MAX_NODE_LABEL_ZOOM
      Maximum value of map scale for rendering the labels of Nodes without either matching a searched-for AmenityType or having an expanded zoom level (due to being a Place).
      See Also:
    • MAX_MARINE_NODE_ZOOM

      public static final float MAX_MARINE_NODE_ZOOM
      Maximum value of map scale for rendering marine Nodes without either matching a searched-for AmenityType or having an expanded zoom level (due to being a Place).
      See Also:
  • Constructor Details

    • OSMLayer

      public OSMLayer(com.bbn.openmap.MapBean mapBean)
      Create a layer for the map that renders OpenStreetMap data from the default filetypes.
      Parameters:
      mapBean - MapBean that will contain this OSMLayer
    • OSMLayer

      public OSMLayer(com.bbn.openmap.MapBean mapBean, String nodesSuffix, String waysSuffix, String swaysSuffix)
      Create a layer for the map that renders OpenStreetMap data.
      Parameters:
      mapBean - MapBean that will contain this OSMLayer
      nodesSuffix - String suffix for files containing OpenStreetMap nodes
      waysSuffix - String suffix for files containing OpenStreetMap ways
      swaysSuffix - String suffix for files containing OpenStreetMap ways with less information
  • Method Details

    • setFontsAndSigns

      public void setFontsAndSigns(float fontScaleFactor)
    • reloadMapParamsFromPreferences

      public void reloadMapParamsFromPreferences()
      Load all the WayParam and VisibleCtls objects from their cached Preference values (or defaults if not saved).
    • initializePlaceZoomLevels

      public void initializePlaceZoomLevels()
      Load the persisted zoom levels for Place labels from the Preferences backing store.
    • isShowMap

      public final boolean isShowMap()
      Report whether the OpenStreetMap map overlay should be displayed.
      Returns:
      boolean true if OpenStreetMap overlay is displayed
    • setShowMap

      public void setShowMap(boolean showMap)
      Specify whether the OpenStreetMap map overlay should be rendered. Note this is independent of whether there actually is any OpenStreetMap data to render.
      Parameters:
      showMap - boolean true if OpenStreetMap layer should be rendered
    • isShowLayer

      public final boolean isShowLayer(int index)
      Report whether the identified WayType layer should be rendered on the map.
      Parameters:
      index - WayType enumeration ordinal of type being queried
      Returns:
      boolean true if ways of the specified WayType should be rendered
    • setShowLayer

      public void setShowLayer(boolean showLayer, int index)
      Specify whether the identified WayType layer should be rendered on the map.
      Parameters:
      showLayer - boolean true if ways of the specified WayType should be rendered
      index - WayType enumeration ordinal of type being specified
    • isShowHighwaySigns

      public boolean isShowHighwaySigns()
      Report whether highway signs should be displayed on the map.
      Returns:
      boolean true if highways signs should be displayed
    • setShowHighwaySigns

      public void setShowHighwaySigns(boolean showHighwaySigns)
      Specify whether highway signs should be displayed on the map.
      Parameters:
      showHighwaySigns - boolean true if highways signs should be displayed
    • isShowPOI

      public boolean isShowPOI()
      Report whether OSM Node points of interest should be displayed.
      Returns:
      boolean true if points of interest should be rendered on the map
    • setShowPOI

      public void setShowPOI(boolean showPOI)
      Specify whether OSM Node points of interest should be displayed.
      Parameters:
      showPOI - boolean true if points of interest should be rendered on the map
    • isShowUnlabeledWays

      public boolean isShowUnlabeledWays()
      Report if unlabeled and untyped map features should be displayed.
      Returns:
      boolean true if unlabeled/untyped map elements should be plotted
    • setShowUnlabeledWays

      public void setShowUnlabeledWays(boolean showUnlabeledWays)
      Specify if unlabeled and untyped map features should be displayed.
      Parameters:
      showUnlabeledWays - boolean true if unlabeled/untyped map elements should be plotted
    • isAutoLoadOsmTiles

      public static boolean isAutoLoadOsmTiles()
      Report whether YAAC is configured to try to auto-download pre-imported OSM tiles that are not currently on the system.
      Returns:
      boolean true if auto-download is enabled
    • setAutoLoadOsmTiles

      public void setAutoLoadOsmTiles(boolean autoLoadOsmTiles)
      Specify whether auto-download of missing pre-imported OSM tiles should be performed.
      Parameters:
      autoLoadOsmTiles - boolean true if auto-download should be enabled
    • isShowLabelsInEnglish

      public boolean isShowLabelsInEnglish()
      Report whether map labels should be displayed in English if the default name is in some other locale and OpenStreetMap provides an English translation.
      Returns:
      boolean true if English labels should be used
    • setShowLabelsInEnglish

      public void setShowLabelsInEnglish(boolean showLabelsInEnglish)
      Specify whether map labels should be displayed in English if the default name is in some other locale and OpenStreetMap provides an English translation.
      Parameters:
      showLabelsInEnglish - boolean true if English labels should be used
    • isHideSeamarks

      public boolean isHideSeamarks()
      Report whether seamark data should not be rendered. Normally, OpenSeaMap data should be rendered, unless another layer is rendering it better.
      Returns:
      boolean true if seamark map data should be rendered
    • setHideSeamarks

      public void setHideSeamarks(boolean hideSeamarks)
      Report whether seamark data should not be rendered. Normally, OpenSeaMap data should be rendered, unless another layer is rendering it better.
      Parameters:
      hideSeamarks - boolean true if seamark map data should be rendered
    • isSuppressMapPopups

      public boolean isSuppressMapPopups()
      Test if popup windows from clicking on a map feature will be allowed.
      Returns:
      boolean true if street map popup windows will not occur
    • setSuppressMapPopups

      public void setSuppressMapPopups(boolean suppressMapPopups)
      Specify if streemap popup windows should be triggered from mouse clicks.
      Parameters:
      suppressMapPopups - boolean true if popup windows should be prevented
    • getAmenityToShow

      public AmenityType getAmenityToShow()
      Report the specific AmenityType being highlighted on the map.
      Returns:
      the currently highlighted AmenityType, or null for no highlighting
    • setAmenityToShow

      public void setAmenityToShow(AmenityType amenityToShow)
      Specify that Ways and Nodes of the specified AmenityType should be highlighted on the map, regardless of zoom level, or that there is no special type to highlight.
      Parameters:
      amenityToShow - AmenityType to highlight, or null for no special highlighting
    • getBuildingColor

      public Color getBuildingColor()
      Get the current color used for filling in buildings on the map.
      Returns:
      Color of building fill
    • setBuildingColor

      public void setBuildingColor(Color buildingColor)
      Set the color to be used for filling building outlines on the map.
      Parameters:
      buildingColor - Color for building fill
    • getVisibleCtls

      public VisibleCtls getVisibleCtls()
      Get the type-specific visibility controls for this OSMLayer instance.
      Returns:
      VisibleEnum containing visibility controls for this layer
    • regenerateAndRepaint

      public void regenerateAndRepaint()
      Cause the OSMLayer to recompute its map based on current settings.
    • projectionChanged

      public void projectionChanged(com.bbn.openmap.event.ProjectionEvent e)
      Callback from OpenMap when map projection is changed,
      Specified by:
      projectionChanged in interface com.bbn.openmap.event.ProjectionListener
      Parameters:
      e - ProjectionEvent identifying new projection
    • paintComponent

      protected void paintComponent(Graphics g)
      Paint the rendered OpenStreetMap data into the map window.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - Graphics object to use for painting
    • stopRegenerate

      public void stopRegenerate(int offsetX, int offsetY)
      Stop the current re-rendering of the map and set the pixel offsets for painting the last rendering of the OSM data. Typically used when map is being panned rapidly to allow the user to still see some map data without thrashing the system with aborted re-rendering for different re-centering and/or re-zooming of the map.
      Parameters:
      offsetX - int horizontal pixel offset for painting the last render of the OSM data onto the map
      offsetY - int vertical pixel offset for painting the last render of the OSM data onto the map
    • startRegenerate

      public void startRegenerate()
      Release the lock against rendering OSM data and start a fresh rendering.
    • run

      public final void run()
      DO NOT CALL: background thread to render OpenStreetMap data into a BufferedImage for painting on the map window.
      Specified by:
      run in interface Runnable
    • flushFileCache

      public void flushFileCache()
      Clear cached pointers to tile files. This is called when the configuration dialog changes the tile root directory path.
      Specified by:
      flushFileCache in interface FlushableLayer
    • componentHidden

      public void componentHidden(ComponentEvent e)
      Invoked when the OSMLayer has been made invisible.
      Specified by:
      componentHidden in interface ComponentListener
    • componentMoved

      public void componentMoved(ComponentEvent e)
      Invoked when the OSMLayer's position changes.
      Specified by:
      componentMoved in interface ComponentListener
    • componentResized

      public void componentResized(ComponentEvent e)
      Invoked when the map window's size changes.
      Specified by:
      componentResized in interface ComponentListener
    • componentShown

      public void componentShown(ComponentEvent e)
      Invoked when the OSMLayer has been made visible.
      Specified by:
      componentShown in interface ComponentListener
    • getMapMouseListener

      public com.bbn.openmap.event.MapMouseListener getMapMouseListener()
      Specify the object to receive OpenMap mouse events on behalf of the OSM Layer.
      Overrides:
      getMapMouseListener in class com.bbn.openmap.Layer
      Returns:
      the OSMLayer object itself
    • getMouseModeServiceList

      public String[] getMouseModeServiceList()
      Specify the behavior the MapBean should give to this OSMLayer for mouse input.
      Specified by:
      getMouseModeServiceList in interface com.bbn.openmap.event.MapMouseListener
      Returns:
      the SELECT_MOUSE_MODE constant to specify selecting items with the mouse
    • mouseClicked

      public boolean mouseClicked(MouseEvent e)
      Invoked when the mouse button has been clicked (pressed and released) on a component.
      Specified by:
      mouseClicked in interface com.bbn.openmap.event.MapMouseListener
    • mousePressed

      public boolean mousePressed(MouseEvent mouseEvent)
      Invoked when a mouse button has been pressed on a component.
      Specified by:
      mousePressed in interface com.bbn.openmap.event.MapMouseListener
    • mouseReleased

      public boolean mouseReleased(MouseEvent mouseEvent)
      Invoked when a mouse button has been released on a component.
      Specified by:
      mouseReleased in interface com.bbn.openmap.event.MapMouseListener
    • mouseEntered

      public void mouseEntered(MouseEvent mouseEvent)
      Invoked when the mouse enters a component.
      Specified by:
      mouseEntered in interface com.bbn.openmap.event.MapMouseListener
    • mouseExited

      public void mouseExited(MouseEvent mouseEvent)
      Invoked when the mouse exits a component.
      Specified by:
      mouseExited in interface com.bbn.openmap.event.MapMouseListener
    • mouseDragged

      public boolean mouseDragged(MouseEvent mouseEvent)
      Specified by:
      mouseDragged in interface com.bbn.openmap.event.MapMouseListener
    • mouseMoved

      public boolean mouseMoved(MouseEvent mouseEvent)
      Specified by:
      mouseMoved in interface com.bbn.openmap.event.MapMouseListener
    • mouseMoved

      public void mouseMoved()
      Specified by:
      mouseMoved in interface com.bbn.openmap.event.MapMouseListener