|
專(zhuān)題圖需要使用擴(kuò)展map的方式來(lái)實(shí)現(xiàn),我把步驟說(shuō)一下,請(qǐng)您試一下!
1、后臺(tái)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) { //調(diào)用父類(lèi)構(gòu)造函數(shù) super(mapName, hostAddress, port, stateManager); }
//重載父類(lèi)Map的execute方法 public boolean execute(String command, String parameter) { //調(diào)用父類(lèi)的execute方法,并將父類(lèi)execute方法的返回值附給變量flag boolean flag = super.execute(command, parameter);
//如果flag為false,說(shuō)明父類(lèi)對(duì)傳入的command命令不能處理,此時(shí)對(duì)父類(lèi)進(jìn)行擴(kuò)展,處理父類(lèi)execute方法不能處理的命令 if(!flag){ if (command.equals("makeXXX")) {//自己定義的名稱(chēng) ...//實(shí)例化專(zhuān)題圖對(duì)象代碼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");//要做專(zhuān)題圖的圖層名稱(chēng)格式是:數(shù)據(jù)集@數(shù)據(jù)源 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("添加專(zhuān)題圖層失敗"); } } } return flag; } }
2、設(shè)置mapconfig.xml文件
<map mapClass="com.supermap.server.components.MyMap(上面代碼里面的包名+類(lèi)名)" mapId="MyMap(隨便起的)"> 3、修改加載的mapname名稱(chēng),改為上面的mapid
4、javascript代碼調(diào)用
function makeXXX()\\函數(shù)名任意
{ SuperMap.Committer.commitMapCmd("MyMap"(與mapname的名字相同), "makeXXX(與自己定義的方法相同)", null,null(如果不需要傳遞參數(shù)兩個(gè)都為null), onquerybysqlComplete(回調(diào)函數(shù))); } function onquerybysqlComplete(e) { mapControl.getMap()._params.layersKey = e; mapControl.refreshMapControl(); }
|