分享

server 专题图

 WindySky 2009-01-07

专题图需要使用扩展map的方式来实现,我把步骤说一下,请您试一下!

1、后台java代码

package com.supermap.server.components;

import java.util.*;
import com.supermap.services.commontypes.*;

public class MyMap extends Map{
    public MyMap(String mapName, String hostAddress, int port, HashMap stateManager) {
        //调用父类构造函数
        super(mapName, hostAddress, port, stateManager);
    }

    //重载父类Map的execute方法
    public boolean execute(String command, String parameter) {
        //调用父类的execute方法,并将父类execute方法的返回值附给变量flag
        boolean flag = super.execute(command, parameter);

        //如果flag为false,说明父类对传入的command命令不能处理,此时对父类进行扩展,处理父类execute方法不能处理的命令
        if(!flag){
   if (command.equals("makeXXX")) {//自己定义的名称
    ...//实例化专题图对象代码themeXXX

    MapParam mapParam = super.getMapParam();
    LayerCollection layerCollection = (LayerCollection) mapParam.layerCollection
      .get(this.getMapName());
    boolean success = false;
    SuperMapLayerSetting superMapLayerSetting = null;
    Layer newLayer = null;
    if (layerCollection != null) {
     Layer layer = (Layer) layerCollection.get("XX@XX");//要做专题图的图层名称格式是:数据集@数据源
     if (layer != null && layer.isHavingValidDatasetInfo()) {
      SuperMapLayerSetting layerSetting = (SuperMapLayerSetting) layer.getLayerSetting();
      DatasetInfo datasetInfo = new DatasetInfo(layerSetting.datasetInfo);
      if (datasetInfo != null) {
       superMapLayerSetting = new SuperMapLayerSetting(themeXXX, layerSetting);
      }
     }
    }
    if (superMapLayerSetting != null) {
     newLayer = new Layer(superMapLayerSetting);
     newLayer.visible = true;
     success = layerCollection.addLayer(true, newLayer);
     if (success) {
      ISession session = this.getSession();
      session.setAttribute(XMLTool.getNodeText(parameter,"mapName")+ "_"+ mapParam.layerCollection.hashCode() + "", mapParam.layerCollection);
      session.setAttribute(session.getId()+ this.getMapName(), this);
      this.commandResultsList.put(command,mapParam.layerCollection.hashCode() + "");
     } else {
      System.out.println("添加专题图层失败");
     }
    }
  }
        return flag;
    }
}

2、设置mapconfig.xml文件

<map mapClass="com.supermap.server.components.MyMap(上面代码里面的包名+类名)" mapId="MyMap(随便起的)">
3、修改加载的mapname名称,改为上面的mapid

4、javascript代码调用

 function makeXXX()\\函数名任意

{
  SuperMap.Committer.commitMapCmd("MyMap"(与mapname的名字相同), "makeXXX(与自己定义的方法相同)", null,null(如果不需要传递参数两个都为null), onquerybysqlComplete(回调函数));
 }
 function onquerybysqlComplete(e)
 {
  mapControl.getMap()._params.layersKey = e;
  mapControl.refreshMapControl();

 }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多