Creating and implementing the service component

Feedback


Below is an example of a Temperature service component interface and its implementation class "TemperatureImpl" which implements two methods to get maps (getMapImage) and to get weather information (getTemperature).

Temperature service component interface:

package com.supermap.sample.temperature;

public interface Temperature {

    String getTemperature();

    String getMapImage();

}

TemperatureImpl code:

package com.supermap.sample.temperature;

import java.util.HashMap;

import com.supermap.services.components.commontypes.*;

import com.supermap.services.components.spi.MapProvider;

import com.supermap.services.providers.UGCMapProvider;

import com.supermap.services.providers.UGCMapProviderSetting;

public class TemperatureImpl implements Temperature {

    private MapProvider mapProvider = null;

    private MapParameter defaultMapParam = null;

    private static String outputPath = "../webapps/iserver/output";

    private static final String WORKSPACE_CHINA = "../samples/data/China/China100.smwu";

    public TemperatureImpl() {

        UGCMapProviderSetting mapSetting = new UGCMapProviderSetting();

        mapSetting.setWorkspacePath(WORKSPACE_CHINA);

        mapSetting.setOutputPath(outputPath);

        mapSetting.setOutputSite("http://localhost:8090/iserver/output");

        mapSetting.setMaps("China");

        mapProvider = new UGCMapProvider(mapSetting);

        defaultMapParam = mapProvider.getDefaultMapParameter("China");

        this.defaultMapParam.viewer = new Rectangle(new Point(0, 0), new Point(800, 600));

    }

    @Override

    public String getTemperature() {

        String temp;

        temp = "Sunny, 10 ℃";

        return temp;

    }

    @Override

    public String getMapImage() {

        String imageUrl = null;

        if (defaultMapParam != null) {

            ImageOutputOption imageOutputOption = new ImageOutputOption();

            imageOutputOption.format = OutputFormat.JPG;

            imageOutputOption.transparent = false;

            ThemeLabel themeLabel = new ThemeLabel();

            themeLabel.memoryData = new HashMap<String, String>();

            String cityName = "Beijing";

            String temp = cityName + "," + getTemperature();

            themeLabel.memoryData.put(cityName, temp);

            themeLabel.labelExpression = "NAME";

            themeLabel.labelBackShape = LabelBackShape.ROUNDRECT;

            Style style = new Style();

            style.fillBackColor = new Color(java.awt.Color.MAGENTA.getRed(), java.awt.Color.MAGENTA.getGreen(), java.awt.Color.MAGENTA.getBlue());

            style.fillBackOpaque = true;

            style.fillForeColor = new Color(java.awt.Color.YELLOW.getRed(), java.awt.Color.YELLOW.getGreen(), java.awt.Color.YELLOW.getBlue());

            style.fillGradientMode = FillGradientMode.RADIAL;

            themeLabel.backStyle = style;

            TextStyle textStyle = new TextStyle();

            textStyle.backColor = new Color(java.awt.Color.BLUE.getRed(), java.awt.Color.BLUE.getGreen(), java.awt.Color.BLUE.getBlue());

            textStyle.fontWidth = 100000;

            textStyle.fontHeight = 100000;

            textStyle.align = TextAlignment.MIDDLECENTER;

            themeLabel.uniformStyle = textStyle;

            DatasetVectorInfo datasetVectorInfo = new DatasetVectorInfo();

            datasetVectorInfo.name = "China_Capital_P";

            datasetVectorInfo.type = DatasetType.POINT;

            datasetVectorInfo.dataSourceName = "China";

            UGCThemeLayer themelayer = new UGCThemeLayer();

            themelayer.theme = themeLabel;

            themelayer.datasetInfo = datasetVectorInfo.copy();

            themelayer.visible = true;

            themelayer.displayFilter = "NAME = '" + cityName + "'";

            this.defaultMapParam.layers.get(0).subLayers.add(true, themelayer);

            this.defaultMapParam.center = new Point2D(11000000.0, 3500000.0);

            this.defaultMapParam.scale = 0.00000003;

            MapImage mapImage = mapProvider.getMapImage(this.defaultMapParam, imageOutputOption);

            imageUrl = mapImage.imageUrl;

        }

        return imageUrl;

    }

}

After compiling the above code, you need copy the entire com directory (%SuperMap iServer_HOME%\samples\code\DSSE\Temperature_SC\bin\com), which inlcudes the Temperature.class file, to the application directory of SuperMap iServer Web, i.e. %SuperMap iServer_HOME%webapps\iserver\WEB-INF\classes (if the classes folder does not exist yet, create it first).