supermap iserver中实现领域模块集成到服务管理器

参考:http://support.supermap.com.cn/DataWarehouse/WebDocHelp/iServer/index.htm

然后点击【iServer开发与扩展指南】-【扩展iserver】-【领域空间服务扩展】-【领域模块集成到服务管理器】

 

一,服务提供者层的扩展

  1. 新建java工程,并导入jar包,jar包路径:

D:\supermap-iserver-9.1.0a-win64-deploy\supermap-iserver-9.1.0a-win64-deploy\webapps\iserver\WEB-INF\lib

注意:TemperatureProvider.properties应该放在META-INF/extensions/providers目录下,因为这是服务提供者元信息。如果是服务组件元信息,那就放在META-INF/extensions/components目录下。如果是服务接口元信息,就放在META-INF/extensions/interfaces目录下。

 

目录结构如下:

FileSetting.java如下:

package com.supermap.sample.temperature;
public class FileSetting {
          private String filePath;
             public void setFilePath(String filePath) {
                 this.filePath = filePath;
             }
             public String getFilePath() {
                 return filePath;
             }
}

TemperatureProvider.java如下:

package com.supermap.sample.temperature;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.LinkedList;
import com.supermap.services.components.spi.ProviderContext;
import com.supermap.services.components.spi.ProviderContextAware;
public class TemperatureProvider implements ProviderContextAware  {
	private String filePath;
    public String GetTemperature(String cityName) throws Exception {
        String temperature = null;
        LinkedList<String> list = new LinkedList<String>();

        File f = new File(filePath);
        InputStreamReader isr = new InputStreamReader(new FileInputStream(f), "UTF-8");
        BufferedReader reader = new BufferedReader(isr);
        String str = null;
        while ((str = reader.readLine()) != null) {
            list.add(str);
        }
        reader.close();
        Iterator<String> it = list.iterator();
        while (it.hasNext()) {
            String strInfo = (String) it.next();
            if (strInfo.startsWith(cityName)) {
                int i = strInfo.indexOf("=");
                temperature = strInfo.substring(i + 1);
                break;
            }
        }
        if (temperature != null) {
            return temperature;
        } else {
            temperature = "没有 " + cityName + " 城市的天气信息";
            return temperature;
        }
    }
    public void setProviderContext(ProviderContext context) {
        FileSetting file = context.getConfig(FileSetting.class);
        this.filePath = file.getFilePath();
    }
}

FileSetting_zh_CN.js如下:

res["com.supermap.sample.temperature.TemperatureProvider"] = [new configParam("filePath", "温度信息文件的路径", "Text", false)];
typeToDisplayMapping["com.supermap.sample.temperature.TemperatureProvider"] = "温度服务提供者";

TemperatureProvider.properties如下:

implementation=com.supermap.sample.temperature.TemperatureProvider
paramType=com.supermap.sample.temperature.FileSetting
alias=温度服务提供者

2.将工程导出为jar包

右键工程-【export】-【Java】-【Jar file】

注意:使用 Eclipse 打 Jar 包时,需要勾上“Add directory entries”一项,如下图所示:

3.将导出的jar包放在目录

D:\supermap-iserver-9.1.0a-win64-deploy\supermap-iserver-9.1.0a-win64-deploy\webapps\iserver\WEB-INF\lib里面

4.启动iserver

D:\supermap-iserver-9.1.0a-win64-deploy\supermap-iserver-9.1.0a-win64-deploy\bin\startup.bat

5.添加服务提供者

访问 http://localhost:8090/iserver/manager/spsAndspsets  进行自定义模块的配置管理

  

即可看到添加的服务提供者类型

 

二,服务组件层的扩展

组件层的扩展和提供层很相似,这里我指出不同的地方。

  1. 新建java工程目录结构如下:

Temperature.java:

package com.supermap.sample.temperature;
public interface Temperature {
	String getTemperature();
    String getMapImage();
}

TemperatureImpl.java:

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));
	    }
	public String getTemperature() {
		 String temp;
	        temp = "晴,气温10度";
	        return temp;
	}
	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 = "北京";
	            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;
	}
}

FileSetting_zh_CN.js:

res["com.supermap.sample.temperature.TemperatureImpl"] = [new configParam("filePath", "温度信息文件的路径", "Text", false)];

typeToDisplayMapping["com.supermap.sample.temperature.TemperatureImpl"] = "温度服务提供者";

TemperatureImpl.properties:

implementation=com.supermap.sample.temperature.TemperatureImpl

alias=温度服务提供者

2.添加服务组件

  

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值