Private Sub AddPolygonGraphics(coordinateString1 As String, Gname As String, Gdesc As String)
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
Dim pointConverter As New PointCollectionConverter()
Dim pointCollection1 As ESRI.ArcGIS.Client.Geometry.PointCollection = TryCast(pointConverter.ConvertFromString(coordinateString1), ESRI.ArcGIS.Client.Geometry.PointCollection)
Dim polygon1 As New ESRI.ArcGIS.Client.Geometry.Polygon()
polygon1.Rings.Add(pointCollection1)
_activeSymbol = TryCast(LayoutRoot.Resources("DefaultFillSymbolT"), Symbol)
Dim graphic As New Graphic() With
{
.Geometry = mercator.FromGeographic(polygon1),
.Symbol = _activeSymbol
}
polygon1.SpatialReference = New SpatialReference(4326)
Dim strhotspot As String = ""
strhotspot = Trim(Gname)
If Gdesc <> "" Then
strhotspot = strhotspot & "," & Trim(Gdesc)
End If
graphicsLayer.Graphics.Add(graphic)
MyMap.ZoomTo(graphicsLayer.FullExtent)
End SubImports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Public Class GoogleStaticMapLayer
Inherits DynamicMapServiceLayer
Private Shared mercator As New ESRI.ArcGIS.Client.Projection.WebMercator()
Private Const cornerCoordinate As Double = 20037508.3427892
Private Const WKID As Integer = 102100
Public Sub New()
MyBase.New()
End Sub
Private Property Lods() As Lod()
Get
Return m_Lods
End Get
Set(value As Lod())
m_Lods = Value
End Set
End Property
Private m_Lods As Lod()
Public Overrides Sub Initialize()
Me.FullExtent = New ESRI.ArcGIS.Client.Geometry.Envelope(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate) With { _
.SpatialReference = New SpatialReference(WKID) _
}
Me.SpatialReference = New SpatialReference(WKID)
Lods = New Lod(20) {}
Dim resolution As Double = cornerCoordinate * 2 / 256
For i As Integer = 0 To Lods.Length - 1
Lods(i) = New Lod() With { _
.Resolution = resolution _
}
resolution /= 2
Next
MyBase.Initialize()
End Sub
Public Overrides Sub GetUrl(extent As ESRI.ArcGIS.Client.Geometry.Envelope, width As Integer, height As Integer, onComplete As DynamicMapServiceLayer.OnUrlComplete)
Dim geogCenterPoint As MapPoint = Nothing
Dim mapURL As String = Nothing
Try
Dim currentResolution As Double = extent.Width / width
Dim currentLodIndex As Integer = 0
Dim requestWidth As Integer = 0
Dim requestHeight As Integer = 0
For i As Integer = 0 To Lods.Length - 1
Dim lod As Lod = Lods(i)
currentLodIndex = i
If CInt(lod.Resolution) <= CInt((currentResolution)) Then
requestWidth = CInt(extent.Width / lod.Resolution)
requestHeight = CInt(extent.Height / lod.Resolution)
Exit For
End If
Next
geogCenterPoint = TryCast(mercator.ToGeographic(extent.GetCenter()), MapPoint)
mapURL = String.Format("http://maps.google.com/maps/api/staticmap?center={0},{1}&zoom={2}&size={3}x{4}&scale=2&maptype=roadmap&sensor=false&key=AIzaSyDoFucUPlE1lpMxNqc1-cN-dihqGZuLYUw", geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight)
Catch ex As Exception
Return
End Try
onComplete(mapURL, width, height, New ESRI.ArcGIS.Client.Geometry.Envelope() With { _
.XMin = extent.XMin, _
.YMin = extent.YMin, _
.XMax = extent.XMax, _
.YMax = extent.YMax _
})
End Sub
End Class
<esri:Map.Layers> <customLayers:MercatorSchemaTiledLayer Visible="False" /> <customLayers:GoogleStaticMapLayer ID="roadmap" Visible="True"/> <customLayers:GoogleStaticMapLayerSatellite ID="satelite" Visible="False"/> <customLayers:GoogleStaticMapLayerTerrain ID="terrain" Visible="False"/> <customLayers:GoogleStaticMapLayerHybrid ID="hybrid" Visible="False"/> <esri:GraphicsLayer ID="MyGraphicsLayer" /> </esri:Map.Layers> </esri:Map>
Public Class GoogleStaticMapLayer Inherits DynamicMapServiceLayer Private Shared mercator As New ESRI.ArcGIS.Client.Projection.WebMercator() Private Const cornerCoordinate As Double = 20037508.3427892 Private Const WKID As Integer = 102100
<esri:Map x:Name="MyMap" WrapAround="true"> <esri:ArcGISTiledMapServiceLayer ID="BaseLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_D/MapServer" /> <customLayers:DynamicWmsLayer x:Name="MyWmsLayer" /> </esri:Map>
using System;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
namespace CustomLayers
{
public class DynamicWmsLayer : DynamicMapServiceLayer
{
public DynamicWmsLayer() : base()
{
}
public override void Initialize()
{
this.FullExtent = new Envelope(-126, 24, -66, 50) { SpatialReference = new SpatialReference(4326) };
this.SpatialReference = new SpatialReference(4326);
base.Initialize();
}
public override void GetUrl(Envelope extent, int width, int height, OnUrlComplete onComplete)
{
string mapURL = "http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=nexrad-n0r,nexrad-n0r-900913,nexrad-n0r-900913-m05m,nexrad-n0r-900913-m10m,nexrad-n0r-900913-m15m,nexrad-n0r-900913-m20m,nexrad-n0r-900913-m25m,nexrad-n0r-900913-m30m,nexrad-n0r-900913-m35m,nexrad-n0r-900913-m40m,nexrad-n0r-900913-m45m,nexrad-n0r-900913-m50m,nexrad-n0r-m05m,nexrad-n0r-m10m,nexrad-n0r-m15m,nexrad-n0r-m20m,nexrad-n0r-m25m,nexrad-n0r-m30m,nexrad-n0r-m35m,nexrad-n0r-m40m,nexrad-n0r-m45m,nexrad-n0r-m50m&STYLES=&SRS=EPSG:4326&BBOX=-126,24,-66,50&WIDTH=600&HEIGHT=350&TRANSPARENT=TRUE&FORMAT=image/png";
onComplete(mapURL, width, height, new ESRI.ArcGIS.Client.Geometry.Envelope()
{
XMin = extent.XMin,
YMin = extent.YMin,
XMax = extent.XMax,
YMax = extent.YMax
});
}
}
}
namespace CustomLayers
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
MyWmsLayer = new DynamicWmsLayer();
MyWmsLayer.Initialize();
MyMap.Extent = new Envelope(-126, 24, -66, 50) { SpatialReference = new SpatialReference(4326) };
}
}
}
onComplete(mapURL, width, height, new Envelope()
{
XMin = this.FullExtent.XMin,
YMin = this.FullExtent.YMin,
XMax = this.FullExtent.XMax,
YMax = this.FullExtent.YMax
});
string mapURL = http://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r.cgi?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap...;
using System;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Geometry;
namespace CustomLayers
{
public class GoogleStaticMapLayer : DynamicMapServiceLayer
{
private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
new ESRI.ArcGIS.Client.Projection.WebMercator();
private const double cornerCoordinate = 20037508.3427892;
private const int WKID = 102100;
public GoogleStaticMapLayer() : base(){ }
private Lod[] Lods { get; set;}
public override void Initialize()
{
this.FullExtent =
new ESRI.ArcGIS.Client.Geometry.Envelope(-cornerCoordinate, -cornerCoordinate, cornerCoordinate, cornerCoordinate)
{
SpatialReference = new SpatialReference(WKID)
};
this.SpatialReference = new SpatialReference(WKID);
Lods = new Lod[21];
double resolution = cornerCoordinate * 2 / 256;
for (int i = 0; i < Lods.Length; i++)
{
Lods = new Lod() { Resolution = resolution };
resolution /= 2;
}
base.Initialize();
}
public override void GetUrl(ESRI.ArcGIS.Client.Geometry.Envelope extent, int width, int height,
DynamicMapServiceLayer.OnUrlComplete onComplete)
{
MapPoint geogCenterPoint = null;
string mapURL = null;
try
{
//if (width > 640 || height > 640)
// throw new Exception("Width or height greater than 640");
double currentResolution = extent.Width / width;
int currentLodIndex = 0;
int requestWidth = 0;
int requestHeight = 0;
for (int i = 0; i < Lods.Length; i++)
{
Lod lod = Lods;
currentLodIndex = i;
if ((int)lod.Resolution <= (int)currentResolution)
{
requestWidth = (int)(extent.Width / lod.Resolution);
requestHeight = (int)(extent.Height / lod.Resolution);
break;
}
}
//if (requestWidth > 640 || requestHeight > 640)
// throw new Exception("Request width or height greater than 640");
geogCenterPoint = mercator.ToGeographic(extent.GetCenter()) as MapPoint;
mapURL = string.Format
("http://maps.google.com/maps/api/staticmap?center={0},{1}&zoom={2}&size={3}x{4}&maptype=roadmap&sensor=false",
geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight);
}
catch (Exception ex)
{
// Message box just for debug purposes
//System.Windows.MessageBox.Show( ex.Message,"Error: Google Static Map not generated", System.Windows.MessageBoxButton.OK);
return;
}
onComplete(mapURL, width, height, new ESRI.ArcGIS.Client.Geometry.Envelope()
{
XMin = extent.XMin,
YMin = extent.YMin,
XMax = extent.XMax,
YMax = extent.YMax
});
}
}
}