📄 testgj.java.svn-base
字号:
/**
* @(#) TestGJ.java 2007-11-3
*
* TIANHUI 2007
*/
package com.th.workframe;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.UIManager;
import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.beans.toolbar.ToolbarBean;
import com.esri.arcgis.carto.FDOGraphicsLayerFactory;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.IFDOGraphicsLayerFactory;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.UniqueValueRenderer;
import com.esri.arcgis.carto.esriViewDrawPhase;
import com.esri.arcgis.controls.ControlsMapFullExtentCommand;
import com.esri.arcgis.controls.ControlsMapPanTool;
import com.esri.arcgis.controls.ControlsMapZoomInTool;
import com.esri.arcgis.controls.ControlsMapZoomOutTool;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.display.CartographicLineSymbol;
import com.esri.arcgis.display.CharacterMarkerSymbol;
import com.esri.arcgis.display.IColor;
import com.esri.arcgis.display.ITemplate;
import com.esri.arcgis.display.RgbColor;
import com.esri.arcgis.display.SimpleLineSymbol;
import com.esri.arcgis.display.Template;
import com.esri.arcgis.display.esriSimpleLineStyle;
import com.esri.arcgis.geodatabase.ICursor;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IEnumDataset;
import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geodatabase.IRow;
import com.esri.arcgis.geodatabase.QueryFilter;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.systemUI.esriCommandStyles;
/**
* <code><strong> TestGJ 简单类说明 </strong><code>
*
* @author <strong> GUJUN </strong>
* @version 2007-11-3 下午02:47:07
* @since 1.0
*/
public class TestGJ
extends JFrame
implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
/* ArcGIS */
private AoInitialize aoInit = null;
private IFeatureWorkspace ifw = null;
private MapBean map = null;
private ToolbarBean toolbar = null;
TH_CharacterMarkerSymbol tcms1, tcms2, tcms3, tcms4;
/* 框架组件 */
private JPanel panelMain = null;
/**
* 构造函数
* @throws Exception
*/
public TestGJ() throws Exception {
super("ArcGIS 的地图渲染与修饰");
//注册Engine
EngineInitializer.initializeVisualBeans();
aoInit = new AoInitialize();
aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
//连接SDE
connectionSDE();
//构建地图
buildMap();
buildToolBar();
//构建窗口面板布局
JButton bt = new JButton();
bt.setText("变 变 变");
bt.addActionListener(this);
//加入组件到主面板
panelMain = new JPanel(new BorderLayout());
panelMain.add("Center", map);
panelMain.add("South", bt);
panelMain.add("North", toolbar);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
String msg = "关闭?";
int flag = JOptionPane.showConfirmDialog(null, msg, "确认信息", JOptionPane.YES_NO_OPTION);
if(flag == JOptionPane.YES_OPTION) {
((JFrame)we.getSource()).setVisible(false);
try { aoInit.shutdown(); }catch (Exception e) { }
System.exit(0);
}//Endif
}
});
this.setContentPane(panelMain);
this.setBounds(100, 100, 800, 600);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
this.setVisible (true);
}
/**
* 连接SDE
*/
public void connectionSDE() throws Exception {
PropertySet ps = new PropertySet();
ps.setProperty("SERVER", "192.168.1.220");
ps.setProperty("INSTANCE", "5151");
ps.setProperty("USER", "SDE");
ps.setProperty("PASSWORD", "SDE");
ps.setProperty("VERSION", "SDE.DEFAULT");
SdeWorkspaceFactory swf = new SdeWorkspaceFactory();
ifw = (IFeatureWorkspace) swf.open(ps, 0);
}
/**
* buildMap() 构建地图组件
*/
public void buildMap() throws Exception {
map = new MapBean();
//去掉地图边框.很关键,影响map的显示尺寸
map.setBorderStyle(com.esri.arcgis.controls.esriControlsBorderStyle.esriNoBorder);
map.setShowScrollbars(false);
map.setBackColor(0);
//map.set
//开始加载
IEnumDataset edst = ifw.openFeatureDataset("TestGJ").getSubsets();
IDataset ds = edst.next();
while(ds != null) {
System.out.print("加载 " + ds.getName() + "....");
int tmpType = ds.getType();
if(tmpType == com.esri.arcgis.geodatabase.esriDatasetType.esriDTNetworkDataset) {
//
}else if(tmpType == com.esri.arcgis.geodatabase.esriDatasetType.esriDTFeatureClass) {
IFeatureClass ifc = ifw.openFeatureClass(ds.getName());
if(ds.getName().indexOf("Junction") < 0) {
if(ds.getName().indexOf("Text_Layer") < 0) {
IFeatureLayer layer = new FeatureLayer();
layer.setName(ds.getName());
layer.setFeatureClassByRef(ifc);
map.addLayer(layer, 0);
}else {
IFDOGraphicsLayerFactory fdoFactory = new FDOGraphicsLayerFactory();
map.addLayer(fdoFactory.openGraphicsLayer(ifw, ifw.openFeatureDataset("TestGJ"), ds.getName()), 0);
}//Endif
}//Endif
}//Endif
System.out.println(" 完成");
ds = edst.next();
}//Endwhile
fee();////////////////////
map.refresh(esriViewDrawPhase.esriViewGeography, null, null);
}
public void fee() throws Exception {
//从MapBean中获得要修饰的图层
FeatureLayer fl = (FeatureLayer) map.getLayer(0);
int fieldNumber1 = fl.findField("ABC");
int fieldNumber2 = fl.findField("DEF");
System.out.println(fieldNumber1 + "==========" + fieldNumber2);
//设置修饰参数
UniqueValueRenderer uniqueValueRenderer = new UniqueValueRenderer();
uniqueValueRenderer.setFieldCount(2);
uniqueValueRenderer.setField(0, "ABC");
uniqueValueRenderer.setField(1, "DEF");
uniqueValueRenderer.setFieldDelimiter(",");
//查找字段
QueryFilter queryFilter = new QueryFilter();
queryFilter.addField("ABC");
queryFilter.addField("DEF");
//queryFilter.setWhereClause("objectid > 0");
ICursor cursor = fl.ITable_search(queryFilter, true);
IRow nextRow = cursor.nextRow();
while (nextRow != null) {
IRow nextRowBuffer = nextRow;
String codeValue = (String) nextRowBuffer.getValue(fieldNumber1);
codeValue += "," + (String) nextRowBuffer.getValue(fieldNumber2);
//修饰Line标记
/*CartographicLineSymbol cls = new CartographicLineSymbol();
//设置标记颜色
IColor ic = new RgbColor();
if("1".equals(codeValue)) {
ic.setRGB(0x0000FF);
width = 1;
}else if("2".equals(codeValue)) {
ic.setRGB(0x00FFFF);
width = 2;
}else if("3".equals(codeValue)) {
ic.setRGB(0xFFFFFF);
width = 4;
}//Endif
cls.setColor(ic);
cls.setWidth(width);
cls.setOffset(0);
cls.setCap(1);
cls.setJoin(1);
Template tl = new Template();
tl.addPatternElement(5, 5);
cls.setTemplateByRef(tl);
//修饰Line结束
*/
if("1,1".equals(codeValue)) {System.out.println("--------------");
tcms1 = new TH_CharacterMarkerSymbol("New_Elec", 70, TH_CharacterMarkerSymbol.FONT_COLOR_RED, 20);
uniqueValueRenderer.addValue(codeValue, codeValue, tcms1);
}else if("2,1".equals(codeValue)) {
tcms2 = new TH_CharacterMarkerSymbol("New_Elec", 72, TH_CharacterMarkerSymbol.FONT_COLOR_YELLOW, 40);
uniqueValueRenderer.addValue(codeValue, codeValue, tcms2);
}else if("1".equals(codeValue)) {
tcms3 = new TH_CharacterMarkerSymbol("New_Elec", 74, TH_CharacterMarkerSymbol.FONT_COLOR_PURPLE, 60);
uniqueValueRenderer.addValue(codeValue, codeValue, tcms3);
}else {
tcms4 = new TH_CharacterMarkerSymbol("New_Elec", 76, TH_CharacterMarkerSymbol.FONT_COLOR_GREEN, 80);
uniqueValueRenderer.addValue(codeValue, codeValue, tcms4);
}
//tcms4.setAngle(90);
//uniqueValueRenderer.setRotationField("FLAG");
//uniqueValueRenderer.setRotationType(2);
//加入修饰
//uniqueValueRenderer.addValue(codeValue, codeValue, cls);
//uniqueValueRenderer.addValue(codeValue, codeValue, tcms);
System.out.println("***" + codeValue);///////////////
//uniqueValueRenderer.setDefaultSymbol(new TH_CharacterMarkerSymbol("New_Elec", 78, TH_CharacterMarkerSymbol.FONT_COLOR_WHITE, 90));
//int[] tt = {0x00FFFF, 0xFFFFFF, 0xFF0000};
//uniqueValueRenderer.setDefaultSymbol(new TH_TransformerSymbol(1, 40, tt, 0x000000));
//uniqueValueRenderer.setDefaultSymbol(new TH_BreakerSymbol(1, 40, 0x00FFFF, 0x000000));
//uniqueValueRenderer.setDefaultSymbol(new TH_DisconnectorSymbol(0, 40, 0x00FF00, 0x000000));
uniqueValueRenderer.setDefaultSymbol(new TH_ReactorSymbol(40, 0x00FF00, 0x000000));
uniqueValueRenderer.setUseDefaultSymbol(true);
nextRow =cursor.nextRow();
}
fl.setRendererByRef(uniqueValueRenderer);
}
/**
* buildToolBar() 构建工具栏组件
*/
public void buildToolBar() throws Exception {
toolbar = new ToolbarBean();
toolbar.setItemsString("8|controls/ControlsSelectTool|0|-1|0|0|1;5|controls/ControlsAddDataCommand|0|-1|0|0|1");
//设置工具栏停止任何自动发生的更新
toolbar.setUpdateInterval(0);
toolbar.addItem( new ControlsMapZoomInTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly );
toolbar.addItem( new ControlsMapZoomOutTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly );
toolbar.addItem( new ControlsMapPanTool(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly );
toolbar.addItem( new ControlsMapFullExtentCommand(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconOnly );
toolbar.setBuddyControl(map);
}
public void actionPerformed(ActionEvent e) {
try {
tcms1.setColor(TH_CharacterMarkerSymbol.FONT_COLOR_BLUE);
tcms2.setColor(TH_CharacterMarkerSymbol.FONT_COLOR_BLUE);
tcms3.setColor(TH_CharacterMarkerSymbol.FONT_COLOR_BLUE);
tcms4.setColor(TH_CharacterMarkerSymbol.FONT_COLOR_BLUE);
tcms1.setCharacterIndex(71);
tcms2.setCharacterIndex(73);
tcms3.setCharacterIndex(75);
tcms4.setCharacterIndex(77);
map.refresh(esriViewDrawPhase.esriViewGeography, null, null);
} catch (Exception ex) {
// TODO: handle exception
ex.printStackTrace();
}
System.out.println("aaaa");
}
/**
* 程序入口
*/
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
try {
new TestGJ();
} catch (Exception e) {
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -