public class MapServer extends Object
Modifier and Type | Field and Description |
---|---|
private static GraphDB |
g |
private static int |
HALT_RESPONSE
HTTP failed response.
|
private static String |
IMG_ROOT
The tile images are in the IMG_ROOT folder.
|
private static String |
OSM_DB_PATH
The OSM XML file path.
|
private static String[] |
REQUIRED_RASTER_REQUEST_PARAMS
Each raster request to the server will have the following parameters
as keys in the params map accessible by,
i.e., params.get("ullat") inside getMapRaster().
|
private static String[] |
REQUIRED_ROUTE_REQUEST_PARAMS
Each route request to the server will have the following parameters
as keys in the params map.
start_lat -> start point latitude, start_lon -> start point longitude, end_lat -> end point latitude, end_lon -> end point longitude. |
static double |
ROOT_LRLAT
The root upper left/lower right longitudes and latitudes represent the bounding box of
the root tile, as the images in the img/ folder 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 in the img/ folder 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 in the img/ folder 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 in the img/ folder are scraped.
|
static Color |
ROUTE_STROKE_COLOR
Route stroke information: Cyan with half transparency.
|
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 and Description |
---|
MapServer() |
Modifier and Type | Method and Description |
---|---|
static List<Long> |
findAndDrawRoute(Map<String,Double> routeParams,
Map<String,Object> rasterImageParams,
BufferedImage im)
Searches for the shortest route satisfying the input request parameters, and returns a
List of the route's node ids. |
static List<Map<String,Object>> |
getLocations(String locationName)
Collect all locations that match a cleaned
locationName , and return
information about each node that matches. |
static List<String> |
getLocationsByPrefix(String prefix)
In linear time, collect all the names of OSM locations that prefix-match the query string.
|
static BufferedImage |
getMapRaster(Map<String,Double> inputParams,
Map<String,Object> rasteredImageParams)
Handles raster API calls, queries for tiles and rasters the full image.
|
private static HashMap<String,Double> |
getRequestParams(spark.Request req,
String[] requiredParams)
Return a parameter map of the required request parameters.
|
private static boolean |
hasRequestParameters(HashMap<String,Double> params,
String[] requiredParams)
Check if the computed parameter map matches the required parameters on length.
|
static void |
initialize()
Place any initialization statements that will be run before the server main loop here.
|
static void |
main(String[] args) |
private static void |
validateRequestParameters(HashMap<String,Double> params,
String[] requiredParams)
Validate that the computed parameters matches the required parameters.
|
(package private) static void |
writeJpgToStream(BufferedImage im,
OutputStream os)
Write a
BufferedImage to an OutputStream . |
public static final double ROOT_ULLAT
public static final double ROOT_ULLON
public static final double ROOT_LRLAT
public static final double ROOT_LRLON
public static final int TILE_SIZE
private static final int HALT_RESPONSE
public static final float ROUTE_STROKE_WIDTH_PX
public static final Color ROUTE_STROKE_COLOR
private static final String IMG_ROOT
private static final String OSM_DB_PATH
private static final String[] REQUIRED_RASTER_REQUEST_PARAMS
private static final String[] REQUIRED_ROUTE_REQUEST_PARAMS
private static GraphDB g
public static void initialize()
public static void main(String[] args)
private static boolean hasRequestParameters(HashMap<String,Double> params, String[] requiredParams)
private static void validateRequestParameters(HashMap<String,Double> params, String[] requiredParams)
private static HashMap<String,Double> getRequestParams(spark.Request req, String[] requiredParams)
req
- HTTP RequestrequiredParams
- TestParams to validatestatic void writeJpgToStream(BufferedImage im, OutputStream os)
BufferedImage
to an OutputStream
. The image is written as
a lossy JPG, but with the highest quality possible.im
- Image to be written.os
- Stream to be written to.public static BufferedImage getMapRaster(Map<String,Double> inputParams, Map<String,Object> rasteredImageParams)
The rastered photo must have the following properties:
inputParams
- Map of the HTTP GET request's query parameters - the query bounding box
and the user viewport width and height.rasteredImageParams
- This is constructed beforehand and passed in as an empty map.BufferedImage
, which is the rastered result.REQUIRED_RASTER_REQUEST_PARAMS
public static List<Long> findAndDrawRoute(Map<String,Double> routeParams, Map<String,Object> rasterImageParams, BufferedImage im)
List
of the route's node ids. im
is not null, draw the route onto the image by drawing lines in between
adjacent points in the route. The lines should be drawn using ROUTE_STROKE_COLOR,
ROUTE_STROKE_WIDTH_PX, BasicStroke.CAP_ROUND and BasicStroke.JOIN_ROUND.routeParams
- Params collected from the API call. Members are as
described in REQUIRED_ROUTE_REQUEST_PARAMS.rasterImageParams
- parameters returned from the image rastering.im
- The rastered map image to be drawn on.public static List<String> getLocationsByPrefix(String prefix)
prefix
- Prefix string to be searched for. Could be any case, with our without
punctuation.List
of the full names of locations whose cleaned name matches the
cleaned prefix
.public static List<Map<String,Object>> getLocations(String locationName)
locationName
, and return
information about each node that matches.locationName
- A full name of a location searched for.locationName
, and each location is a map of parameters for the Json
response as specified: