我做过气泡提示,方法就是用百度出来的方法。用IBalloonCallOut接口实现,但也就能达到ToolTip的效果,如果要想达到Google地图的效果,貌似用上面的方法很困难。如果显示图片和文字,倒可以尝试IPictureElement.下面是我实现气泡提示的代码,希望对你有用:
- ///里面有些外调的方法,都是一些返回颜色,Symbol,IElement等方法
- public IElement AutoFeatureSense(string m_layerName,int x, int y,out IFeature catchFeature)
- {
- IPoint point = new PointClass();
- point.PutCoords(x, y);
- IFeature feature = GDMapOpUtility.GetFeatureByPoint(m_map,x,y, m_sensePrecise, m_layerName);
- if (feature == null)
- {
- catchFeature = null;
- return null;
- }
- IEnvelope forEnvlope = new EnvelopeClass();
- IGraphicsContainer container = m_map.ActiveView as IGraphicsContainer;
- if (m_senseElement != null)
- {
- (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, forEnvlope);
- }
- if (feature != null)
- {
- catchFeature = feature;
- string name = string.Empty;
- if (m_target != null)
- {
- name = m_target(feature);//代理,由调用方返回目标名称
- }
- else
- {
- name = "未命名";
- }
- IDisplayTransformation trans = m_map.ActiveView.ScreenDisplay.DisplayTransformation;
- int xOffset = x + name.Length * 5 + (name.Length - 1) * 2 + 8;
- int yOffset = y + 18;
- IPoint mousePt = trans.ToMapPoint(xOffset, yOffset);
- //IProximityOperator proxOper = feature.Shape as IProximityOperator;
- //IPoint labelPt = proxOper.ReturnNearestPoint(mousePt, esriSegmentExtension.esriNoExtension);
- if (m_senseElement == null)
- {
- m_senseElement = GetLabelElement(container, "sense") as ITextElement;
- }
- if (m_senseElement == null)
- {
- m_senseElement = AddPicBalloonElement(mousePt, null, name, 10) as ITextElement;
- (m_senseElement as IElementProperties).Type = "sense";
- container.AddElement((IElement)m_senseElement, 0);
- }
- else
- {
- m_senseElement.Text = name;
- (m_senseElement as IElement).Geometry = (IGeometry)mousePt;
- container.UpdateElement(m_senseElement as IElement);
- }
- if (!forEnvlope.IsEmpty)
- {
- m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnvlope);
- }
- IEnvelope refreshEnv = new EnvelopeClass();
- (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, refreshEnv);
- m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, refreshEnv);
- return m_senseElement as IElement;
- }
- else
- {
- if (m_senseElement != null)
- {
- container.DeleteElement(m_senseElement as IElement);
- m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnvlope);
- m_senseElement = null;
- }
- catchFeature = null;
- return null;
- }
- }
- public void CloseMapSense()
- {
- try
- {
- if (m_senseElement != null)
- {
- IGraphicsContainer container = m_map.ActiveView as IGraphicsContainer;
- container.DeleteElement(m_senseElement as IElement);
- IEnvelope forEnv = new EnvelopeClass();
- (m_senseElement as IElement).QueryBounds(m_map.ActiveView.ScreenDisplay, forEnv);
- m_map.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, forEnv);
- m_senseElement = null;
- }
- }
- catch
- {
- }
- }
- private ITextElement AddPicBalloonElement(IPoint labelPt, IPoint anchorPt,string text, double leaderLen)
- {
- ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
- fillSymbol.Color = DisplayColorUtility.GetRgbColor(204, 255, 255);
- fillSymbol.Outline = LineSymbolFactory.GetSimpleLineSymbol(GISRgbColorEnum.Black, 1, esriSimpleLineStyle.esriSLSSolid);
- fillSymbol.Style = esriSimpleFillStyle.esriSFSSolid;
- IBalloonCallout callOut = new BalloonCalloutClass();
- if (anchorPt != null)
- {
- callOut.AnchorPoint = anchorPt;
- }
- callOut.LeaderTolerance = leaderLen;
- callOut.Style = esriBalloonCalloutStyle.esriBCSRoundedRectangle;
- callOut.Symbol = fillSymbol as IFillSymbol;
- ITextSymbol textSymbol = TextSymbolFactory.GetSimpleTextSymbol(TextFontFactory.GetSimpleFont ("宋体",10),GISRgbColorEnum .Black,10);
- IFormattedTextSymbol formatSymbol = textSymbol as IFormattedTextSymbol;
- formatSymbol.Background = callOut as ITextBackground;
- //formatSymbol.Leading = 100;
- ITextElement textEle = new TextElementClass();
- textEle.Symbol = textSymbol;
- textEle.Text = text;
- (textEle as IElement).Geometry = labelPt as IGeometry;
- return textEle;
- }
- private IElement GetLabelElement(IGraphicsContainer container, string type)
- {
- IElement ele = null;
- container.Reset();
- while ((ele = container.Next()) != null)
- {
- IElementProperties eleProp = ele as IElementProperties;
- if (eleProp.Type == type)
- {
- break;
- }
- }
- return ele;
- }
- }
- public delegate string GetTargetName(IFeature feature);