Unable to cast object of type 'ESRI.ArcGIS.Client.Geometry.Polygon' to type 'ESRI.ArcGIS.Client.Geometry.MapPoint'.
Private Sub MyDrawObject_DrawComplete(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.DrawEventArgs) Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer) Dim graphic As New ESRI.ArcGIS.Client.Graphic() With { .Geometry = args.Geometry, .Symbol = _activeSymbol } Dim strhotspot As String = "" strhotspot = Trim(TxtGname.Text) graphic.Attributes.Add("STRHOTSPOT", strhotspot) AddHandler graphic.MouseLeave, AddressOf Graphic_MouseLeave AddHandler graphic.MouseEnter, AddressOf Graphic_MouseEnter graphicsLayer.Graphics.Add(graphic) MyDrawObject.DrawMode = DrawMode.None TxtGname.Text = "" TxtDesc.Text = "" End Sub
Private Sub Graphic_MouseLeave(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) If MyInfoWindow.IsOpen = True Then MyInfoWindow.IsOpen = False End If Return End Sub Private Sub Graphic_MouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) Dim theGraphic As ESRI.ArcGIS.Client.Graphic = CType(sender, ESRI.ArcGIS.Client.Graphic) MyInfoWindow.Anchor = theGraphic.Geometry MyInfoWindow.IsOpen = True MyInfoWindow.Content = theGraphic.Attributes End Sub
Solved! Go to Solution.
Hello i am adding Graphics on my map.And adding tooltip on it.Tooltip is dispaying properly when the graphic type is PictureMarkerSymbol.But for polygon tooltip is giving me the errr like as follows
Can anybdy help me to solve this?Unable to cast object of type 'ESRI.ArcGIS.Client.Geometry.Polygon' to type 'ESRI.ArcGIS.Client.Geometry.MapPoint'.Private Sub Graphic_MouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) Dim theGraphic As ESRI.ArcGIS.Client.Graphic = CType(sender, ESRI.ArcGIS.Client.Graphic) MyInfoWindow.Anchor = theGraphic.Geometry MyInfoWindow.IsOpen = True MyInfoWindow.Content = theGraphic.Attributes End Sub
MyInfoWindow.Anchor = polygon.Extent.GetCenter();
Hello i am adding Graphics on my map.And adding tooltip on it.Tooltip is dispaying properly when the graphic type is PictureMarkerSymbol.But for polygon tooltip is giving me the errr like as follows
Can anybdy help me to solve this?Unable to cast object of type 'ESRI.ArcGIS.Client.Geometry.Polygon' to type 'ESRI.ArcGIS.Client.Geometry.MapPoint'.Private Sub Graphic_MouseEnter(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseEventArgs) Dim theGraphic As ESRI.ArcGIS.Client.Graphic = CType(sender, ESRI.ArcGIS.Client.Graphic) MyInfoWindow.Anchor = theGraphic.Geometry MyInfoWindow.IsOpen = True MyInfoWindow.Content = theGraphic.Attributes End Sub
MyInfoWindow.Anchor = polygon.Extent.GetCenter();
In the MouseEnter handler you set Anchor to the geometry of the Graphic itself. Anchor is a MapPoint so if the Graphic has Polygon geometry you would receive that error. If you want the InfoWindow to display over a polygon (or polyline) you need to pick the anchor point.
For a polygon the simplest would be to cast the Geometry to a Polygon and useMyInfoWindow.Anchor = polygon.Extent.GetCenter();
Hope that helps
Dim theGraphic As ESRI.ArcGIS.Client.Graphic = CType(sender, ESRI.ArcGIS.Client.Graphic) MyInfoWindow.Anchor = theGraphic.Geometry.Extent.GetCenter MyInfoWindow.IsOpen = True MyInfoWindow.Content = theGraphic.Attributes