微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ArcGis API FOR Silverlight 做了个导航工具~

转载请注明文章出处:http://www.cnblogs.com/thinkaspx

地图是读取的谷歌图层。。

主要是导航工具 做出来费劲呀。。

马上上代码

复制代码

namespace ZoomwayWebGis.Controls.Generic
{
    [TemplatePart(Name = "PanLeft",Type = typeof(FrameworkElement))]
    [TemplatePart(Name = PanRightPanUpPanDownZoomSlider(Slider))]
    [TemplatePart(Name = ZoomInButton(Button))]
    [TemplatePart(Name = ZoomOutButtonInstanceMark(Button))]
    public class MapNavigator : ContentControl
    {
        FrameworkElement PanLeft;
        FrameworkElement PanRight;
        FrameworkElement PanUp;
        FrameworkElement PanDown;
        Button ZoomInButton;
        Button ZoomOutButton;
        Slider ZoomSlider;

        private double _panFactor = 0.5;
        const double MaxResolution = 23218.433769164774double MinResolution = 0.59716428347743467;

        public MapNavigator()
        {
            this.DefaultStyleKey = (MapNavigator);
        }

        override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            PanLeft = GetTemplateChild(") as FrameworkElement;
            PanRight = GetTemplateChild( FrameworkElement;
            PanUp = GetTemplateChild( FrameworkElement;
            PanDown = GetTemplateChild( FrameworkElement;
            ZoomSlider = GetTemplateChild( Slider;
            ZoomInButton = GetTemplateChild( Button;
            ZoomOutButton = GetTemplateChild( Button;

            enablePanElement(PanLeft);
            enablePanElement(PanRight);
            enablePanElement(PanUp);
            enablePanElement(PanDown);

            // Set control's flow direction to LTR to avoid flipping East and West keys:
            this.FlowDirection = System.Windows.FlowDirection.LeftToRight;

            if (ZoomSlider != null)
            {
                if (Map != )
                {
                    SetupZoom();
                }

                ZoomSlider.Minimum = 0;
                ZoomSlider.Maximum = 1;
                ZoomSlider.SmallChange = .01;
                ZoomSlider.LargeChange = .;
                ZoomSlider.LostMouseCapture += ZoomSlider_LostMouseCapture;
                ZoomSlider.LostFocus += ZoomSlider_LostMouseCapture;
            }
            if (ZoomInButton != )
                ZoomInButton.Click += ZoomInButton_Click;
            if (ZoomOutButton != )
                ZoomOutButton.Click += ZoomOutButton_Click;

            bool isDesignMode = System.ComponentModel.DesignerProperties.GetIsInDesignMode(this);
            if (isDesignMode)
                mouSEOver = isDesignMode;
            ChangeVisualState(false);
        }

     
        void ZoomOutButton_Click(object sender,RoutedEventArgs e)
        {
            Map.Zoom(1 / Map.ZoomFactor);
        }

        void ZoomInButton_Click(void Map_ExtentChanged(if (!double.IsNaN(Map.Resolution) && ZoomSlider != )
                ZoomSlider.Value = ResolutionTovalue(Map.Resolution);
        }

        #region State management

        bool mouSEOver = ;


        protected  OnMouseLeave(MouseEventArgs e)
        {
            mouSEOver = ;
            trackingRotation)
                ChangeVisualState(true.OnMouseLeave(e);
        }


         OnMouseEnter(MouseEventArgs e)
        {
            mouSEOver = ;
            ChangeVisualState(.OnMouseEnter(e);
        }

        void ChangeVisualState(bool useTransitions)
        {
             (mouSEOver)
            {
                GoToState(useTransitions,MouSEOver");
            }
            else
            {
                GoToState(useTransitions,0)">normal);
            }
        }

        bool GoToState(bool useTransitions,string stateName)
        {
            return visualstatemanager.GoToState(,stateName,useTransitions);
        }

        #endregion

        #region Rotation

        Point startMousePos;
        double angle = bool trackingRotation = double GetAngle(Point a,Point b)
        {
            if (a == null || b == null) return return Math.atan2((b.X - a.X),(a.Y - b.Y)) / Math.PI * 180;
        }

        #region Zoom

        void ZoomSlider_LostMouseCapture(etoResolution(ZoomSlider.Value));
        }

         enablePanElement(FrameworkElement element)
        {
            if (element == return;
            element.MouseLeave += panElement_MouseLeftButtonUp;
            element.MouseLeftButtonDown += panElement_MouseLeftButtonDown;
            element.MouseLeftButtonUp += panElement_MouseLeftButtonUp;
        }

        void panElement_MouseLeftButtonDown(if (Map == null || sender == ;

            Envelope env = Map.Extent;
            if (env == double x = 0,y = ;
            MapPoint oldCenter = env.GetCenter();
            MapPoint newCenter = var height = env.Height * _panFactor;
            var width = env.Width * if units are degrees (the default),limit or alter panning to the lat/lon limits
            if (sender == PanUp)  north
            {
                y = oldCenter.Y + height;
                newCenter = new MapPoint(oldCenter.X,y);
            }
            else if (sender == PanRight)  East
            {
                x = oldCenter.X + width;
                newCenter =  MapPoint(x,oldCenter.Y);
            }
            if (sender == PanLeft)  West
            {
                x = oldCenter.X -if (sender == PanDown)  South
            {
                y = oldCenter.Y -if (newCenter != )
                Map.PanTo(newCenter);

        }

        void panElement_MouseLeftButtonUp(;
        }


        double ValuetoResolution( value)
        {
            double max = Math.Log10(MaxResolution);
            double min = Math.Log10(MinResolution);
            double resLog = (1 - value) * (max - min) + min;
            return Math.Pow(10double ResolutionTovalue( resolution)
        {
            double value = 1 - ((Math.Log10(resolution) - min) / (max - min));
            return Math.Min(1,Math.Max(value,0)); cap values between 0..1
        }

         SetupZoom()
        {
            null && Map != double.IsNaN(MinResolution) && !double.IsNaN(MaxResolution) &&
                    MaxResolution != double.MaxValue &&
                    MinResolution != double.Epsilon &&
                    !.IsNaN(Map.Resolution))
                {
                    ZoomSlider.Value = ResolutionTovalue(Map.Resolution);
                }
            }
        }

        #region Properties

        static readonly DependencyProperty MapProperty = DependencyProperty.Register(Maptypeof(Map),255)">typeof(MapNavigator),0)"> PropertyMetadata(OnMapPropertyChanged));

         OnMapPropertyChanged(DependencyObject d,DependencyPropertyChangedEventArgs e)
        {
            MapNavigator nav = d  MapNavigator;
            Map map = e.NewValue  Map;
            Map oldmap = e.OldValue  Map;

            if (oldmap != )
            {
                oldmap.RotationChanged -= nav.Map_RotationChanged;
                oldmap.ExtentChanged -= nav.Map_ExtentChanged;
                oldmap.ExtentChanging -= nav.Map_ExtentChanged;
                if (oldmap.Layers != )
                    oldmap.Layers.LayersInitialized -= nav.Layers_LayersInitialized;
            }
            if (map != )
            {
                map.RotationChanged += nav.Map_RotationChanged;
                map.ExtentChanged += nav.Map_ExtentChanged;
                map.ExtentChanging +=if (map.Layers != )
                    map.Layers.LayersInitialized += nav.Layers_LayersInitialized;
                nav.SetupZoom();
            }
        }

        void Layers_LayersInitialized( Map Map
        {
            get { return GetValue(MapProperty)  Map; }
            set { SetValue(MapProperty,value); }
        }


        public Double PanFactor { return _panFactor; } set { _panFactor = value; } }

        void Map_RotationChanged(double value = (this.FlowDirection == System.Windows.FlowDirection.LeftToRight) ? (double)e.NewValue : -()e.NewValue;
            angle = ()e.NewValue;
        }

        #endregion
    }

复制代码

 

复制代码

 <Style targettype=nmap:MapNavigator">
        <Setter Property=Foreground" Value=White" />
        <Setter Property=Background#F0999988BorderBrushTransparent"/>
        <Setter Property=BorderThickness0Template">
            <Setter.Value>
                <ControlTemplate  targettype=">
                    <Grid x:Name=NavigatorRootGrid" Background=" RenderTransformOrigin=0.5,0.5" Opacity=1">
                        <Grid.Resources>
                            <RadialGradientBrush x:Key=CircleButtonGradientBrush" GradientOrigin=0.25,0.25">
                                <GradientStop Offset=0.25" Color=#99CCCCCC"/>
                                <GradientStop Offset=1.00#99000000"/>
                            </RadialGradientBrush>

                            <SolidColorBrush x:Key=HoverShineBrush#749dd2" />
                            <DropShadowEffect x:Key=HoverShineEffect" BlurRadius=20" ShadowDepth=" />

                            <LinearGradientBrush x:Key=ThumbGradientBrush" EndPoint=" StartPoint=">
                                <GradientStop Color=" Offset=" />
                                <GradientStop Color=" />
                            </LinearGradientBrush>

                            <LinearGradientBrush x:Key=ThumbpressedBrush#99333333" />
                            </LinearGradientBrush>

                            <!--Circle Button Style-->
                            <Style targettype=Button" x:Key=CircleButtonStyle" >
                                <Setter Property=#F0CCCCCC" />
                                <Setter Property=#FF000000#F0333333Padding"/>
                                <Setter Property=">
                                    <Setter.Value>
                                        <ControlTemplate xmlns:vsm=clr-namespace:System.Windows;assembly=System.Windows" targettype=">
                                            <Grid x:Name=ButtonRootGrid">
                                                <visualstatemanager.VisualStateGroups>
                                                    <VisualStateGroup x:Name=CommonStates" >
                                                        <VisualState x:Name=" />
                                                        <VisualState x:Name=">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName=HoverShineshape" Storyboard.TargetProperty=Opacity" To=1.0" Duration=0:0:0.1" />
                                                            </Storyboard>
                                                        </VisualState>
                                                        <VisualState x:Name=presseddisableddisabledMask0.7" />
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                </visualstatemanager.VisualStateGroups>
                                                <Ellipse x:Name=BackgroundShape" Width={TemplateBinding Width}" Height={TemplateBinding Height} 
                                            Fill={TemplateBinding Background}" stroke={TemplateBinding BorderBrush} 
                                            strokeThickness={TemplateBinding BorderThickness}"/>
                                                <Ellipse x:Name=
                                            Fill={StaticResource HoverShineBrush}#00FFFFFF" strokeThickness=
                                            Effect={StaticResource HoverShineEffect}0.0" />
                                                <ContentPresenter x:Name=contentPresenter" Content={TemplateBinding Content}
                                            ContentTemplate={TemplateBinding ContentTemplate} 
                                            VerticalAlignment={TemplateBinding VerticalContentAlignment}
                                            HorizontalAlignment={TemplateBinding HorizontalContentAlignment}" Margin={TemplateBinding Padding}" />
                                                <Ellipse x:Name=#F0999999" IsHitTestVisible=false"/>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                            <!-- Zoom Bar Thumb Style-->
                            <Style targettype=ThumbZoomBarThumbStyle">
                                <Setter Property={StaticResource ThumbGradientBrush}IsTabStopFalse">
                                    <Setter.Value>
                                        <ControlTemplate targettype=ThumbrootGrid">
                                                        <VisualStateGroup.Transitions>
                                                            <VisualTransition GeneratedDuration=00:00:00.1" />
                                                            <VisualTransition GeneratedDuration=" />
                                                            <VisualTransition From=" GeneratedDuration=00:00:00.25" />
                                                        </VisualStateGroup.Transitions>
                                                        <VisualState x:Name=HoverShineBorderpressedBorderdisabledBorder0.5" />
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                </visualstatemanager.VisualStateGroups>
                                                <Border x:Name=BackgroundBorder
                                         BorderBrush= 
                                         BorderThickness=" CornerRadius=2" />
                                                <Border x:Name=" BorderThickness=
                                          CornerRadius={StaticResource ThumbpressedBrush}" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>

                            <!-- Zoom Slider Style-->
                            <Style targettype=SliderZoomSliderStyle#99666666MaximumMinimumLayoutRoot">
                                                <Grid.Resources>
                                                    <ControlTemplate x:Key=RepeatButtonTemplate1">
                                                        <Grid x:Name=Root" />
                                                    </ControlTemplate>
                                                    <ControlTemplate x:Key=RepeatButtonTemplate2"  />
                                                    </ControlTemplate>
                                                </Grid.Resources>
                                                <visualstatemanager.VisualStateGroups>
                                                    <VisualStateGroup x:Name=">
                                                        <VisualState x:Name=">
                                                            <Storyboard>
                                                                <DoubleAnimationUsingKeyFrames Storyboard.TargetName=(UIElement.Opacity)">
                                                                    <SplineDoubleKeyFrame KeyTime=" />
                                                                </DoubleAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </VisualState>
                                                    </VisualStateGroup>
                                                </visualstatemanager.VisualStateGroups>
                                                <Grid x:Name=HorizontalTemplate0,0">
                                                    <Grid.ColumnDeFinitions>
                                                        <ColumnDeFinition Width=Auto" />
                                                        <ColumnDeFinition Width=*" />
                                                    </Grid.ColumnDeFinitions>
                                                    <Rectangle Margin=" Grid.Column=" Grid.ColumnSpan=3" Fill=0.8" RadiusX=" RadiusY=" />
                                                    <RepeatButton x:Name=HorizontalTrackLargeChangeDecreaseRepeatButton" IsTabStop=" Template={StaticResource RepeatButtonTemplate2}HorizontalTrackLargeChangeIncreaseRepeatButton{StaticResource RepeatButtonTemplate1}" />
                                                    <Thumb x:Name=HorizontalThumb8True" Style={StaticResource ZoomBarThumbStyle}" />
                                                </Grid>
                                                <Grid x:Name=VerticalTemplate" Visibility=Collapsed">
                                                    <Grid.RowDeFinitions>
                                                        <RowDeFinition Height=" />
                                                        <RowDeFinition Height=" />
                                                    </Grid.RowDeFinitions>
                                                    <Rectangle Margin=4,0)">" Grid.Row=" Grid.RowSpan=
                                             stroke=VerticalTrackLargeChangeDecreaseRepeatButton
                                             Template=VerticalTrackLargeChangeIncreaseRepeatButton" BorderBrush=" />
                                                    <Grid Margin=6,2,6,2
                                             Grid.RowSpan=" HorizontalAlignment=Stretch
                                              VerticalAlignment=
                                               Background=#FFFBF9FA" >
                                                        <Grid.RowDeFinitions>
                                                            <RowDeFinition Height=" />
                                                            <RowDeFinition Height=" />
                                                        </Grid.RowDeFinitions>
                                                        <Rectangle Grid.Row={TemplateBinding Foreground}" />
                                                        <Rectangle Grid.Row=#F0FFFFFF4567910111213141516171819" />
                                                    </Grid>
                                                    <Thumb x:Name=VerticalThumb 
                                                            Width= 
                                                            Style=" >
                                                        <Thumb.BorderBrush>
                                                            <LinearGradientBrush EndPoint=">
                                                                <GradientStop Color=#FFA3AEB9"/>
                                                                <GradientStop Color=#FF8399A90.375#FF718597#FF6C84A4"/>
                                                            </LinearGradientBrush>
                                                        </Thumb.BorderBrush>
                                                        <Thumb.Background>
                                                            <RadialGradientBrush>
                                                                <GradientStop Color=#FF749DD2"/>
                                                            </RadialGradientBrush>
                                                        </Thumb.Background>
                                                    </Thumb>
                                                </Grid>
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>

                        <Grid.RowDeFinitions>
                            <RowDeFinition Height=64" />
                            <RowDeFinition Height=" />
                            <RowDeFinition />
                            <RowDeFinition Height=" />
                        </Grid.RowDeFinitions>

                        <visualstatemanager.VisualStateGroups>
                            <VisualStateGroup x:Name=" >
                                <VisualState x:Name=" />
                                <VisualState x:Name=">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName=0:0:0" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </visualstatemanager.VisualStateGroups>

                        <Grid x:Name=Navigator60Center" VerticalAlignment=">
                            <Grid.RenderTransform>
                                <RotateTransform x:Name=TransformRotate" Angle="/>
                            </Grid.RenderTransform>
                            <Ellipse x:Name=RotateRing1 
                                     VerticalAlignment= 
                                     stroke=#FFA6A6A6">
                                <Ellipse.Fill>
                                    <RadialGradientBrush>
                                        <GradientStop Color="/>
                                        <GradientStop Color="/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <local:ButtonGrid x:Name= 
                                                BackgroundShape=M0.0,4.0 A10,3.0 0 0 1 20,4.0 L16,16 A8.0,4.0 0 0 0 4.0,16 L0.0,4.0 z 
                                                ForegroundShape=" ForeBorderBrush=
                                                ForeBorderThick=" ForeShapeFill=" MouSEOverBackFill=
                                                MouSEOverForeFill=CyanTop
                                                ToolTipService.ToolTip=向上平移" Cursor=Hand" />
                            <local:ButtonGrid x:Name=" BackgroundShape=M20,12 A10,3.0 0 0 1 0.0,12 L4.0,0.0 A8.0,4.0 0 0 0 16,0.0 L20.0,12 z
                                                ForegroundShape= 
                                                ForeBorderBrush=" MouSEOverForeBorderBrush=
                                                VerticalAlignment=Bottom" ToolTipService.ToolTip=向下平移"/>
                            <local:ButtonGrid x:Name=2,0)">M4.0,0.0 L16,4.0 A4.0,8.0 0 0 0 16,16 L4.0,20 A3.0,10 0 0 1 4.0,0.0 zM1.0,0.0 L0.0,0.5 L1.0,1.0
                                                ForeBorderBrush= 
                                                HorizontalAlignment=Left向左平移M12,0 A3.0,10 0 0 1 12,20 L0.0,16 A4.0,8.0 0 0 0 0.0,4.0 L12.0,0.5 L0.0,0)">
                                                HorizontalAlignment=Right向右平移"/>
                            <Button x:Name=ResetRotation{StaticResource CircleButtonStyle}24 
                                    HorizontalAlignment= 
                                    ToolTipService.ToolTip=Reset Map north">
                                <Image Source=../Images/icons/i_nav.png" Stretch=Uniform" />
                            </Button>
                        </Grid>

                        <Grid x:Name=ZoomHistoryPanel">
                            <Grid.ColumnDeFinitions>
                                <ColumnDeFinition Width="/>
                                <ColumnDeFinition Width="/>
                            </Grid.ColumnDeFinitions>
                            <local:ButtonGrid  x:Name=ZoomBackButton1,-1,0)">
                                                BackgroundShape=" BackShapeFill=#F0666666Zoom to PrevIoUs ExtentZoomFullButtonZoom to Full Extent../Images/icons/i_globe.png"  Width=" />
                            </Button>
                            <local:ButtonGrid x:Name=ZoomNextButton-1,1,0)">" ForegroundShape=Zoom to Next Extent"/>
                        </Grid>

                        <Border x:Name=ZoomSliderBorder
                                BorderBrush=">
                            <StackPanel x:Name=ZoomStack" Orientation=Vertical">
                                <Button x:Name=22" Foreground=Black 
                                        BorderBrush=Zoom In" >
                                    <Button.Background>
                                        <RadialGradientBrush>
                                            <GradientStop Color="/>
                                            <GradientStop Color="/>
                                        </RadialGradientBrush>
                                    </Button.Background>
                                    <Path stroke=#a6a6a6 
                                          Width=Fill" Data= 
                                          Fill=#FF949494"/>
                                </Button>
                                <Grid x:Name=ZoomLevelGrid">
                                    <Slider x:Name=150
                                            Minimum=" Maximum=" SmallChange=" LargeChange= 
                                            ToolTipService.ToolTip=拖动缩放{StaticResource ZoomSliderStyle} 
                                            BorderBrush=SizeNS#fbf9fa" />
                                </Grid>
                                <Button x:Name=Zoom Out">
                                    <Button.Background>
                                        <RadialGradientBrush>
                                            <GradientStop Color="  strokeThickness="/>
                                </Button>
                            </StackPanel>
                        </Border>

                        <ContentPresenter Grid.Row=" ContentTemplate=
                                          Content=
                                          Margin=" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐