zoukankan      html  css  js  c++  java
  • 气泡提示

    我做过气泡提示,方法就是用百度出来的方法。用IBalloonCallOut接口实现,但也就能达到ToolTip的效果,如果要想达到Google地图的效果,貌似用上面的方法很困难。如果显示图片和文字,倒可以尝试IPictureElement.下面是我实现气泡提示的代码,希望对你有用:

    1. ///里面有些外调的方法,都是一些返回颜色,Symbol,IElement等方法
    2. public IElement AutoFeatureSense(string m_layerName,int x, int y,out IFeature catchFeature)
    3.         {
    4.             IPoint point = new PointClass();
    5.             point.PutCoords(x, y);
    6.             IFeature feature = GDMapOpUtility.GetFeatureByPoint(m_map,x,y, m_sensePrecise, m_layerName);
    7.             if (feature == null)
    8.             {
    9.                 catchFeature = null;
    10.                 return null;
    11.             }
    12.             IEnvelope forEnvlope = new EnvelopeClass();
    13.             IGraphicsContainer container = m_map.ActiveView as IGraphicsContainer;
    14.             if (m_senseElement != null)
    15.             {
    16.                 (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, forEnvlope);
    17.             }
    18.             if (feature != null)
    19.             {
    20.                 catchFeature = feature;
    21.                 string name = string.Empty;
    22.                 if (m_target != null)
    23.                 {
    24.                     name = m_target(feature);//代理,由调用方返回目标名称
    25.                 }
    26.                 else
    27.                 {
    28.                     name = "未命名";
    29.                 }
    30.                 IDisplayTransformation trans = m_map.ActiveView.ScreenDisplay.DisplayTransformation;
    31.                 int xOffset = x + name.Length * 5 + (name.Length - 1) * 2 + 8;
    32.                 int yOffset = y + 18;
    33.                 IPoint mousePt = trans.ToMapPoint(xOffset, yOffset);
    34.                 //IProximityOperator proxOper = feature.Shape as IProximityOperator;
    35.                 //IPoint labelPt = proxOper.ReturnNearestPoint(mousePt, esriSegmentExtension.esriNoExtension);
    36.                 if (m_senseElement == null)
    37.                 {
    38.                     m_senseElement = GetLabelElement(container, "sense") as ITextElement;
    39.                 }
    40.                 if (m_senseElement == null)
    41.                 {
    42.                     m_senseElement = AddPicBalloonElement(mousePt, null, name, 10) as ITextElement;
    43.                     (m_senseElement as IElementProperties).Type = "sense";
    44.                     container.AddElement((IElement)m_senseElement, 0);
    45.                 }
    46.                 else
    47.                 {
    48.                     m_senseElement.Text = name;
    49.                     (m_senseElement as IElement).Geometry = (IGeometry)mousePt;
    50.                     container.UpdateElement(m_senseElement as IElement);
    51.                 }
    52.                 if (!forEnvlope.IsEmpty)
    53.                 {
    54.                     m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnvlope);
    55.                 }
    56.                 IEnvelope refreshEnv = new EnvelopeClass();
    57.                 (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, refreshEnv);
    58.                 m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, refreshEnv);
    59.                 return m_senseElement as IElement;
    60.             }
    61.             else
    62.             {
    63.                 if (m_senseElement != null)
    64.                 {
    65.                     container.DeleteElement(m_senseElement as IElement);
    66.                     m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnvlope);
    67.                     m_senseElement = null;
    68.                 }
    69.                 catchFeature = null;
    70.                 return null;
    71.             }
    72.         }
    73.         public void CloseMapSense()
    74.         {
    75.             try
    76.             {
    77.                 if (m_senseElement != null)
    78.                 {
    79.                     IGraphicsContainer container = m_map.ActiveView as IGraphicsContainer;
    80.                     container.DeleteElement(m_senseElement as IElement);
    81.                     IEnvelope forEnv = new EnvelopeClass();
    82.                     (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, forEnv);
    83.                     m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnv);
    84.                     m_senseElement = null;
    85.                 }
    86.             }
    87.             catch
    88.             {
    89.             
    90.             }
    91.         }
    92.         private ITextElement AddPicBalloonElement(IPoint labelPt, IPoint anchorPt,string text, double leaderLen)
    93.         {
    94.             ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
    95.             fillSymbol.Color = DisplayColorUtility.GetRgbColor(204, 255, 255);
    96.             fillSymbol.Outline = LineSymbolFactory.GetSimpleLineSymbol(GISRgbColorEnum.Black, 1, esriSimpleLineStyle.esriSLSSolid);
    97.             fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
    98.             IBalloonCallout callOut = new BalloonCalloutClass();
    99.             if (anchorPt != null)
    100.             {
    101.                 callOut.AnchorPoint = anchorPt;
    102.             }
    103.             callOut.LeaderTolerance = leaderLen;
    104.             callOut.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
    105.             callOut.Symbol = fillSymbol as IFillSymbol;
    106.             ITextSymbol textSymbol = TextSymbolFactory.GetSimpleTextSymbol(TextFontFactory.GetSimpleFont ("宋体",10),GISRgbColorEnum .Black,10);
    107.             IFormattedTextSymbol formatSymbol = textSymbol as IFormattedTextSymbol;
    108.             formatSymbol.Background = callOut as ITextBackground;
    109.             //formatSymbol.Leading = 100;
    110.             ITextElement textEle = new TextElementClass();
    111.             textEle.Symbol = textSymbol;
    112.             textEle.Text = text;
    113.             (textEle as IElement).Geometry = labelPt as IGeometry;
    114.             return textEle;
    115.         }
    116.         private IElement GetLabelElement(IGraphicsContainer container, string type)
    117.         {
    118.             IElement ele = null;
    119.             container.Reset();
    120.             while ((ele = container.Next()) != null)
    121.             {
    122.                 IElementProperties eleProp = ele as IElementProperties;
    123.                 if (eleProp.Type == type)
    124.                 {
    125.                     break;
    126.                 }
    127.             }
    128.             return ele;
    129.         }
    130.     }
    131.     public delegate string GetTargetName(IFeature feature);
    复制代码
  • 相关阅读:
    SPOJ SAMER08A
    SPOJ TRAFFICN
    CS Academy Set Subtraction
    CS Academy Bad Triplet
    CF Round 432 C. Five Dimensional Points
    CF Round 432 B. Arpa and an exam about geometry
    SPOJ INVCNT
    CS Academy Palindromic Tree
    身体训练
    简单瞎搞题
  • 原文地址:https://www.cnblogs.com/xianyin05/p/3101135.html
Copyright © 2011-2022 走看看