ArcGIS.Server.9.2.DotNet實現動態設定Label標註功能
阿新 • • 發佈:2019-02-17
{
4 ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunct = Map1.GetFunctionality("worldCities");
5 MapResourceLocal mapResLocal = mapFunct.Resource as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal;
6 ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf = mapFunct as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality;
7 ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc = mf.MapDescription;
8 IServerContext serverContext = mapResLocal.ServerContextInfo.ServerContext;
9 IMapServer mapServer = serverContext.ServerObject as IMapServer;
10 IMapServerObjects mapServerObjects = mapServer as IMapServerObjects;
11 int index = getLyaerIndex(layerName);
12 ILayer layer = mapServerObjects.get_Layer(mapServer.DefaultMapName, index);
13 //獲取面圖層14 IFeatureLayer pFLayer = layer as IFeatureLayer;
15
16 IGeoFeatureLayer pGeoFeatureLayer = pFLayer as IGeoFeatureLayer;
17 //清除原來的標註屬性18 pGeoFeatureLayer.AnnotationProperties.Clear();
19 //標註屬性集合20 IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.AnnotationProperties;
21 ILabelEngineLayerProperties pLabelEngine;
22
23 pLabelEngine = serverContext.CreateObject("esriCarto.LabelEngineLayerProperties") as ILabelEngineLayerProperties;
24
25 //可以對輸出的文字樣式進行設定
26 //ESRI.ArcGIS.Display.ITextSymbol textSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();27 pLabelEngine.Symbol.Font = ESRI.ArcGIS.ADF.Converter.ToStdFont(new Font("Times New Roman", 14, FontStyle.Italic));
28 pLabelEngine.Symbol.Color = ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter.ToRGBColor(serverContext, System.Drawing.Color.Blue);
29
30
31 pLabelEngine.Expression ="["+ field +"]";//設定作為Label的欄位名32 IAnnotateLayerProperties pAnnoLayerProps = pLabelEngine as IAnnotateLayerProperties;
33 pAnnoLayerPropsColl.Add(pAnnoLayerProps);
34 //設定標註顯示35 pGeoFeatureLayer.DisplayAnnotation =true;
36 ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription LayerDesc = mapDesc.LayerDescriptions[0] as ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription;
37 //設定Label顯示38 LayerDesc.ShowLabels =true;
39 //重新整理輸出結果用來給客戶端更新顯示40 Map1.Refresh();
41 return Map1.CallbackResults.ToString();
42 }
4 ESRI.ArcGIS.ADF.Web.DataSources.IMapFunctionality mapFunct = Map1.GetFunctionality("worldCities");
5 MapResourceLocal mapResLocal = mapFunct.Resource as ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapResourceLocal;
6 ESRI.ArcGIS.ADF.Web.DataSources.ArcGISServer.MapFunctionality mf
7 ESRI.ArcGIS.ADF.ArcGISServer.MapDescription mapDesc = mf.MapDescription;
8 IServerContext serverContext = mapResLocal.ServerContextInfo.ServerContext;
9 IMapServer mapServer = serverContext.ServerObject
10 IMapServerObjects mapServerObjects = mapServer as IMapServerObjects;
11 int index = getLyaerIndex(layerName);
12 ILayer layer = mapServerObjects.get_Layer(mapServer.DefaultMapName, index);
13 //獲取面圖層14 IFeatureLayer pFLayer = layer as
15
16 IGeoFeatureLayer pGeoFeatureLayer = pFLayer as IGeoFeatureLayer;
17 //清除原來的標註屬性18 pGeoFeatureLayer.AnnotationProperties.Clear();
19 //標註屬性集合20 IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.AnnotationProperties;
21 ILabelEngineLayerProperties pLabelEngine;
22
23 pLabelEngine = serverContext.CreateObject("esriCarto.LabelEngineLayerProperties") as ILabelEngineLayerProperties;
24
25 //可以對輸出的文字樣式進行設定
26 //ESRI.ArcGIS.Display.ITextSymbol textSymbol = new ESRI.ArcGIS.Display.TextSymbolClass();27 pLabelEngine.Symbol.Font = ESRI.ArcGIS.ADF.Converter.ToStdFont(new Font("Times New Roman", 14, FontStyle.Italic));
28 pLabelEngine.Symbol.Color = ESRI.ArcGIS.ADF.Web.UI.WebControls.Converter.ToRGBColor(serverContext, System.Drawing.Color.Blue);
29
30
31 pLabelEngine.Expression ="["+ field +"]";//設定作為Label的欄位名32 IAnnotateLayerProperties pAnnoLayerProps = pLabelEngine as IAnnotateLayerProperties;
33 pAnnoLayerPropsColl.Add(pAnnoLayerProps);
34 //設定標註顯示35 pGeoFeatureLayer.DisplayAnnotation =true;
36 ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription LayerDesc = mapDesc.LayerDescriptions[0] as ESRI.ArcGIS.ADF.ArcGISServer.LayerDescription;
37 //設定Label顯示38 LayerDesc.ShowLabels =true;
39 //重新整理輸出結果用來給客戶端更新顯示40 Map1.Refresh();
41 return Map1.CallbackResults.ToString();
42 }