当前位置:编程学习 > 网站相关 >>

silverlight 连接google map

        string baseUrl = "http://mt2.google.cn/vt/lyrs=s@167000000&hl=zh-CN&gl=cn&s=Galil&x=";//卫星图
        string cbaseUrl = "http://mt2.google.cn/vt/lyrs=m@167000000&hl=zh-CN&gl=cn&x=0&y=0&z=0&s=Galil";//市区图
 
 
 
 
 
页面
 
<UserControl x:Class="SilverlightApplication6.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:open="clr-namespace:ESRI.ArcGIS.Client.Toolkit.DataSources;assembly=ESRI.ArcGIS.Client.Toolkit.DataSources"
             xmlns:Classgoole="SilverlightApplication6"
    mc:Ignorable="d"
             
    d:DesignHeight="300" d:DesignWidth="400" xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
 
    <Grid x:Name="LayoutRoot" Background="White">
        <esri:Map Background="White" HorizontalAlignment="Left" Name="map1" VerticalAlignment="Top" Height="300" Width="400">         
        </esri:Map>
    </Grid>
</UserControl>
 
后台
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightApplication6
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            map1.Loaded += LoadMap;
        }
        private void LoadMap(object sender, RoutedEventArgs e)
        {
            GoogleMapLayer gm = new GoogleMapLayer();
           
            map1.Layers.Add(gm);
        }
 
    }
}
GoogleMapLayer
 
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
 
public class GoogleMapLayer : TiledMapServiceLayer
{
    private const double cornerCoordinate = 20037508.3427892;
    public override void Initialize()
    {
        //this.Opacity = 0.5;
 
        this.FullExtent = new
 
        ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.342787, -20037508.342787, 20037508.342787, 20037508.342787);//(-180,-85.0511287798066,180, 85.0511287798066)
 
        {
 
            SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100);
 
        };
 
        this.SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100);
 
        //this.InitialExtent = this.FullExtent;
 
        this.TileInfo = new TileInfo()
 
        {
 
            Height = 256,
 
            Width = 256,
 
            Origin = new ESRI.ArcGIS.Client.Geometry.MapPoint(-20037508.342787,20037508.342787)//Origin = new ESRI.ArcGIS.Geometry.MapPoint(-180, 90)
 
            {
 
                SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100)
 
            },
 
            Lods = new Lod[20]
 
        };
 
        double resolution = 156543.033928;
 
        for(int i = 0; i < TileInfo.Lods.Length; i++)
 
        {
 
            TileInfo.Lods[i] = new Lod() { Resolution = resolution };
 
            resolution /= 2;
 
        }
 
        base.Initialize();
 
 
        //this.FullExtent = new ESRI.ArcGIS.Client.Geometry.Envelope(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892)
        //{
        //    SpatialReference = new SpatialReference(102100)
        //};
        //// This layer's spatial reference
        //this.SpatialReference = new SpatialReference(102100);
        //// Set up tile information. Each tile is 256x256px, 19 levels.
        //this.TileInfo = new TileInfo()
        //{
        //    Height = 256,
        //    Width = 256,
        //    Origin = new MapPoint(-cornerCoordinate, cornerCoordinate) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(102100) },
        //    Lods = new Lod[19]
        //};
        //// Set the resolutions for each level. Each level is half the resolution of the previous one.
        //double resolution = cornerCoordinate * 2 / 256;
补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,