<esri:Map Extent="-120, 20, -100, 40" Grid.Row="3" Name="MyMap" Visibility="Visible" Background="Transparent" Margin="2,0" BorderThickness="1" BorderBrush="{StaticResource TitleBarGradient}"> <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" /> <esri:GraphicsLayer ID="MyGraphicsLayer" /> </esri:Map>Solved! Go to Solution.
Ok Joe let me try. Now the things is working fine in vb.net. I have a problem in one line of codeIf CInt(lod.Resolution) <= CInt(Math.Truncate(currentResolution)) Then
This line i am getting error
truncate is not a member of system.math
1.how can i write this line in another way for same result?
2.i generated google API key ,in this project where i need to specify google API kety???
3.Whether it is legal to use Google API key or not?We have licence of arcgis desktop10 and arcgis server.
There is nothing along the lines of a Silverlight control for google maps (certainly none I am aware of).
Good luck
-Joe
Hmm. I was able to download and open the sample in VS 2010 (Version 10.0.40219.1 SP1Rel). I just had to update references and replace ScaleBar with ScaleLine. http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Scaleline
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);
Interesting post, thanks.
In the mapUrl returned the maptype is definedmapURL = 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);
Seems you could make two other Google layer classes nearly identical to the one Rex provides but one would have maptype=satellite and one maptype=hybrid (https://developers.google.com/maps/documentation/staticmaps/#MapTypes). When the user clicks the button either add/remove layers or set the Visible property accordingly. I would test, but the environment I work in does not allow outside access from our development machines
Good luck
-Joe
If CInt(lod.Resolution) <= CInt(Math.Truncate(currentResolution)) Then
Ok Joe let me try. Now the things is working fine in vb.net. I have a problem in one line of codeIf CInt(lod.Resolution) <= CInt(Math.Truncate(currentResolution)) Then
This line i am getting error
truncate is not a member of system.math
1.how can i write this line in another way for same result?
2.i generated google API key ,in this project where i need to specify google API kety???
3.Whether it is legal to use Google API key or not?We have licence of arcgis desktop10 and arcgis server.
......could make two other Google layer classes nearly identical to the one Rex provides but one would have maptype=satellite and one maptype=hybrid (...ks the button either add/remove layers or set the Visible property accordingly...e
Private Sub RadRoadMap_Checked(sender As Object, e As System.Windows.RoutedEventArgs) Handles RadRoadMap.Checked
MyMap.Layers("222").Visible = True
MyMap.Layers("111").Visible = False
End Sub
Private Sub RadSatellite_Checked(sender As Object, e As System.Windows.RoutedEventArgs) Handles RadSatellite.Checked
MyMap.Layers("222").Visible = False
MyMap.Layers("111").Visible = True
End Sub<esri:Map x:Name="MyMap" Grid.Row="3" SnapToLevels="True" Visibility="Visible" Background="Transparent" Margin="2,0" BorderThickness="1" BorderBrush="{StaticResource TitleBarGradient}">
<esri:Map.Template>
<ControlTemplate>
<Grid Background="{TemplateBinding Background}">
<Grid x:Name="RootElement" Width="Auto" Height="Auto" />
<Rectangle x:Name="ZoomBox" Fill="#55FFFFFF" Stroke="Green" StrokeThickness="2" Visibility="Collapsed" />
<esri:ScaleBar x:Name="MyScaleBar" Margin="75,5,5,5" MapUnit="Meters" TextColor="Black" HorizontalAlignment="Left" VerticalAlignment="Bottom" DisplayUnit="Miles" Map="{Binding ElementName=MyMap}" />
</Grid>
</ControlTemplate>
</esri:Map.Template>
<esri:Map.Layers>
<customLayers:MercatorSchemaTiledLayer Visible="False" />
<customLayers:GoogleStaticMapLayer ID="222"/>
<esri:ArcGISDynamicMapServiceLayer ID="OperationalLayer" Opacity="0.7" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayers/MapServer" />
<customLayers:MercatorSchemaTiledLayer Visible="False" />
<customLayers:GoogleStaticMapLayerSatellite ID="111" Visible="False"/>
<esri:ArcGISDynamicMapServiceLayer ID="OperationalLayer1" Visible="False" Opacity="0.7" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyOperationalLayers/MapServer" />
<esri:GraphicsLayer ID="MyGraphicsLayer" />
</esri:Map.Layers>
</esri:Map>Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Geometry
Public Class GoogleStaticMapLayerSatellite
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
'If width > 640 OrElse height > 640 Then
' Throw New Exception("Width or height greater than 640")
'End If
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(Math.Truncate(currentResolution)) Then
If CInt(lod.Resolution) <= CInt((currentResolution)) Then
requestWidth = CInt(extent.Width / lod.Resolution)
requestHeight = CInt(extent.Height / lod.Resolution)
Exit For
End If
Next
'If requestWidth > 640 OrElse requestHeight > 640 Then
' Throw New Exception("Request width or height greater than 640")
'End If
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=satellite&sensor=false", geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight)
Catch ex As Exception
' Message box just for debug purposes
'System.Windows.MessageBox.Show( ex.Message,"Error: Google Static Map not generated", System.Windows.MessageBoxButton.OK);
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 ClassImports 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
'If width > 640 OrElse height > 640 Then
' Throw New Exception("Width or height greater than 640")
'End If
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(Math.Truncate(currentResolution)) Then
If CInt(lod.Resolution) <= CInt((currentResolution)) Then
requestWidth = CInt(extent.Width / lod.Resolution)
requestHeight = CInt(extent.Height / lod.Resolution)
Exit For
End If
Next
'If requestWidth > 640 OrElse requestHeight > 640 Then
' Throw New Exception("Request width or height greater than 640")
'End If
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", geogCenterPoint.Y, geogCenterPoint.X, currentLodIndex, requestWidth, requestHeight)
Catch ex As Exception
' Message box just for debug purposes
'System.Windows.MessageBox.Show( ex.Message,"Error: Google Static Map not generated", System.Windows.MessageBoxButton.OK);
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