⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 annotatelayerproperties.java.svn-base

📁 aresde 空间数据开发 例子
💻 SVN-BASE
字号:
import java.awt.BorderLayout;
import java.awt.Frame;
import java.io.IOException;
import java.io.InputStream;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import com.esri.arcgis.beans.map.MapBean;
import com.esri.arcgis.carto.AnnotationVBScriptEngine;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.IAnnotateLayerProperties;
import com.esri.arcgis.carto.IAnnotateLayerPropertiesCollection;
import com.esri.arcgis.carto.IAnnotationExpressionEngine;
import com.esri.arcgis.carto.IBasicOverposterLayerProperties;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.IGeoFeatureLayer;
import com.esri.arcgis.carto.ILabelEngineLayerProperties;
import com.esri.arcgis.carto.ILabelStyle;
import com.esri.arcgis.carto.ILineLabelPlacementPriorities;
import com.esri.arcgis.carto.ILineLabelPosition;
import com.esri.arcgis.carto.IPointPlacementPriorities;
import com.esri.arcgis.carto.LabelEngineLayerProperties;
import com.esri.arcgis.carto.LineLabelPlacementPriorities;
import com.esri.arcgis.carto.LineLabelPosition;
import com.esri.arcgis.carto.PointPlacementPriorities;
import com.esri.arcgis.datasourcesGDB.SdeWorkspaceFactory;
import com.esri.arcgis.geodatabase.FeatureClass;
import com.esri.arcgis.geodatabase.FeatureDataset;
import com.esri.arcgis.geodatabase.IDataset;
import com.esri.arcgis.geodatabase.IEnumDataset;
import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geodatabase.IFeatureDataset;
import com.esri.arcgis.geodatabase.IFeatureWorkspace;
import com.esri.arcgis.geodatabase.IWorkspace;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.maplex.IMaplexAnnotateMap;
import com.esri.arcgis.maplex.IMaplexAnnotateMapProxy;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.PropertySet;
import com.esri.arcgis.system.esriLicenseProductCode;


/**
 * @author qishaofan
 *	用feature的一个字段,和VBscript脚本显示注记层
 */

public class AnnotateLayerProperties {
	private IFeatureClass featureClass;
	private MapBean mapBean = null;
	
	protected Shell shell;



	/**
	 * Open the window!!!!!!!!!!!!! 构建窗口有点问题
	 */
	public void open() {
		final Display display = Display.getDefault();
		shell = new Shell();
		shell.setSize(500, 375);
		shell.setText("SWT Application");
		shell.open();

		final Composite composite = new Composite(shell, SWT.EMBEDDED);
		//composite.setBounds(0, 0, 492, 341);

		final Frame frame = SWT_AWT.new_Frame(composite);

		mapBean = new MapBean();
		frame.add(mapBean, BorderLayout.CENTER);
		load();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
	}
	
	
	
	
	public void load(){
		try{
			IEnumDataset edst=FeatureDatasetFactory.getInstance().getIFeatureDataset("SDE.SLB_FF_").getSubsets();
			int i=0;
			for(IDataset ds=edst.next();ds!=null;ds=edst.next()){			//把featureClass转换为 Layer添加到MapBean
				//fcls=Workspace.openFeatureClass(ds.getName());
				featureClass=FeatureClassFactory.getInstance().getFeatureClass(ds.getName());
				
				if(featureClass.getFeatureType()!=com.esri.arcgis.geodatabase.esriDatasetType.esriDTNetworkDataset){
					IFeatureLayer layer=new FeatureLayer();
	
					//layerIndexMap.put(ds.getName(),i);						//注册图层名对应的层数
					
					layer.setName(ds.getName());
					layer.setFeatureClassByRef(featureClass);
					layer.setDisplayField("OBJECTID");
					mapBean.addLayer(layer, i++);
					IMaplexAnnotateMap maplexAnnotateMap = new IMaplexAnnotateMapProxy(layer);
					System.out.println("读出一个");
					LabelField_VB(layer);
					//LabelField_Simple(layer);
				}
				
			}
			

		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void main(String args[]) throws IOException{
		EngineInitializer.initializeEngine();
		final AoInitialize aoInit =new AoInitialize();
		try{
			//aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
			aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
			new AnnotateLayerProperties().open();
			
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			aoInit.shutdown();
		}
	}
	
	/**
	 * 用 VB脚本的方式给 feature增加标注 		
	 * 此方法参考了 f_Label_MakeLabels方法	
	 * @param pFeatureLayer
	 * @throws AutomationException
	 * @throws IOException
	 */
	private void LabelField_VB(IFeatureLayer pFeatureLayer) throws AutomationException, IOException{  
	   IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)pFeatureLayer; 
	   pGeoFeatureLayer.getAnnotationProperties().clear(); 
	   IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.getAnnotationProperties(); 
	   ILabelEngineLayerProperties pLabelEngine  = new LabelEngineLayerProperties();
	   pLabelEngine.setExpression("Function FindLabel ( [OBJECTID] )  FindLabel = [OBJECTID]&\"ff\" End Function"); 
//	   ITextSymbol pTextSyl = new TextSymbol();
//       // Dim pFont As stdole.StdFont
//       StdFont pFont = new StdFont();
//       pFont.setName("verdana");
//       pFont.setSize(50);
//       pTextSyl.setFont(pFont);
//       pTextSyl.setColor(new HsvColor());
//       pLabelEngine.setSymbolByRef(pTextSyl);
	   pLabelEngine.setIsExpressionSimple(false);						//设置是否是简单表达式
	   IAnnotationExpressionEngine i_AnnoVBScriptEngine =  new AnnotationVBScriptEngine();			//使用VBScript代理
       pLabelEngine.setExpressionParserByRef(i_AnnoVBScriptEngine);			//设置标签解析器用Vb代理
       //aLELayerProps.setBasicOverposterLayerPropertiesByRef(BOLP);
	   IAnnotateLayerProperties pAnnoLayerProps = (IAnnotateLayerProperties)pLabelEngine; 
	   pAnnoLayerPropsColl.add(pAnnoLayerProps); 
	   pGeoFeatureLayer.setDisplayAnnotation(true);
	}
	
	/**
	 * 用 简单的方式给 feature增加标注 
	 * @param pFeatureLayer
	 * @throws AutomationException
	 * @throws IOException
	 */
	private void LabelField_Simple(IFeatureLayer pFeatureLayer) throws AutomationException, IOException{  
	   IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)pFeatureLayer; 
	   pGeoFeatureLayer.getAnnotationProperties().clear(); 
	   IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.getAnnotationProperties(); 
	   ILabelEngineLayerProperties pLabelEngine  = new LabelEngineLayerProperties();
	   //pLabelEngine = (ILabelEngineLayerProperties)pServerContext.createObject("esriCarto.LabelEngineLayerProperties"); 
	   pLabelEngine.setExpression("[OBJECTID]"); 
   
	   IAnnotateLayerProperties pAnnoLayerProps = (IAnnotateLayerProperties)pLabelEngine; 
	   pAnnoLayerPropsColl.add(pAnnoLayerProps); 
	   pGeoFeatureLayer.setDisplayAnnotation(true);
	}
	
	
	
	
	
	//下个方法翻译于 vb的代码  还没有调用
	private void f_Label_MakeLabels(IGeoFeatureLayer pGeoLayer,String pLabelField,IBasicOverposterLayerProperties BOLP,
			ILabelStyle pLabelStyle) throws UnknownHostException, IOException{

	    if(pLabelStyle==null){
	        
	        BOLP.setBufferRatio(0);
	        BOLP.setFeatureWeight(0);
	        BOLP.setLabelWeight(3);
	        BOLP.setGenerateUnplacedLabels(false);
	    
	        ILineLabelPlacementPriorities LLPP = new LineLabelPlacementPriorities();
	    
	        LLPP.setAboveAfter(3);
	        LLPP.setAboveAlong(1);
	        LLPP.setAboveBefore(3);
	        LLPP.setAboveEnd(3);
	        LLPP.setAboveStart(3);
	        LLPP.setBelowAfter(3);
	        LLPP.setBelowAlong(3);
	        LLPP.setBelowBefore(3);
	        LLPP.setBelowEnd(3);
	        LLPP.setBelowStart(3);
	        LLPP.setCenterAfter(3);
	        LLPP.setCenterAlong(3);
	        LLPP.setCenterBefore(3);
	        LLPP.setCenterEnd(3);
	        LLPP.setCenterStart(3);
		        
	        ILineLabelPosition LLP = new LineLabelPosition();
	        LLP.setProduceCurvedLabels(false);
	     
	        LLP.setAbove(true);
	        LLP.setAtEnd(false);
	        LLP.setAtStart(false);
	        LLP.setBelow(false);
	        LLP.setInLine(false);
	        LLP.setLeft(false);
	        LLP.setOnTop(false);
	        LLP.setRight(false);
	            //'** These Are Exclusive
	        LLP.setParallel(true);
	        LLP.setPerpendicular(false);
	        LLP.setHorizontal(false);	        
	        
	        IPointPlacementPriorities PPP = new PointPlacementPriorities();
	        
	        PPP.setAboveCenter(2);
	        PPP.setAboveLeft(3);
	        PPP.setAboveRight(1);
	        PPP.setBelowCenter(3);
	        PPP.setBelowLeft(3);
	        PPP.setBelowRight(3);
	        PPP.setCenterLeft(3);
	        PPP.setCenterRight(2);
	        
	        
	        BOLP.setPointPlacementOnTop(true);
	        BOLP.setLineLabelPlacementPriorities(LLPP);
	        BOLP.setLineLabelPosition(LLP);
	        BOLP.setPointPlacementPriorities(PPP);
	        
	        //'添加文字注记
	        IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = null;
	        ILabelEngineLayerProperties aLELayerProps = null;
	        
	        IAnnotateLayerProperties pAnnotateLayerProperties = null;
	          
	        pAnnoLayerPropsColl = pGeoLayer.getAnnotationProperties();
//	        pAnnoLayerPropsColl.queryItem(0, aLELayerProps,null,null);

	        
	        pAnnotateLayerProperties = (IAnnotateLayerProperties)aLELayerProps;
//	        pAnnotateLayerProperties.setAnnotationMaximumScale(m_ScaleMax);
//	        pAnnotateLayerProperties.setAnnotationMinimumScale(m_ScaleMin);
	        

	       
	        aLELayerProps.setExpression(pLabelField);
	        //aLELayerProps.setIsExpressionSimple(m_bIsExpressionSimple);
	        aLELayerProps.setIsExpressionSimple(true);

	        IAnnotationExpressionEngine i_AnnoVBScriptEngine =  new AnnotationVBScriptEngine();
	        

	        aLELayerProps.setExpressionParserByRef(i_AnnoVBScriptEngine);
	        aLELayerProps.setBasicOverposterLayerPropertiesByRef(BOLP);
	        
	            
//	        if(m_Symbol !=null){
//	        	aLELayerProps.setSymbol(m_Symbol);
//	        }
	       
	    }

	    pGeoLayer.setDisplayAnnotation(true);
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
}


//================================================================下面为一些连接空间数据库的方法,在本例程中不是重点
class FeatureDatasetFactory {
	private Log log=LogFactory.getLog(this.getClass());
	
	private HashMap<String,FeatureDataset> dataMap = new HashMap<String,FeatureDataset>();
	
	FeatureDataset d;
	
	private static FeatureDatasetFactory INSTANCE=new FeatureDatasetFactory();
	
	private FeatureDatasetFactory(){};
	
	public static FeatureDatasetFactory getInstance(){
		return INSTANCE;
	}
	
	public FeatureDataset getFeatureDataset(String name) throws Exception{
		if(dataMap.get(name)!=null){
			return dataMap.get(name);
		}else if(dataMap.get("SDE."+name)!=null){
			return dataMap.get("SDE."+name);
		}else{
			d=new FeatureDataset(OraSDEWorkspaceFactory.getInstance().getIFeatureWorkSpace().openFeatureDataset(name));
			dataMap.put(d.getName(), d);
			return dataMap.get(d.getName());
		}
	}
	
	public IFeatureDataset getIFeatureDataset(String name) throws Exception{
		return getFeatureDataset(name);
	}
}

class OraSDEWorkspaceFactory {

	private static PropertySet PropSet;
	private static SdeWorkspaceFactory SDE_WORKSPACEFACTORY;
	private static IWorkspace WORKSPACE;
	private static OraSDEWorkspaceFactory FACTORY = new OraSDEWorkspaceFactory();


	private OraSDEWorkspaceFactory() {
		try {
			
			Properties pro = new Properties();

			PropSet = new PropertySet();
			PropSet.setProperty("SERVER", "192.168.1.220");
			PropSet.setProperty("INSTANCE","5151");
			PropSet.setProperty("USER","sde");
			PropSet.setProperty("PASSWORD", "sde");
			PropSet.setProperty("VERSION", "SDE.DEFAULT");
			SDE_WORKSPACEFACTORY = new SdeWorkspaceFactory();
			WORKSPACE = SDE_WORKSPACEFACTORY.open(PropSet, 0);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
	/**
	 * 取得OraSDEWorkspaceFactory的实例
	 */
	public static OraSDEWorkspaceFactory getInstance() {
		return FACTORY;
	}
	/**
	 * 取得IFeatureWorkspace
	 */
	public IFeatureWorkspace getIFeatureWorkSpace() {
		return (IFeatureWorkspace) WORKSPACE;
	}
	/**
	 * 取得IWorkspace
	 */
	public IWorkspace getIWorkspace() {
		return WORKSPACE;
	}
	/**
	 * 取得SdeWorkspaceFactory
	 */
	public SdeWorkspaceFactory getSdeWorkspaceFactory() {
		return SDE_WORKSPACEFACTORY;
	}
}
class FeatureClassFactory {
	private Log log=LogFactory.getLog(this.getClass());
	
	private HashMap<String,FeatureClass> fMap = new HashMap<String,FeatureClass>();
	
	private FeatureClass f;
	
	private static FeatureClassFactory INSTANCE = new FeatureClassFactory();
	
	private FeatureClassFactory(){}
	
	public static FeatureClassFactory getInstance(){
		return INSTANCE;
	}
	
	public FeatureClass getFeatureClass(String name) throws Exception{
		if(fMap.get(name)!=null){
			return fMap.get(name);
		}else if(fMap.get("SDE."+name)!=null){
			return fMap.get("SDE."+name);
		}else{
			f = new FeatureClass(OraSDEWorkspaceFactory.getInstance().getIFeatureWorkSpace().openFeatureClass(name));
			fMap.put(f.getName(), f);
			return fMap.get(f.getName());
		}
	}
	
	public IFeatureClass getIFeatureClass(String name) throws Exception{
			return getFeatureClass(name);
	}
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -