ArcGIS API for Silverlight 查詢點閃爍顯示

暖楓無敵發表於2012-03-09

主要樣式如下程式碼段內所示:
<esri:MarkerSymbol x:Name="DefaultMarkerSymbol">
 ....
</esri:MarkerSymbol>


...
xmlns:esri="http://schemas.esri.com/arcgis/client/2009"
...

<Grid.Resources>
     <esri:MarkerSymbol x:Name="DefaultMarkerSymbol">
                <esri:MarkerSymbol.ControlTemplate>
                    <ControlTemplate>
                        <Canvas>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualState x:Name="Normal">
                                        <Storyboard RepeatBehavior="Forever">

                                            <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" From="1" To="10" Duration="00:00:01" />

                                            <DoubleAnimation BeginTime="0:0:0" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" From="1" To="10" Duration="00:00:01" />

                                            <DoubleAnimation BeginTime="00:00:00" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0" Duration="00:00:01" />
                                        </Storyboard>
                                    </vsm:VisualState>

                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" RenderTransformOrigin="0.5,0.5" x:Name="ellipse" IsHitTestVisible="False">
                                <Ellipse.RenderTransform>
                                    <ScaleTransform />
                                </Ellipse.RenderTransform>
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="#00FF0000" />
                                        <GradientStop Color="#FFFF0000" Offset="0.25" />
                                        <GradientStop Color="#00FF0000" Offset="0.5" />
                                        <GradientStop Color="#FFFF0000" Offset="0.75" />
                                        <GradientStop Color="#00FF0000" Offset="1" />
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" Fill="#FFFF0000" x:Name="ellipse1" />
                        </Canvas>
                    </ControlTemplate>
                </esri:MarkerSymbol.ControlTemplate>
            </esri:MarkerSymbol>
</Grid.Resources>


private void UserControl_Loaded(object sender, RoutedEventArgs e)
{

     QueryTask queryTask = new QueryTask("http://192.168.2.5/arcgis/rest/services/AnHuiDynamic/MapServer/0");
     queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
     queryTask.Failed += QueryTask_Failed;

     ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
     query.ReturnGeometry = true;
     query.Text = conditions;
     query.OutSpatialReference = myMap.SpatialReference;
     query.OutFields.Add("NAME");
     queryTask.ExecuteAsync(query);      

}

 private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
     FeatureSet featureSet = args.FeatureSet;
       
    GraphicsLayer graphicsLayer = myMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
    graphicsLayer.ClearGraphics();

    if (featureSet != null && featureSet.Features.Count > 0)
    {
        Graphic selectedFeature = featureSet.Features[0];

       // Highlight selected feature
       selectedFeature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
       graphicsLayer.Graphics.Add(selectedFeature);

       // Zoom to selected feature (define expand percentage)
       ESRI.ArcGIS.Client.Geometry.Envelope selectedFeatureExtent = selectedFeature.Geometry.Extent;

       double expandPercentage = 30;

      double widthExpand = selectedFeatureExtent.Width * (expandPercentage / 100);
       double heightExpand = selectedFeatureExtent.Height * (expandPercentage / 100);

       ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(
       selectedFeatureExtent.XMin - (widthExpand / 2),
       selectedFeatureExtent.YMin - (heightExpand / 2),
       selectedFeatureExtent.XMax + (widthExpand / 2),
       selectedFeatureExtent.YMax + (heightExpand / 2));

       myMap.ZoomTo(displayExtent);
     }
}

private void QueryTask_Failed(object sender, TaskFailedEventArgs args)
{
    MessageBox.Show("Query failed: " + args.Error);
}


效果如下圖:


相關文章