Select to view content in your preferred language

Information window on polygon retriving error

693
2
Jump to solution
06-25-2012 10:37 PM
JulieBiju
Deactivated User
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 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
0 Kudos
1 Solution

Accepted Solutions
JoeHershman
MVP Alum
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 


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 use

     MyInfoWindow.Anchor = polygon.Extent.GetCenter(); 
 

Hope that helps
Thanks,
-Joe

View solution in original post

0 Kudos
2 Replies
JoeHershman
MVP Alum
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 


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 use

     MyInfoWindow.Anchor = polygon.Extent.GetCenter(); 
 

Hope that helps
Thanks,
-Joe
0 Kudos
JulieBiju
Deactivated User
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 use


    MyInfoWindow.Anchor = polygon.Extent.GetCenter();

 

Hope that helps


Joe , I did my code like as follows...Thank u

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
0 Kudos