Class AbstractRestMapProvider
- java.lang.Object
-
- com.supermap.services.components.spi.AbstractRestMapProvider
-
- All Implemented Interfaces:
- Disposable, MapProvider, ProviderContextAware
public abstract class AbstractRestMapProvider extends java.lang.Object implements ProviderContextAware, MapProvider, Disposable
Location service provider base class based on REST service.
Encapsulates the basic functions required to access the REST map service, and all service providers that use REST map services can use such class to extend.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description protected static classAbstractRestMapProvider.TileIndexThe index of the tile, including the line number, column number
-
Field Summary
Fields Modifier and Type Field and Description protected static java.lang.StringCACHEKEYprotected intdefaultDPIDPI of picture.static java.lang.StringLINK_MARKprotected static LocLoggerloggerstatic java.lang.StringQUESTION_MARKstatic doubleRESOLUTION_PRECESIONResolution accuracy, within the accuracy range, thinks that the two resolutions are equal.inttileColsTile width, the unit is the pixel, the default is 256 pixels.inttileRowsTile height, the unit is the pixel, the default is 256 pixels.static java.lang.StringURL_ENCODEThe encoding format of the URI.
-
Constructor Summary
Constructors Constructor and Description AbstractRestMapProvider()AbstractRestMapProvider(MapProviderSetting setting)
-
Method Summary
Methods Modifier and Type Method and Description protected static voidcheckParameterNull(java.lang.Object obj, java.lang.String parameterName)protected abstract voidcheckSetting(MapProviderSetting setting)Initialize the default map state.voidclearCache(java.lang.String mapName, Rectangle2D bounds)Clears the cache image of the map's corresponding range.voiddispose()Release the resource object.QueryResultfindNearest(java.lang.String mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet)Queries the nearest geometric object on a specified map whose distance to a specified geometry is within a certain value.protected ImageCacheHelpergetCacheHelper()java.lang.StringgetContent(java.lang.String url, java.lang.String method)Execute an HTTP request on the specified URL to get the response.MapParametergetDefaultMapParameter(java.lang.String mapName)Returns the default map state.protected java.util.Map<java.lang.String,MapParameter>getDefaultMapParameters()JsonConvertergetJsonConverter()Gets JSON Converter.MapImagegetMapImage(MapParameter mapParameter, ImageOutputOption outputOption)According to the map parameters, picture output settings to obtain the map image.protected byte[]getMapImageData(java.lang.String imageFilePath)MapParametergetMapParameter(java.lang.String mapName)Gets the status of a map (the map parameters) after outputting map images last time.MapProviderSettinggetMapProviderSetting()java.util.List<java.lang.String>getNames()Returns the map name list.OverviewgetOverview(MapParameter mapParameter, ImageOutputOption outputOption)Gets eagle-eye map according to map parameters and image output settings.java.lang.StringgetResource(java.lang.String mapName, ResourceParameter resourceParameter)Gets the resource image of a specified map according to a resource image parameter.abstract double[]getSupportResolutions()Returns the resolution of the current service support.protected Rectangle2DgetTileBounds(double currentResolution, int colIndex, int rowIndex, Point2D tileOrigin)With the given resolution, returns the range of tiles where the specified point is located.protected abstract java.io.InputStreamgetTileImageStream(MapParameter tileParam, ImageOutputOption outputOption, int colIndex, int rowIndex, double currentResolution)Gets the image stream for the specified tile.protected AbstractRestMapProvider.TileIndexgetTileIndex(Point2D point, double currentResolution, Point2D tileOriginPos)Returns the tile index of the tile where the specified point is locatedprotected abstract Point2DgetTileOrigin()Gets the geographic coordinates of the upper left corner of the map.protected abstract java.util.Map<java.lang.String,MapParameter>initDefaultMapParameter()Initializes the default map state, the return value is a map, the key is the map name, and the value is the map parameter object.protected abstract java.util.List<java.lang.String>initSupportedMapNames()Initialize the list of supported maps.protected booleanisResolutionEquals(double resolution1, double resolution2)protected booleanisResolutionSupported(double currentResolution)protected abstract booleanloadMetaData()Load meta information for the Rest service.MeasureResultmeasureArea(java.lang.String mapName, Point2D[] points, MeasureParameter measureParam)Measures areas on a specified map based on 2D geographic coordinates and a measuring parameter.MeasureResultmeasureDistance(java.lang.String mapName, Point2D[] points, MeasureParameter measureParam)Measures distances on a specified map based on 2D geographic coordinates and a measuring parameter.protected voidoutputImage(MapParameter param, ImageOutputOption outputOption, double currentResolution, java.lang.String targetFileName)Draws a picture in real time.protected voidoutputImageToFile(java.lang.String targetFileName, java.awt.image.BufferedImage targetImage)The area in which each tile coincide with the given range are spliced into a picture, write to the specified fileprotected booleanoutputStreamToFile(java.io.InputStream resultStream, java.lang.String targetFileName)Writes a byte stream to a fileQueryResultqueryByBounds(java.lang.String mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet)Queries the geometries in the specified range on the map.QueryResultqueryByDistance(java.lang.String mapName, Geometry geometry, double distance, QueryParameterSet queryParameterSet)Queries all the geometric objects on a specified map whose distances to a specified geometry are within a certain value.QueryResultqueryByGeometry(java.lang.String mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet)Queries geometric objects that satisfy a certain spatial relationship with a specified geometric object and meet query conditions on a specified map.QueryResultqueryBySQL(java.lang.String mapName, QueryParameterSet queryParameterSet)Performs SQL query on specified map.protected booleanrectifyViewBoundsAndViewer(MapParameter defaultMapParameter)Corrects the map state so that the ratio of map width to height is equal to the ratio of plot width to plot heightprotected doubleresolutionToScale(double resolution, int dpi, Unit mapUnit)According to the resolution, DPI, map units, calculate the scale.protected java.util.Map<java.lang.String,java.lang.Object>sendRequestByHttpURLConnection(java.lang.String urlStr, java.lang.String method, java.io.InputStream requestStream)Send an HTTP request viaHttpURLConnection.MapParametersetDefaultMapParameter(MapParameter mapParameter)Sets the default map parameters.protected voidsetDefaultMapParameters(java.util.Map<java.lang.String,MapParameter> defaultMapParameters)Sets the default map state.protected voidsetJsonConverter(JsonConverter jsonConverter)Sets JSON converter, the JSON converter can convert a JSON string to a Java object.voidsetMapProviderSetting(MapProviderSetting mapProviderSetting)voidsetProviderContext(ProviderContext context)Sets the service provider contextMapImageviewEntire(java.lang.String layerName, MapParameter mapParameter, ImageOutputOption outputOption)Conducts full display according to the map layer name, map parameters and picture output settings.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.supermap.services.components.spi.MapProvider
getResource, getVectorStyle, support, updateMap
-
-
-
-
Field Detail
-
QUESTION_MARK
public static final java.lang.String QUESTION_MARK
-
LINK_MARK
public static final java.lang.String LINK_MARK
-
URL_ENCODE
public static final java.lang.String URL_ENCODE
The encoding format of the URI.
-
RESOLUTION_PRECESION
public static final double RESOLUTION_PRECESION
Resolution accuracy, within the accuracy range, thinks that the two resolutions are equal.
-
logger
protected static final LocLogger logger
-
CACHEKEY
protected static final java.lang.String CACHEKEY
-
tileCols
public int tileCols
Tile width, the unit is the pixel, the default is 256 pixels.
-
tileRows
public int tileRows
Tile height, the unit is the pixel, the default is 256 pixels.
-
defaultDPI
protected int defaultDPI
DPI of picture.
-
-
Constructor Detail
-
AbstractRestMapProvider
public AbstractRestMapProvider(MapProviderSetting setting)
-
AbstractRestMapProvider
public AbstractRestMapProvider()
-
-
Method Detail
-
setProviderContext
public void setProviderContext(ProviderContext context)
Description copied from interface:ProviderContextAwareSets the service provider context
- Specified by:
setProviderContextin interfaceProviderContextAware- Parameters:
context- service provider context
-
loadMetaData
protected abstract boolean loadMetaData()
Load meta information for the Rest service.- Returns:
-
initSupportedMapNames
protected abstract java.util.List<java.lang.String> initSupportedMapNames()
Initialize the list of supported maps.- Returns:
-
checkSetting
protected abstract void checkSetting(MapProviderSetting setting)
Initialize the default map state.- Parameters:
setting-
-
getDefaultMapParameter
public MapParameter getDefaultMapParameter(java.lang.String mapName)
Returns the default map state.
Makes the center point of the map range as the default center point, makes the pixel size of a tile as the default picture size, the pixel size of a tile as the default picture size,
- Specified by:
getDefaultMapParameterin interfaceMapProvider- Parameters:
mapName- map name.- Returns:
- The default map state.
-
initDefaultMapParameter
protected abstract java.util.Map<java.lang.String,MapParameter> initDefaultMapParameter()
Initializes the default map state, the return value is a map, the key is the map name, and the value is the map parameter object.
- Returns:
- map state mapping, the key is the map name, and the value is the map parameter object.
-
rectifyViewBoundsAndViewer
protected boolean rectifyViewBoundsAndViewer(MapParameter defaultMapParameter)
Corrects the map state so that the ratio of map width to height is equal to the ratio of plot width to plot height
-
getMapImage
public MapImage getMapImage(MapParameter mapParameter, ImageOutputOption outputOption)
According to the map parameters, picture output settings to obtain the map image.
- Specified by:
getMapImagein interfaceMapProvider- Parameters:
mapParameter- map parametersoutputOption- Picture output settings.- Returns:
- Map image object.
-
outputImage
protected void outputImage(MapParameter param, ImageOutputOption outputOption, double currentResolution, java.lang.String targetFileName)
Draws a picture in real time. According to the map parameters, draws to the specified path.- Parameters:
param-outputOption-currentResolution-targetFileName-
-
isResolutionSupported
protected boolean isResolutionSupported(double currentResolution)
-
getTileOrigin
protected abstract Point2D getTileOrigin()
Gets the geographic coordinates of the upper left corner of the map.
- Returns:
- The geographic coordinates of the upper left corner of the map.
-
outputImageToFile
protected void outputImageToFile(java.lang.String targetFileName, java.awt.image.BufferedImage targetImage)The area in which each tile coincide with the given range are spliced into a picture, write to the specified file
- Parameters:
targetFileName- The specified file nametargetImage- Results picture
-
outputStreamToFile
protected boolean outputStreamToFile(java.io.InputStream resultStream, java.lang.String targetFileName)Writes a byte stream to a file- Parameters:
resultStream-targetFileName-
-
getTileImageStream
protected abstract java.io.InputStream getTileImageStream(MapParameter tileParam, ImageOutputOption outputOption, int colIndex, int rowIndex, double currentResolution)
Gets the image stream for the specified tile.
- Parameters:
tileParam-outputOption-colIndex-rule-currentResolution-- Returns:
-
getTileIndex
protected AbstractRestMapProvider.TileIndex getTileIndex(Point2D point, double currentResolution, Point2D tileOriginPos)
Returns the tile index of the tile where the specified point is located- Parameters:
point-currentResolution-- Returns:
-
getTileBounds
protected Rectangle2D getTileBounds(double currentResolution, int colIndex, int rowIndex, Point2D tileOrigin)
With the given resolution, returns the range of tiles where the specified point is located.- Returns:
-
getMapImageData
protected byte[] getMapImageData(java.lang.String imageFilePath)
-
getMapParameter
public MapParameter getMapParameter(java.lang.String mapName)
Description copied from interface:MapProviderGets the status of a map (the map parameters) after outputting map images last time.
- Specified by:
getMapParameterin interfaceMapProvider- Parameters:
mapName- The specified map name.- Returns:
- Map parameters.
-
getOverview
public Overview getOverview(MapParameter mapParameter, ImageOutputOption outputOption)
Description copied from interface:MapProviderGets eagle-eye map according to map parameters and image output settings.
- Specified by:
getOverviewin interfaceMapProvider- Parameters:
mapParameter- Map parameters.outputOption- Image output settings.- Returns:
- Eagle-eye object.
-
viewEntire
public MapImage viewEntire(java.lang.String layerName, MapParameter mapParameter, ImageOutputOption outputOption)
Conducts full display according to the map layer name, map parameters and picture output settings.
The layer name specified in the parameter refers to the geographic circumference of the minimum circumscribed rectangle as full display of the contents of the layer.
- Specified by:
viewEntirein interfaceMapProvider- Parameters:
layerName- Map layer name, that is, the geographic circumference of the minimum circumscribed rectangle as full display of the contents of the layer.mapParameter- Map parametersoutputOption- Image output settings.- Returns:
- map object.
-
getNames
public java.util.List<java.lang.String> getNames()
Returns the map name list.- Specified by:
getNamesin interfaceMapProvider- Returns:
- The list of map names.
-
findNearest
public QueryResult findNearest(java.lang.String mapName, Geometry geometry, double maxDistance, QueryParameterSet queryParameterSet)
Description copied from interface:MapProviderQueries the nearest geometric object on a specified map whose distance to a specified geometry is within a certain value. When limit the number of returned geometric objects (specified by
QueryParameterSet.expectCount), the query result is the expectCount features nearest to the center in the records. There is no orders of expectCount.- Specified by:
findNearestin interfaceMapProvider- Parameters:
mapName- The map name.geometry- The geometric object.maxDistance- The maximum distance, of which the unit is identical with that of the map specified with mapName parameter.queryParameterSet- Query parameters can query multiple layers of a map. The query parameters in a single layer can be set inqueryParameterSet.queryParams[i].- Returns:
- Query result object.
-
getResource
public java.lang.String getResource(java.lang.String mapName, ResourceParameter resourceParameter)Description copied from interface:MapProviderGets the resource image of a specified map according to a resource image parameter.
- Specified by:
getResourcein interfaceMapProvider- Parameters:
mapName- The map name.resourceParameter- The resource image parameter.- Returns:
- The resource image address.
-
measureArea
public MeasureResult measureArea(java.lang.String mapName, Point2D[] points, MeasureParameter measureParam)
Description copied from interface:MapProviderMeasures areas on a specified map based on 2D geographic coordinates and a measuring parameter.
- Specified by:
measureAreain interfaceMapProvider- Parameters:
mapName- The map name.points- The array of 2D geographic coordinates.measureParam- The measuring parameter.- Returns:
- Measurement result object.
-
measureDistance
public MeasureResult measureDistance(java.lang.String mapName, Point2D[] points, MeasureParameter measureParam)
Description copied from interface:MapProviderMeasures distances on a specified map based on 2D geographic coordinates and a measuring parameter.
- Specified by:
measureDistancein interfaceMapProvider- Parameters:
mapName- The map name.points- The array of 2D geographic coordinates.measureParam- The measuring parameter.- Returns:
- Measurement result object.
-
queryByDistance
public QueryResult queryByDistance(java.lang.String mapName, Geometry geometry, double distance, QueryParameterSet queryParameterSet)
Description copied from interface:MapProviderQueries all the geometric objects on a specified map whose distances to a specified geometry are within a certain value.
Which means to query all the geometries within a circle whose center is the specified geometry.
- Specified by:
queryByDistancein interfaceMapProvider- Parameters:
mapName- The map name.geometry- The geometric object.distance- The querying distance.queryParameterSet- Query parameters can query multiple layers of a map. The query parameters in a single layer can be set inqueryParameterSet.queryParams[i].- Returns:
- Query result object.
-
checkParameterNull
protected static void checkParameterNull(java.lang.Object obj, java.lang.String parameterName)
-
dispose
public void dispose()
Description copied from interface:DisposableRelease the resource object.
- Specified by:
disposein interfaceDisposable
-
clearCache
public void clearCache(java.lang.String mapName, Rectangle2D bounds)Clears the cache image of the map's corresponding range.
- Specified by:
clearCachein interfaceMapProvider- Parameters:
mapName- Map name.bounds- Map range.
-
queryByGeometry
public QueryResult queryByGeometry(java.lang.String mapName, Geometry geometry, SpatialQueryMode spatialQueryMode, QueryParameterSet queryParameterSet)
Description copied from interface:MapProviderQueries geometric objects that satisfy a certain spatial relationship with a specified geometric object and meet query conditions on a specified map.
- Specified by:
queryByGeometryin interfaceMapProvider- Parameters:
mapName- The map name.geometry- The geometric object, which has spatial information and shape information, but no attribute information.spatialQueryMode- The spatial query mode, which defines several spatial relationships between geometries, and it allows users to construct filter conditions to perform querying. For example, searching spatial objects which are contained in specified region object, or which have a disjoint or adjacent relationship with the specified region object.queryParameterSet- Query parameters can query multiple layers of a map. The query parameters in a single layer can be set inqueryParameterSet.queryParams[i].- Returns:
- Query result object.
-
queryBySQL
public QueryResult queryBySQL(java.lang.String mapName, QueryParameterSet queryParameterSet)
Description copied from interface:MapProviderPerforms SQL query on specified map.
- Specified by:
queryBySQLin interfaceMapProvider- Parameters:
mapName- The map name.queryParameterSet- Query parameters can query multiple layers of a map. The query parameters in a single layer can be set inqueryParameterSet.queryParams[i].- Returns:
- Query result object.
-
queryByBounds
public QueryResult queryByBounds(java.lang.String mapName, Rectangle2D bounds, QueryParameterSet queryParameterSet)
Description copied from interface:MapProviderQueries the geometries in the specified range on the map.
- Specified by:
queryByBoundsin interfaceMapProvider- Parameters:
mapName- The map name.bounds- The specified query bounds.- Returns:
- Query result object.
-
getContent
public java.lang.String getContent(java.lang.String url, java.lang.String method) throws java.io.IOExceptionExecute an HTTP request on the specified URL to get the response.
- Parameters:
url- The specified URI.method- An HTTP method that executes a URI, such as "GET".- Returns:
- The HTTP response converted into the text format.
- Throws:
java.io.IOException
-
setDefaultMapParameter
public MapParameter setDefaultMapParameter(MapParameter mapParameter)
Description copied from interface:MapProviderSets the default map parameters.
- Specified by:
setDefaultMapParameterin interfaceMapProvider- Parameters:
mapParameter- Map parameters.- Returns:
- The map parameter object.
-
isResolutionEquals
protected boolean isResolutionEquals(double resolution1, double resolution2)
-
sendRequestByHttpURLConnection
protected java.util.Map<java.lang.String,java.lang.Object> sendRequestByHttpURLConnection(java.lang.String urlStr, java.lang.String method, java.io.InputStream requestStream) throws java.io.IOExceptionSend an HTTP request via
HttpURLConnection.- Parameters:
urlStr- Request URI.method- HTTP methods such as "GET".requestStream- Request stream.- Returns:
- Response to the result mapping, the key for the project name, such as status, entity, value for the project value.
- Throws:
java.io.IOException
-
resolutionToScale
protected double resolutionToScale(double resolution, int dpi, Unit mapUnit)According to the resolution, DPI, map units, calculate the scale.
- Parameters:
resolution- The specified resolution in units of "pixels / map units".dpi- Specified DPI.mapUnit- Map unit, which corresponds to the unit of resolution.- Returns:
- the scale.
-
getJsonConverter
public JsonConverter getJsonConverter()
Gets JSON Converter.
The JSON converter can convert a JSON string to a Java object.
- Returns:
-
setJsonConverter
protected void setJsonConverter(JsonConverter jsonConverter)
Sets JSON converter, the JSON converter can convert a JSON string to a Java object.
- Parameters:
jsonConverter- JSON converter.
-
getDefaultMapParameters
protected java.util.Map<java.lang.String,MapParameter> getDefaultMapParameters()
-
setDefaultMapParameters
protected void setDefaultMapParameters(java.util.Map<java.lang.String,MapParameter> defaultMapParameters)
Sets the default map state.
- Parameters:
defaultMapParameters- Map state mapping, the key is the map name, and the value is the map parameter object.
-
getCacheHelper
protected ImageCacheHelper getCacheHelper()
-
getMapProviderSetting
public MapProviderSetting getMapProviderSetting()
-
setMapProviderSetting
public void setMapProviderSetting(MapProviderSetting mapProviderSetting)
-
getSupportResolutions
public abstract double[] getSupportResolutions()
Returns the resolution of the current service support. If all resolutions are supported, empty is returned.- Returns:
-
-