com.supermap.services.components.spi

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.

    • 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()
        
    • Method Detail

      • 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:
        getDefaultMapParameter in interface MapProvider
        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:
        getMapImage in interface MapProvider
        Parameters:
        mapParameter - map parameters
        outputOption - 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 name
        targetImage - 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: MapProvider

        Gets the status of a map (the map parameters) after outputting map images last time.

        Specified by:
        getMapParameter in interface MapProvider
        Parameters:
        mapName - The specified map name.
        Returns:
        Map parameters.
      • getOverview

        public Overview getOverview(MapParameter mapParameter,
                           ImageOutputOption outputOption)
        
        Description copied from interface: MapProvider

        Gets eagle-eye map according to map parameters and image output settings.

        Specified by:
        getOverview in interface MapProvider
        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:
        viewEntire in interface MapProvider
        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 parameters
        outputOption - Image output settings.
        Returns:
        map object.
      • getNames

        public java.util.List<java.lang.String> getNames()
        
        Returns the map name list.
        Specified by:
        getNames in interface MapProvider
        Returns:
        The list of map names.
      • findNearest

        public QueryResult findNearest(java.lang.String mapName,
                              Geometry geometry,
                              double maxDistance,
                              QueryParameterSet queryParameterSet)
        
        Description copied from interface: MapProvider

        Queries 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:
        findNearest in interface MapProvider
        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 in queryParameterSet.queryParams[i] .
        Returns:
        Query result object.
      • getResource

        public java.lang.String getResource(java.lang.String mapName,
                                   ResourceParameter resourceParameter)
        
        Description copied from interface: MapProvider

        Gets the resource image of a specified map according to a resource image parameter.

        Specified by:
        getResource in interface MapProvider
        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: MapProvider

        Measures areas on a specified map based on 2D geographic coordinates and a measuring parameter.

        Specified by:
        measureArea in interface MapProvider
        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: MapProvider

        Measures distances on a specified map based on 2D geographic coordinates and a measuring parameter.

        Specified by:
        measureDistance in interface MapProvider
        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: MapProvider

        Queries 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:
        queryByDistance in interface MapProvider
        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 in queryParameterSet.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: Disposable

        Release the resource object.

        Specified by:
        dispose in interface Disposable
      • clearCache

        public void clearCache(java.lang.String mapName,
                      Rectangle2D bounds)
        

        Clears the cache image of the map's corresponding range.

        Specified by:
        clearCache in interface MapProvider
        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: MapProvider

        Queries geometric objects that satisfy a certain spatial relationship with a specified geometric object and meet query conditions on a specified map.

        Specified by:
        queryByGeometry in interface MapProvider
        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 in queryParameterSet.queryParams[i] .
        Returns:
        Query result object.
      • queryBySQL

        public QueryResult queryBySQL(java.lang.String mapName,
                             QueryParameterSet queryParameterSet)
        
        Description copied from interface: MapProvider

        Performs SQL query on specified map.

        Specified by:
        queryBySQL in interface MapProvider
        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 in queryParameterSet.queryParams[i] .
        Returns:
        Query result object.
      • queryByBounds

        public QueryResult queryByBounds(java.lang.String mapName,
                                Rectangle2D bounds,
                                QueryParameterSet queryParameterSet)
        
        Description copied from interface: MapProvider

        Queries the geometries in the specified range on the map.

        Specified by:
        queryByBounds in interface MapProvider
        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.IOException
        

        Execute 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
      • 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.IOException
        

        Send 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.
      • 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: