@Code
Dim i As Integer
Dim connectString As String = ConfigurationManager.ConnectionStrings("Connection").ConnectionString.ToString
Dim tableName As String = "TblName" 'Table Name for getting geo data
Dim tableField As String = "id" 'Field from the table for display geo map
Dim srid As Integer = "32723"
'Initialize the map and it's properties
Dim oid As Integer = 0
Dim MapBuilder = Html.ThinkGeo.Map("Map1", New System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 530)
MapBuilder.MapBackground(New BackgroundLayer(New GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"))))
MapBuilder.MapUnit(GeographyUnit.Meter)
MapBuilder.MapTools(Sub(tools)
tools.OverlaySwitcherMapTool().Enabled(true)
tools.MouseCoordinateMapTool().Enabled(True)
tools.KeyboardMapTool().Enabled(True)
tools.LoadingImageMapTool().Enabled(True)
End Sub)
MapBuilder.CurrentExtent(-5297892.20116, 7001997.4056, -2500796.18635, 3026987.386962)
MapBuilder.CustomOverlays(Sub(overlays)
overlays.GoogleOverlay("Google Map").JavaScriptLibraryUri(New Uri(ConfigurationManager.AppSettings("GoogleUriV3"))).GoogleMapType(GoogleMapType.Normal)
'=========Load Images on Map
Global.MvcGEO.MultiGeoRasterLayer.BuildReferenceFile(Server.MapPath("~\App_Data\6000\referenceFile.txt"), Server.MapPath("~\App_Data\6000\"))
Dim multiGeoRasterLayer As Global.MvcGEO.MultiGeoRasterLayer = New Global.MvcGEO.MultiGeoRasterLayer(Server.MapPath("~\App_Data\6000\referenceFile.txt"))
overlays.LayerOverlay("multiGeoRasterLayer").Layer("multiGeoRasterLayer", multiGeoRasterLayer).IsBaseOverlay(False).TileType(TileType.MultipleTile).IsVisible(True)
'=========Load map for Mapa_Beiral
Dim Mapa_Beiral As MsSql2008FeatureLayer = New MsSql2008FeatureLayer(connectString, "Mapa_Beiral", "geodb_oid", 32723)
Mapa_Beiral.Open()
Mapa_Beiral.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.DarkBlue)
Mapa_Beiral.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
Dim proj1 As Proj4Projection = New Proj4Projection()
proj1.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(32723)
proj1.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
proj1.Open()
Mapa_Beiral.FeatureSource.Projection = proj1
overlays.LayerOverlay("Mapa Beiral", False, TileType.SingleTile).Layer(Mapa_Beiral).IsVisible(False)
'I am using 6 overlays.Layeroverlay using above code
End Sub).OnClientClick("mapClickToEdit").Render()
-------------------------------------------HomeController.vb------------------------------------------------------------------
'There is one more class in this file "HomeController" which Inherits System.Web.Mvc.Controller and other logic related to project are in this class
Public Class MultiGeoRasterLayer
Inherits Layer
Private rasterRefrencePathFileName1 As String
Private spatialIndex As STRtree
Private upperScale1 As Double
Private lowerScale1 As Double
Private boundingBox As RectangleShape
Private Const upperLeftXPosition As Integer = 0
Private Const upperLeftYPosition As Integer = 2
Private Const lowerRightXPosition As Integer = 1
Private Const lowerRightYPosition As Integer = 3
Private Const pathFileNamePosition As Integer = 4
Public Sub DrawImage(map As Map)
Dim multiGeoRasterLayer As New MultiGeoRasterLayer("D:\Projects\App_Data\6000\referenceFile.txt")
Dim overlay As New LayerOverlay("multiGeoRasterLayer", False, TileType.MultipleTile)
overlay.IsBaseOverlay = False
overlay.Layers.Add(multiGeoRasterLayer)
map.CustomOverlays.Add(overlay)
End Sub
Public Sub New()
Me.New(String.Empty, Double.MaxValue, Double.MinValue)
End Sub
Public Sub New(rasterRefrencePathFileName1 As String)
Me.New(rasterRefrencePathFileName1, Double.MaxValue, Double.MinValue)
End Sub
Public Sub New(rasterRefrencePathFileName As String, upperScale As Double, lowerScale As Double)
Me.RasterRefrencePathFileName = rasterRefrencePathFileName
Me.UpperScale = upperScale
Me.LowerScale = lowerScale
boundingBox = New RectangleShape()
End Sub
Public Property RasterRefrencePathFileName() As String
Get
Return rasterRefrencePathFileName1
End Get
Set(value As String)
rasterRefrencePathFileName1 = value
End Set
End Property
Public Property UpperScale() As Double
Get
Return upperScale1
End Get
Set(value As Double)
upperScale1 = value
End Set
End Property
Public Property LowerScale() As Double
Get
Return lowerScale1
End Get
Set(value As Double)
lowerScale1 = value
End Set
End Property
Protected Overrides Sub OpenCore()
If File.Exists(RasterRefrencePathFileName) Then
Dim rasterFiles As String() = File.ReadAllLines(RasterRefrencePathFileName)
spatialIndex = New STRtree(rasterFiles.Length)
Dim boundingBoxes As New Collection(Of ThinkGeo.MapSuite.Core.BaseShape)()
For Each rasterLine As String In rasterFiles
Dim parts As String() = rasterLine.Split(New String() {","}, StringSplitOptions.None)
Dim rasterBoundingBox As New RectangleShape(New PointShape(Double.Parse(parts(upperLeftXPosition)), Double.Parse(parts(upperLeftYPosition))), New PointShape(Double.Parse(parts(lowerRightXPosition)), Double.Parse(parts(lowerRightYPosition))))
Dim envelope As New Envelope(Double.Parse(parts(upperLeftXPosition)), Double.Parse(parts(lowerRightXPosition)), Double.Parse(parts(upperLeftYPosition)), Double.Parse(parts(lowerRightYPosition)))
spatialIndex.Insert(envelope, parts(pathFileNamePosition))
Next
spatialIndex.Build()
boundingBox = ExtentHelper.GetBoundingBoxOfItems(boundingBoxes)
Else
Throw New FileNotFoundException("The Raster reference file could not be found.", RasterRefrencePathFileName)
End If
End Sub
Protected Overloads Sub CloseCore()
spatialIndex = Nothing
End Sub
Protected Overrides Sub DrawCore(canvas As GeoCanvas, labelsInAllLayers As Collection(Of SimpleCandidate))
Dim currentScale As Double = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit)
If currentScale >= LowerScale AndAlso currentScale <= UpperScale Then
Dim currentExtent As RectangleShape = canvas.CurrentWorldExtent
Dim currentExtentEnvelope As New Envelope(currentExtent.UpperLeftPoint.X, currentExtent.LowerRightPoint.X, currentExtent.UpperLeftPoint.Y, currentExtent.LowerRightPoint.Y)
Dim rasters As ArrayList = DirectCast(spatialIndex.Query(currentExtentEnvelope), ArrayList)
For Each file As String In rasters
Dim rasterRasterLayer As New GdiPlusRasterLayer(file)
rasterRasterLayer.Open()
rasterRasterLayer.Draw(canvas, labelsInAllLayers)
rasterRasterLayer.Close()
Next
End If
End Sub
Public Overrides ReadOnly Property HasBoundingBox() As Boolean
Get
Return True
End Get
End Property
Protected Overrides Function GetBoundingBoxCore() As RectangleShape
Return boundingBox
End Function
Public Shared Sub BuildReferenceFile(newReferencepathFileName As String, pathOfRasterFiles As String)
Try
If Directory.Exists(pathOfRasterFiles) Then
Dim files As String() = Directory.GetFiles(pathOfRasterFiles, "*.tif")
Dim streamWriter As StreamWriter = Nothing
Try
streamWriter = System.IO.File.CreateText(newReferencepathFileName)
For Each file As String In files
If System.IO.File.Exists(file) Then
Dim rasterRasterLayer As New GdiPlusRasterLayer(file)
rasterRasterLayer.Open()
Dim boundingBox As New RectangleShape()
boundingBox = rasterRasterLayer.GetBoundingBox()
rasterRasterLayer.Close()
streamWriter.WriteLine(String.Format("{0},{1},{2},{3},{4}", boundingBox.UpperLeftPoint.X, boundingBox.LowerRightPoint.X, boundingBox.UpperLeftPoint.Y, boundingBox.LowerRightPoint.Y, file))
End If
Next
streamWriter.Close()
Catch ex As Exception
Finally
If streamWriter IsNot Nothing Then
streamWriter.Dispose()
End If
End Try
Else
Throw New DirectoryNotFoundException("The path containing the Raster files could not be found.")
End If
Catch ex As Exception
End Try
End Sub
Private Overloads Sub DrawCore(map As Map)
Throw New NotImplementedException
End Sub
End Class