Class MapServer


  • public class MapServer
    extends java.lang.Object
    This MapServer class is the entry point for running the JavaSpark web server for the BearMaps application project, receiving API calls, handling the API call processing, and generating requested images and routes. You should not need to modify this file, though you're welcome to make changes as you see fit.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  MapServer.RenderedRasterResultParams
      An adapter class for extending RasterResultParams with the final image.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static GraphDB graph
      The GraphDBresponsible for managing map data.
      private static com.google.gson.Gson gson
      The configured Gson Java serializer.
      private static int HALT_RESPONSE
      HTTP failed response.
      private static java.lang.String IMG_ROOT
      The directory where tile images can be found.
      private static java.lang.String OSM_DB_PATH
      The OSM XML file path.
      private static Rasterer rasterer
      The Rasterer responsible for computing the shortest path and directions.
      static double ROOT_LAT_DELTA
      The difference between the upper-most and lower-most latitudes of the map.
      static double ROOT_LON_DELTA
      The difference between the left-most and right-most longitudes of the map.
      static double ROOT_LONDPP
      The root longitude distance per pixel.
      static double ROOT_LRLAT
      The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped.
      static double ROOT_LRLON
      The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped.
      static double ROOT_ULLAT
      The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped.
      static double ROOT_ULLON
      The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped.
      private static java.util.List<java.lang.Long> route
      The most recently-requested shortest-paths route.
      private static java.awt.Color ROUTE_STROKE_COLOR
      Route stroke information: semi-transparent cyan.
      private static float ROUTE_STROKE_WIDTH_PX
      Route stroke information: typically roads are not more than 5px wide.
      static int TILE_SIZE
      Each tile is 256x256 pixels.
    • Constructor Summary

      Constructors 
      Constructor Description
      MapServer()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String getDirectionsText​(java.util.List<Router.NavigationDirection> directions)
      Returns the HTML-friendly Stirng representation of the route.
      static void initialize()
      Code responsible for initializing variables.
      static void main​(java.lang.String[] args)
      Launch the mapServer, register server routes, and listen on the default port.
      private static java.awt.image.BufferedImage readImage​(java.lang.String imgPath)
      Returns the image found at the given imgPath.
      private static java.awt.image.BufferedImage renderImage​(RasterResultParams resultParams)
      Return the image defined by the resultParams.
      • Methods inherited from class java.lang.Object

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

      • ROOT_ULLAT

        public static final double ROOT_ULLAT
        The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped. Longitude refers to the x-axis (vertical lines). Latitude refers to the y-axis (horizontal lines).
        See Also:
        Constant Field Values
      • ROOT_ULLON

        public static final double ROOT_ULLON
        The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped. Longitude refers to the x-axis (vertical lines). Latitude refers to the y-axis (horizontal lines).
        See Also:
        Constant Field Values
      • ROOT_LRLAT

        public static final double ROOT_LRLAT
        The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped. Longitude refers to the x-axis (vertical lines). Latitude refers to the y-axis (horizontal lines).
        See Also:
        Constant Field Values
      • ROOT_LRLON

        public static final double ROOT_LRLON
        The root upper left/lower right longitudes and latitudes represent the bounding box of the root tile, as the images are scraped. Longitude refers to the x-axis (vertical lines). Latitude refers to the y-axis (horizontal lines).
        See Also:
        Constant Field Values
      • TILE_SIZE

        public static final int TILE_SIZE
        Each tile is 256x256 pixels.
        See Also:
        Constant Field Values
      • ROOT_LONDPP

        public static final double ROOT_LONDPP
        The root longitude distance per pixel.
        See Also:
        Constant Field Values
      • ROOT_LON_DELTA

        public static final double ROOT_LON_DELTA
        The difference between the left-most and right-most longitudes of the map.
      • ROOT_LAT_DELTA

        public static final double ROOT_LAT_DELTA
        The difference between the upper-most and lower-most latitudes of the map.
      • graph

        private static GraphDB graph
        The GraphDBresponsible for managing map data.
      • rasterer

        private static Rasterer rasterer
        The Rasterer responsible for computing the shortest path and directions.
      • route

        private static java.util.List<java.lang.Long> route
        The most recently-requested shortest-paths route. The renderImage method redraws this route every time a new rastering result is requested from the browser.
      • gson

        private static com.google.gson.Gson gson
        The configured Gson Java serializer.
      • HALT_RESPONSE

        private static final int HALT_RESPONSE
        HTTP failed response.
        See Also:
        Constant Field Values
      • ROUTE_STROKE_WIDTH_PX

        private static final float ROUTE_STROKE_WIDTH_PX
        Route stroke information: typically roads are not more than 5px wide.
        See Also:
        Constant Field Values
      • ROUTE_STROKE_COLOR

        private static final java.awt.Color ROUTE_STROKE_COLOR
        Route stroke information: semi-transparent cyan.
      • IMG_ROOT

        private static final java.lang.String IMG_ROOT
        The directory where tile images can be found.
        See Also:
        Constant Field Values
      • OSM_DB_PATH

        private static final java.lang.String OSM_DB_PATH
        The OSM XML file path. Downloaded from here using custom region selection.
        See Also:
        Constant Field Values
    • Constructor Detail

      • MapServer

        public MapServer()
    • Method Detail

      • initialize

        public static void initialize()
        Code responsible for initializing variables. These objects must be instantiated independently of the main method for the tests to function properly.
      • main

        public static void main​(java.lang.String[] args)
        Launch the mapServer, register server routes, and listen on the default port.
        Parameters:
        args - Ignored
      • renderImage

        private static java.awt.image.BufferedImage renderImage​(RasterResultParams resultParams)
        Return the image defined by the resultParams.
        Parameters:
        resultParams - RasterResultParams from Rasterer.getMapRaster
        Returns:
        The final, rastered image including any shortest-paths routes.
      • readImage

        private static java.awt.image.BufferedImage readImage​(java.lang.String imgPath)
        Returns the image found at the given imgPath.
        Parameters:
        imgPath - String path to the image.
        Returns:
        The BufferedImage at the specified imgPath.
      • getDirectionsText

        private static java.lang.String getDirectionsText​(java.util.List<Router.NavigationDirection> directions)
        Returns the HTML-friendly Stirng representation of the route.
        Parameters:
        directions - The List of NavigationDirections.
        Returns:
        An HTML-encoded String of the list of navigation directions.