Class OsmUrlToBounds


  • public final class OsmUrlToBounds
    extends java.lang.Object
    Parses various URL used in OpenStreetMap projects into Bounds.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private OsmUrlToBounds()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String getURL​(double dlat, double dlon, int zoom)
      Return OSM URL for given lat/lon and zoom.
      static java.lang.String getURL​(Bounds b)
      Return OSM URL for given area.
      static java.lang.String getURL​(LatLon pos, int zoom)
      Return OSM URL for given position and zoom.
      static int getZoom​(Bounds b)
      Return OSM Zoom level for a given area
      static Bounds parse​(java.lang.String url)
      Parses an URL into Bounds
      private static double parseDouble​(java.util.Map<java.lang.String,​java.lang.String> map, java.lang.String key)  
      private static Bounds parseHashURLs​(java.lang.String url)
      Openstreetmap.org changed it's URL scheme in August 2013, which breaks the URL parsing.
      private static Bounds parseShortLink​(java.lang.String url)
      Parse OSM short link
      static Bounds positionToBounds​(double lat, double lon, int zoom)
      Compute the bounds for a given lat/lon position and the zoom level
      static void setMapSizeSupplier​(java.util.function.Supplier<java.awt.Dimension> mapSizeSupplier)
      Sets the map size supplier.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • parse

        public static Bounds parse​(java.lang.String url)
        Parses an URL into Bounds
        Parameters:
        url - the URL to be parsed
        Returns:
        the parsed Bounds, or null
      • parseHashURLs

        private static Bounds parseHashURLs​(java.lang.String url)
        Openstreetmap.org changed it's URL scheme in August 2013, which breaks the URL parsing. The following function, called by the old parse function if necessary, provides parsing new URLs the new URLs follow the scheme https://www.openstreetmap.org/#map=18/51.71873/8.76164&layers=CN
        Parameters:
        url - string for parsing
        Returns:
        Bounds if hashurl, null otherwise
      • parseDouble

        private static double parseDouble​(java.util.Map<java.lang.String,​java.lang.String> map,
                                          java.lang.String key)
      • parseShortLink

        private static Bounds parseShortLink​(java.lang.String url)
        Parse OSM short link
        Parameters:
        url - string for parsing
        Returns:
        Bounds if shortlink, null otherwise
        See Also:
        short_link.rb
      • setMapSizeSupplier

        public static void setMapSizeSupplier​(java.util.function.Supplier<java.awt.Dimension> mapSizeSupplier)
        Sets the map size supplier.
        Parameters:
        mapSizeSupplier - returns the map size in pixels
        Since:
        12796
      • positionToBounds

        public static Bounds positionToBounds​(double lat,
                                              double lon,
                                              int zoom)
        Compute the bounds for a given lat/lon position and the zoom level
        Parameters:
        lat - The latitude
        lon - The longitude
        zoom - The current zoom level
        Returns:
        The bounds the OSM server would display
      • getZoom

        public static int getZoom​(Bounds b)
        Return OSM Zoom level for a given area
        Parameters:
        b - bounds of the area
        Returns:
        matching zoom level for area
      • getURL

        public static java.lang.String getURL​(Bounds b)
        Return OSM URL for given area.
        Parameters:
        b - bounds of the area
        Returns:
        link to display that area in OSM map
      • getURL

        public static java.lang.String getURL​(LatLon pos,
                                              int zoom)
        Return OSM URL for given position and zoom.
        Parameters:
        pos - center position of area
        zoom - zoom depth of display
        Returns:
        link to display that area in OSM map
      • getURL

        public static java.lang.String getURL​(double dlat,
                                              double dlon,
                                              int zoom)
        Return OSM URL for given lat/lon and zoom.
        Parameters:
        dlat - center latitude of area
        dlon - center longitude of area
        zoom - zoom depth of display
        Returns:
        link to display that area in OSM map
        Since:
        6453