Extending Service Provider

Feedback


The implementation of the service provider is as follows:

public class SampleProvider implements ProviderContextAware {

     ...

}

ProviderContextAware is used to get the service provider context, through which the configuration information of the service provider can be got.

For the configuration of the three-layer structure, see iServer Configuration File

 

Service Provider interface

The types of service providers already provided by SuperMap iServer include: MapProvider, DataProvider, RealspaceProvider, SpatialAnalystProvider, and TransportationAnalystProvider. SuperMap iServer has implemented these service providers to ensure the sources of GIS capabilities (Refer to Service Providers).

Users can extend service providers to expand the sources of GIS capabilities provided by SuperMap iServer.

Table 1 Interfaces or classes for extending service provider

Type Classes/Interfaces RemarkNote
MapProvider com.supermap.services.components.spi.MapProvider All map providers need to implement this interface.
The service provider that implements the interface can be used by the map component.
com.supermap.services.components.spi.AbstractRestMapProvider Encapsulated the basic functions needed to access REST map service, all the service providers using REST map service can use this class to extend.
com.supermap.services.components.spi.RemoteTiledMapProviderBase RemoteTiledMapProviderBase is an abstract class that used to aggregate the third-party map services. It implements ProviderContextAware and MapProvider.
(See: RemoteTiledMapProviderBase_Extension)
com.supermap.services.components.spi.LocalTiledMapProviderBase LocalTileProviderBase is an abstract class for extending the local map tile service, and the local map tiles are derived from ArcGIS.
(See: LocalTiledMapProviderBase_Extension)
Other implementation classes (See: Service Provider Introduction)  
DataProvider com.supermap.services.components.spi.DataProvider All data providers need to implement this interface.
The service provider that implements the interface can be used by the data component.
Other implementation classes (See: Service Provider Introduction)  
SpatialAnalystProvider com.supermap.services.components.spi.SpatialAnalystProvider All spatial analysis providers need to implement this interface.
The service provider that implements the interface can be used by the spatial analysis component.
Other implementation classes (See: Service Provider Introduction)  
TransportationAnalystProvider com.supermap.services.providers.spi.TransportationAnalystProvider All transportation analysis providers need to implement this interface.
The service provider that implements the interface can be used by the transportation analysis component.
Other implementation classes (See: Service Provider Introduction)  
RealspaceProvider com.supermap.services.components.spi.RealspaceProvider All realspace providers need to implement this interface.
The service provider that implements the interface can be used by the realspace component.
Other implementation classes (See: Service Provider Introduction)  

The restrictions above are not applicable to defining new service provider types to realize functions in a certain domain.

Service Provider context

In the service provider implementation class, the service provider context can be obtained through the ProviderContextAware interface, and the service provider configuration information can be obtained through the service provider context.

The configuration information of the service components is in services.xml. Below is the configuration for a service component: The configuration of service provider is as follows:

<provider class="com.supermap.sample.SampleProvider" name="sampleProvider">

        <config class="com.supermap.sample.SampleProviderSetting">

                <param1>default</param1>

                ...

        </config>

</provider>

Where, SampleProviderSetting is the configuration class of SampleProvider. param1 is the property of SampleProviderSetting. Through SampleProviderSetting, the service providers with different types and sources can be built together in iServer.

In the implementation class of the service provider, the service provider context which enables to get configuration (services.xml) of the service provider can be obtained from the ProviderContextAware interface.

public class SampleProvider implements ProviderContextAware{

        ...

        public void setProviderContext(ProviderContext context) {

                SampleProviderSetting sampleProviderSetting = context.getConfig(SampleProviderSetting.class);

                ...

        }

}

Where sampleProviderSetting is the configuration item <config/> of <provider/> in services.xml.

Extending RemoteTiledMapProviderBase

Introduction

RemoteTiledMapProviderBase is an abstract class that used to aggregate the third-party map services and build online map providers. It implements ProviderContextAware and MapProvider.

The main output method of this class is getTileImageUrl(TileImageParameter tileImageParameter).

  1. How to develop extension

You can aggregate a third-party map services by inheriting from the abstract class of RemoteTileProviderBase.

The methods are shown as follows:

  Note:

  1. Configuration and Deployment

Place the compiled classes files to %SuperMap iServer_HOME%\webap\ iserver\WEB-INF\(classes folder does not exist by default.), or the jar package to %SuperMap iServer_HOME%\webap\ iserver\WEB-INF\lib\. iServer can use extensions of the service provider classes. For configuration, see Configure service provider by XML.

  1. About cache

cacheEnabled() returns true or false that can be used to enable or disable using cache.

When MapParameter.cacheEnabled is true, the system uses image cache. The catalog is MapProviderSetting.getOutputPath(), and its path is "cache\MapName_ImageWidthxImageHeight\ScaleReciprocal\ImagexIndex\ImageyIndex.ImageSuffix". Meanwhile, this class also enables to cache the third-party map services, and the path is "cache\http\MapName_ImageWidthxImageHeight\ScaleReciprocal\ImagexIndexImageyIndex.ImageSuffix".

Sample

Here you are allowed to extend a map service provider. GoogleMapsMapProvider is inherited from TiledMapProviderBase. You can find the sample code in %SuperMap iServer_HOME%/samples/code/DSSE/GoogleMapsProviderSample.

The code for the implementation of GoogleMapsProvider is as follows:

GoogleMapsMapProvider.java

GoogleMapLayer in GoogleMapsMapProvider class represents that the current map uses the Google layer (When extend other provider, you can refer to GoogleMapLayer to define corresponding Layer). The codes of GoogleMapLayer are as follows:

GoogleMapLayer.java

Configuration class uses MapProviderSetting, as follows:

<provider class="com.supermap.sample.serviceprovider.GoogleMapsMapProvider" name="mapProvider-GoogleMaps">

    <config class="com.supermap.services.components.spi.MapProviderSetting">

    </config>

</provider>

Place the Jar package in %SuperMap iServer_HOME%/webapps/iserver/WEB-INF/lib after compiling.

Create a new map component--map-google to publish rest, WMS 1.1.1 services using mapProvider-GoogleMaps.

<component class="com.supermap.services.components.impl.MapImpl" interfaceNames="rest,wms111" name="map-google" providers="mapProvider-GoogleMaps">

    <config class="com.supermap.services.components.MapConfig">

    </config>

</component>

Access the map REST service with the root URI: http://<host>:<port>/iserver/services/map-google/rest. And access the map with the name googlemaps, which is declared in the implementation class of GoogleMapsMapProvider, through http://<host>:<port>/iserver/services/map-google/rest/maps/googlemaps.ijs. with the result shown as below:

Extending LocalTileProviderBase

Introduction

LocalTileProviderBase is used to extend the local map tile service. It implements the ProviderContextAware and MapProvider.

The method used to output map is getTileImage(TiledMapProviderBase.TileImageParameterparamTileImageParameter).

  1. How to develop

Users can inherit LocalTileProviderBase to extend the local map tile service.

Methods to use:

Note:

  1. Configure and Deploy

Place the compiled classes files to %SuperMap iServer_HOME%\webap\ iserver\WEB-INF\, or the jar package to %SuperMap iServer_HOME%\webap\ iserver\WEB-INF\lib\. iServer can use extensions of the service provider classes. For configuration, see Configure service provider by XML.

  1. About Cache

cacheEnabled() returns true or false which is used to set using cache or not.

rue means to use cache. The image cache directory, namely, the directory of MapProviderSetting.getOutputPath(), is “cache\MapName_ImageWidth x ImageHeight\ScaleReciprocal\Image x Index\Image y Index.ImageSuffix". Meanwhile, this class also caches for the third-party map services, and the path is "cache\http\MapName_ImageWidth x ImageHeight\ScaleReciprocal\Image x Index\Image y Index.ImageSuffix".

Sample

The sample takes ArcGISExplodedCacheMapProvider as an example which inherits from the class LocalTileProviderBase to demonstrate how to publish your local ArcGIS Server map tiles to SuperMap services. You can find the sample code in %SuperMap iServer_HOME%/samples/code/DSSE/ArcGISExplodedCacheMapProviderSample.

Notes: When generating ArcGIS Server tiles, choose "Exploded" as the format, and choose from NG8, PNG24, PNG32 as the image format.

ArcGISExplodedCacheMapProvider Sample Code:

ArcGISExplodedCacheMapProvider.java

For the class ArcGISExplodedCacheMapProvider, ArcGISExplodedCacheMapLayer means ArcGIS layer is used currently(to extend other map provider, please refer to ArcGISExplodedCacheMapLayer to define the Layer).

ArcGISExplodedCacheMapLayer Sample Code:

ArcGISExplodedCacheMapLayer.java


ArcGISXMLParseTool is used to get the conf.xml file of the ArcGIS Server tile directory and some node values in the conf.cdi file.

conf.xml file is as follows:

conf.cdi file is as follows:

ArcGISXMLParseTool Sample Code:

ArcGISXMLParseTool.java

ArcGISExplodedCacheMapProviderSetting inherits from MapProviderSetting. It is used to extend MapProviderSetting to set some specific map parameters. cachePath is the path to store the map caches and mapName is the map name.

ArcGISExplodedCacheMapProviderSetting Sample Code:

ArcGISExplodedCacheMapProviderSetting.java

Use ArcGISExplodedCacheMapProviderSetting that herits from MapProviderSetting to do the settings. You must set the cache path by <cachePath>. Optionally set the map name by <mapName>. If the map name is not set, the default will be used. Here shows how to do the settings:

<provider class="com.supermap.sample.serviceprovider.ArcGISExplodedCacheMapProvider" name="mapProvider-ArcGISExplodedCacheMap">

  <config class="com.supermap.sample.serviceprovider.ArcGISExplodedCacheMapProviderSetting">

    <cachePath>C:/arcgisserver/arcgiscache/China400/China400</cachePath>

      <mapName></mapName>

  </config>

</provider>

Place the compiled Jar to %SuperMap iServer_HOME%/webapps/iserver/WEB-INF/lib.

Create a new "map service component" map-arcgis that uses mapProvider-ArcGISMaps, and publish the service as rest, WMS 1.1.1:

<component class="com.supermap.services.components.impl.MapImpl" enabled="true" interfaceNames="wms111,rest" name="map-arcgis" providers="mapProvider-ArcGISExplodedCacheMap">  

</component>

Access the map REST functions via URI:http://<host>:<port>/iserver/services/map-arcgis/rest. Access the map via http://<host>:<port>/iserver/services/map-arcgis/rest/maps/arcgismaps.ijs. Arcgismaps is the map name that is declared in ArcGISExplodedCacheMapProvider. The result is as follows: