Clear features and zoom based on feature collection

398
6
Jump to solution
05-29-2012 10:58 PM
JulieBiju
Occasional Contributor
Dears,
i need urgent help.
I developed one we application using silverlight4 .Now my map is showing .In this map i am adding some picturemarkers.Based on the following code i need some help with code...

1.I am adding lot of picturemarker features on map  in button clik based on some condition.Now i can see some of the features after dragging the map only.How can i see all feature collection  without dragging?

2.How can i clear all the existing features(picturemarker) in button click?

3.How can i link each picturemarker with a straight line with arrow.

4.How can i set a maptip on eachpicture marker in buttonclick event? Like infowindow showing in featureservice popup sample.All sample maptip code is adding from the tables . I need to add some textbox vaule as maptip.


Please help me....It is very urgent...seemyu code below
Dim gpsNMEASentences As String = "$GPGGA, 92204.9, " & e.Result(recordcount).ELat & ", N," & e.Result(recordcount).ELon & ", W, 1, 04, 2.4, 25.7, M,,,,*75"              Dim gpsNMEASentenceArray() As String = gpsNMEASentences.Split(ControlChars.Lf)             Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)             Dim gpsNMEASentence() As String = gpsNMEASentenceArray(0).Split(","c)             '.Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),             Dim graphic As New Graphic() With                 {                     .Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),                     .Symbol = TryCast(LayoutRoot.Resources(colourstyle), Symbol)                 }              graphicsLayer.Graphics.Add(graphic)               Dim textSymbol As New TextSymbol() With                 {                     .FontFamily = New System.Windows.Media.FontFamily("Arial"),                     .Foreground = New System.Windows.Media.SolidColorBrush(Colors.Black),                     .FontSize = 25,                     .Text = gpsNMEASentence(9)                 }              Dim graphicText As New Graphic() With                 {                     .Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),                     .Symbol = textSymbol                 }              graphicsLayer.Graphics.Add(graphicText)
0 Kudos
1 Solution

Accepted Solutions
JenniferNery
Esri Regular Contributor
1.I am adding lot of picturemarker features on map in button clik based on some condition.Now i can see some of the features after dragging the map only.How can i see all feature collection without dragging?

After your graphics are added to GraphicsLayer, you can call ZoomTo, provided your map and layer have the same SpatialReference.
MyMap.ZoomTo(graphicsLayer.FullExtent)


2.How can i clear all the existing features(picturemarker) in button click?

You can use either one of these two:
graphicsLayer.ClearGraphics() //or //graphicsLayer.Graphics.Clear()


3.How can i link each picturemarker with a straight line with arrow.
You can add another GraphicsLayer that will contain Polyline and use Renderer with LineSymbol. After all point graphics (picturemarkers) are added to the other GraphicsLayer, use their geometry as MapPoint in your Polyline.Path.PointCollection
I just used C# to VB converter so I'm not quite sure this works. The idea is you will clone your point graphic geometry add make that as a vertex in your polyline.
lineGraphicsLayer.Renderer = New SimpleRenderer() With { _  Key .Symbol = New SimpleLineSymbol() With { _   Key .Color = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red), _   Key .Width = 3, _   Key .Style = SimpleLineSymbol.LineStyle.Solid _  } _ } Dim polyline = New Polyline() Dim pc = New PointCollection() For Each g As var In pointGraphicsLayer.Graphics  Dim mp = TryCast(Geometry.Clone(TryCast(g.Geometry, MapPoint)), MapPoint)  pc.Add(mp) Next polyline.Paths.Add(pc) lineGraphicsLayer.Graphics.Add(New Graphic() With { _  Key .Geometry = polyline _ })


4.How can i set a maptip on eachpicture marker in buttonclick event? Like infowindow showing in featureservice popup sample.All sample maptip code is adding from the tables . I need to add some textbox vaule as maptip.
You can use VB code from this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#InfoWindowSimple. You will need to update DataTemplate in XAML and if you want this to change your graphic.Attribute, you can change Binding statement Mode to TwoWay.
        <DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">                 <TextBoxText="{Binding [STATE_NAME]}" Foreground="Black" FontSize="12" />             </DataTemplate>

View solution in original post

0 Kudos
6 Replies
JoeHershman
MVP Regular Contributor

  1. Create a Geometry that has an Extent property from the MapPoints, a Polygon or MultiPoint should work.  Then call Map::ZoomTo(your_geometry)

  2. GraphicsLayer:Graphics is a collection which can have items removed.  When the Graphics are added create a temp collection of those graphics, then the next time add is called loop through that collection and remove them from the Graphics collection on GraphicsLayer

  3. You will need to draw these other symbols, by figuring out the coordinates based on the point.  There is an Arrow type for standard drawing  Another option would be to create a custom symbol using a ControlTemplate.

  4. Create a UserControl with what you want in the MapTip.  Set the MapTip property on each graphic with the UserControl.  The MapTip control is bound to the Attributes collection of the Graphic, so you use data binding to associate each attribute to the appropriate control in Xaml.

Thanks,
-Joe
0 Kudos
JulieBiju
Occasional Contributor
Can u provide me some codes for each in vb.net.That will help me lot.I am using map as follows

   <esri:Map MouseClick="MyMap_MouseClick" Extent="-120, 20, -100, 40" Grid.Row="3" Name="MyMap" Visibility="Visible" Background="Transparent" Margin="2,0" BorderThickness="1" BorderBrush="{StaticResource TitleBarGradient}">
          <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
          <esri:GraphicsLayer ID="MyGraphicsLayer" />
        </esri:Map>
        <esri:InfoWindow x:Name="MyInfoWindow"
                         Padding="2"
                         CornerRadius="10"                        
                         Map="{Binding ElementName=MyMap}" >
            <esri:InfoWindow.Background>
                <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188">
                    <GradientStop Color="#FFD1DFF2"/>
                    <GradientStop Color="#FF092959" Offset="0.946"/>
                </LinearGradientBrush>
            </esri:InfoWindow.Background>
        </esri:InfoWindow>
0 Kudos
JenniferNery
Esri Regular Contributor
1.I am adding lot of picturemarker features on map in button clik based on some condition.Now i can see some of the features after dragging the map only.How can i see all feature collection without dragging?

After your graphics are added to GraphicsLayer, you can call ZoomTo, provided your map and layer have the same SpatialReference.
MyMap.ZoomTo(graphicsLayer.FullExtent)


2.How can i clear all the existing features(picturemarker) in button click?

You can use either one of these two:
graphicsLayer.ClearGraphics() //or //graphicsLayer.Graphics.Clear()


3.How can i link each picturemarker with a straight line with arrow.
You can add another GraphicsLayer that will contain Polyline and use Renderer with LineSymbol. After all point graphics (picturemarkers) are added to the other GraphicsLayer, use their geometry as MapPoint in your Polyline.Path.PointCollection
I just used C# to VB converter so I'm not quite sure this works. The idea is you will clone your point graphic geometry add make that as a vertex in your polyline.
lineGraphicsLayer.Renderer = New SimpleRenderer() With { _  Key .Symbol = New SimpleLineSymbol() With { _   Key .Color = New System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red), _   Key .Width = 3, _   Key .Style = SimpleLineSymbol.LineStyle.Solid _  } _ } Dim polyline = New Polyline() Dim pc = New PointCollection() For Each g As var In pointGraphicsLayer.Graphics  Dim mp = TryCast(Geometry.Clone(TryCast(g.Geometry, MapPoint)), MapPoint)  pc.Add(mp) Next polyline.Paths.Add(pc) lineGraphicsLayer.Graphics.Add(New Graphic() With { _  Key .Geometry = polyline _ })


4.How can i set a maptip on eachpicture marker in buttonclick event? Like infowindow showing in featureservice popup sample.All sample maptip code is adding from the tables . I need to add some textbox vaule as maptip.
You can use VB code from this SDK sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#InfoWindowSimple. You will need to update DataTemplate in XAML and if you want this to change your graphic.Attribute, you can change Binding statement Mode to TwoWay.
        <DataTemplate x:Key="MyFeatureLayerInfoWindowTemplate">                 <TextBoxText="{Binding [STATE_NAME]}" Foreground="Black" FontSize="12" />             </DataTemplate>
0 Kudos
JulieBiju
Occasional Contributor
Dear friend,Thank u so much for ur gr8 support...I need your help for information window in another way.

4.How can i set a maptip on eachpicture marker in buttonclick event? Like infowindow showing in featureservice popup sample.All sample mapti...


1.I need to add maptip only on the graphics i adding.For eg:I added 2 graphics on my map. I need to popup inforamtion window when i click only on this two picture  graphics.
2.I need to popup
Status = e.Result(recordcount).EEventName 
as information

below is the function i am using to add graphics.Please help me..:)


 Private Sub LastPositionFinalRunning(ByVal sender As Object, ByVal e As SelectLastPositionCompletedEventArgs)
        For recordcount = 0 To e.Result.Count - 1
            'Dim geometry1 As New Point(csys, rsOman("lon"), rsOman("lat"))
            Dim Status As String = ""
            Dim EventId As Integer
            Dim colourstyle As String
            EventId = e.Result(recordcount).EEventID
            If EventId = 253 Then
                colourstyle = "GlobePictureSymbol_Blue"
            ElseIf EventId = 110 Then
                colourstyle = "GlobePictureSymbol_Green"
            ElseIf EventId = 108 Then
                colourstyle = "GlobePictureSymbol_Green"
            ElseIf EventId = 101 Then
                colourstyle = "GlobePictureSymbol_Red"
            ElseIf EventId = 142 Then
                colourstyle = "GlobePictureSymbol_Black"
            ElseIf EventId = 254 Then
                colourstyle = "GlobePictureSymbol_Gray"
            Else
                colourstyle = "GlobePictureSymbol_Black"
            End If
            Status = e.Result(recordcount).EEventName

            '*************************
            ''''''''''LOCATION FROM POI and Roaddata same connection not possible bfre close 
            Dim procname As String = ""
            Dim location As String
            location = ""
            If e.Result(recordcount).EStreetAddress <> "NULL" And e.Result(recordcount).EStreetAddress <> "" Then
                location = e.Result(recordcount).ELocationName & ", STREET: " & e.Result(recordcount).EStreetAddress
            Else
                location = e.Result(recordcount).ELocationName & ""
            End If
            ''''''''''''''''''''''''''
            TxtLastUpd.Text = e.Result(recordcount).Edatedisplay
            Dim gpsNMEASentences As String = "$GPGGA, 92204.9, " & e.Result(recordcount).ELat & ", N," & e.Result(recordcount).ELon & ", W, 1, 04, 2.4, 25.7, M,,,,*75"

            Dim gpsNMEASentenceArray() As String = gpsNMEASentences.Split(ControlChars.Lf)

            Dim gpsNMEASentence() As String = gpsNMEASentenceArray(0).Split(","c)
            Dim graphic As New Graphic() With
                {
                    .Geometry = mercator.FromGeographic(New MapPoint(Convert.ToDouble(gpsNMEASentence(4)), Convert.ToDouble(gpsNMEASentence(2)))),
                    .Symbol = TryCast(LayoutRoot.Resources(colourstyle), Symbol)
                }
            Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
            graphicsLayer.ClearGraphics()
            graphicsLayer.Graphics.Add(graphic)

            esriLogoImage.Visibility = Windows.Visibility.Collapsed
            MyMap.Visibility = Windows.Visibility.Visible
            MyMap.ZoomTo(graphicsLayer.FullExtent)
            'map1.Center = New DPoint(rsOman("lon"), rsOman("lat"))
            'Dim distance2 As MapInfo.Geometry.Distance = New MapInfo.Geometry.Distance(3, map1.Zoom.Unit)
            'map1.Zoom = distance2

        Next


    End Sub
0 Kudos
JoeHershman
MVP Regular Contributor
The Graphic object has a MapTip property.  Instead of creating a MapTip object and assigning the GraphicsLayer to the MapTip you create your own MapTip and set the MapTip property on the Graphic.  Your custom MapTip can be any UserControl (you have to make the control).

My code is just:
graphic.MapTip = new MapTip();


And my MapTip is a UserControl and the bindings to attributes still work like below where; Name, Lat, Lon are all Attributes on my Graphic:

            <StackPanel Orientation="Vertical" Margin="10,10,10,10">
                <TextBlock Text="{Binding [Name]}"  Width="120" Height="20" TextAlignment="Center"
                           FontWeight="SemiBold"/>
                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <Controls:Label Content="Lattitude:" Margin="0,0,8,0"/>
                    <TextBlock Text="{Binding [Lat]}" Width="60"/>
                </StackPanel>
                <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                    <Controls:Label Content="Longitude:" Margin="0,0,3,0"/>
                    <TextBlock Text="{Binding [Lon]}" Width="60"/>
                </StackPanel>
            </StackPanel>
Thanks,
-Joe
0 Kudos
JulieBiju
Occasional Contributor
dear friend,Thanks...
How can i pass e.result value from xaml.vb as maptip?
The information which is coming in e.result is from another database not from geodatabase.It should pass programattically.
0 Kudos