ArcGIS API for Silverlight loading Google topographic map (tile map)

Source: Internet
Author: User
Tags silverlight

Original: ArcGIS API for Silverlight loading Google topographic map (tile map)

In Water Conservancy, meteorology, land and other industries, if you can use Google's topographic map that is more appropriate, the following describes how to load the Google site in ArcGIS API for Silverlight

Image. First on a diagram, preliminary production, pending further improvement

The arcgistiledmapservicelayer layer in ArcGIS API for Silverlight inherits from Tiledmapservicelayer. If you want to implement your own cached maplayer, inherit it and reload the Gettileurl method. the ArcGIS API for Silverlight internally calculates the current access zoom level, the slice two-dimensional number row,Col. These parameters are exposed to the Gettileurl method, where the URL to the Google static map is set. 1. Create a new folder in the Silverlight project and add a file named GoogletOpographicLayer.cs , which reads as follows :
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;namespace googlemap.commonclass{public class Googletopographiclayer:tiledmapservicelayer {        Private Const Double cornercoordinate = 20037508.3427892; private string _baseurl = "[email protected]"; Google topographic map public override void Initialize () {ESRI. ArcGIS.Client.Projection.WebMercator mercator = new ESRI.            ArcGIS.Client.Projection.WebMercator (); This. Fullextent = new ESRI.                ArcGIS.Client.Geometry.Envelope (-20037508.3427892,-20037508.3427892, 20037508.3427892, 20037508.3427892) {            Spatialreference = new Spatialreference (102100)}; The spatial coordinate system of the layer this. SpatialreferencE = new Spatialreference (102100);            Create slice information, each tile size 256*256px, a total of 16 levels. This. Tileinfo = new Tileinfo () {Height = $, Width = at-A, Origin = NE W MapPoint (-cornercoordinate, cornercoordinate) {spatialreference = new ESRI.            ArcGIS.Client.Geometry.SpatialReference (102100)}, LODs = new lod[16]};            Establish a programme for each level, with each level being half the previous level.            Double Resolution = Cornercoordinate * 2/256; for (int i = 0; i < TileInfo.Lods.Length; i++) {tileinfo.lods[i] = new Lod () {Resolution =                Resolution};            Resolution/= 2; }//Call initialization function base.        Initialize (); } public override string Gettileurl (int. level, int row, int col) {string url = "HTTP://MT" + (CO L% 4) + ". Google.cn/vt/lyrs=" + _baseurl + "&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + ro W + "&" + "z=" + Level + "&s=galil"; if (_baseurl = = "[email protected]") {URL = "http://mt" + (col% 4) + ". google.cn/vt/lyrs  = "+ _baseurl +" &v=w2.114&hl=zh-CN&gl=cn& "+" x= "+ col +" & "+" y= "+ Row +" & "+" z= "+ level + "&s=galil"; Load Google Remote Sensing Map} if (_baseurl = = "[email protected]") {URL = "/http/  Mt "+ (col% 4) +". Google.cn/vt/lyrs= "+ _baseurl +",[email protected]&v=w2.114&hl=zh-cn&gl=cn& "+ "x=" + col + "&" + "y=" + Row + "&" + "z=" + level + "&s=galil";//load Google topographic map} if (_b Aseurl = = "[email protected]") {URL = "http://mt" + (col% 4) + ". google.cn/vt/lyrs=" + _b Aseurl + "&v=w2.114&hl=zh-CN&gl=cn&" + "x=" + col + "&" + "y=" + Row + "&" + "z=" + Level + "& S=galil "; Load Google street map} return string.            Format (URL); Call to load the initialGoogle street map//string baseUrl = "Http://mt2.google.cn/vt/v=w2.116&hl=zh-cn&gl=cn&x={0}&y={1}&amp            ; Z={2}&s=g "; return string.        Format (BaseUrl, col, row, level); There are three types of Google Maps displayed above}}//, and you can modify the initial values of the variable _baseurl as needed.

2. The contents of the MainPage.xaml file in the Silverlight project are as follows:
<usercontrol x:class= "Googlemap.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/ "Xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "xmlns:esri=" http// schemas.esri.com/arcgis/client/2009 "xmlns:controlstoolkit=" clr-namespace:system.windows.controls;assembly= System.Windows.Controls.Toolkit "xmlns:sdk=" Http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk "xmlns" : layer= "Clr-namespace:googlemap.commonclass" d:designheight= "d:designwidth=" loaded= "UserControl_Loaded" > <grid x:name= "LayoutRoot" background= "white" > <esri:map x:name= "myMap" islogovisible= "False" zoomduration= "0:00:02" panduration= "0:00:02" > </esri:Map> </Grid></UserControl>

3. The contents of the MainPage.xaml.cs file in the Silverlight project are as follows:

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;using testdzx.commonclass;using ESRI. Arcgis.client.geometry;using ESRI. Arcgis.client;namespace googlemap{public partial class Mainpage:usercontrol {ESRI. ArcGIS.Client.Projection.WebMercator mercator = new ESRI.        ArcGIS.Client.Projection.WebMercator ();        Public MainPage () {InitializeComponent ();  private void Usercontrol_loaded (object sender, RoutedEventArgs e) {Googletopographiclayerlayer            = new Googletopographiclayer ();        MYMAP.LAYERS.ADD (layer); }    }}

4, after completing the above steps, run, you can see Google topographic map, just try It,have fun!

5, add: Here is the Mercator coordinates, and we often use the latitude and longitude coordinates, which need to do the conversion, the following provides a class, WKIDConvert.cs, content

As follows:

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.geometry;namespace googlemap.commonclass{public static class Wkidconvert {//latitude/longitude to Mercator PU            Blic static MapPoint Lonlat2mercator (MapPoint lonlat) {MapPoint mercator = new MapPoint (); Double X = Lonlat.            X * 20037508.34/180; Double Y = Math.Log (Math.tan ((+ Lonlat).            Y) * math.pi/360)/(math.pi/180);            y = y * 20037508.34/180; Mercator.            x = x; Mercator.            y = y;        return Mercator; }//Mercator warp latitude public static MapPoint Mercator2lonlat (MapPoint Mercator) {MapPoint Lonlat =            New MapPoint (); Double X = Mercator.            x/20037508.34 * 180; Double Y = Mercator. Y/20037508.34 * 180;            Y = 180/math.pi * (2 * Math.atan (MATH.EXP (Y * math.pi/180))-MATH.PI/2); Lonlat.            x = x; Lonlat.            y = y;        return Lonlat; }    }}

Then if we want to locate a city, such as Huangshan, its extent is: 117.647738815324,29.4704217183843,118.446182957997,30.4124245048916

Here we add a line of code to the MainPage.xaml.cs to navigate to the Huangshan range

private void Usercontrol_loaded (object sender, RoutedEventArgs e)
{

Googletopographiclayer layer = new Googletopographiclayer ();

MYMAP.LAYERS.ADD (layer);
mymap.extent = new Envelope (Wkidconvert.lonlat2mercator (New MapPoint (117.647738815324, 29.4704217183843)), Wkidconvert.lonlat2mercator (New MapPoint (118.446182957997, 30.4124245048916));
}

6, re-add: In the previous Google topographic map overlay custom ArcMap maps, can be a dynamic graph can also be a static diagram, as long as the published map, you can display, add the following lines of code in MainPage.xaml.cs.

private void Usercontrol_loaded (object sender, RoutedEventArgs e)
{
Overlay Google topographic Tiles
Googletopographiclayer layer = new Googletopographiclayer ();
MYMAP.LAYERS.ADD (layer);
Layer. Opacity = 1;

//Load dynamic diagram
ESRI. ArcGIS.Client.ArcGISDynamicMapServiceLayer Dlayer = new ESRI. ArcGIS.Client.ArcGISDynamicMapServiceLayer ();
MyMap.Layers.LayersInitialized + = (evtsender, args) =
{
Mymap.zoomto (dlayer.initialextent);
};
Dlayer.url = "http://localhost/arcgis/rest/services/HS/MapServer/";
MYMAP.LAYERS.ADD (Dlayer);
dlayer.opacity = 1;

Mymap.extent = new Envelope (Wkidconvert.lonlat2mercator (New MapPoint (117.647738815324, 29.4704217183843)), Wkidconvert.lonlat2mercator (New MapPoint (118.446182957997, 30.4124245048916));
}

As below, this is just the Huangshan of the city boundary, the main role is in the Google topographic map clearly see the scope of Huangshan:

===========================================================================

If you find it helpful, scan for support:


ArcGIS API for Silverlight loading Google topographic map (tile map)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.