1: Imports OSGeo.MapGuide
2: 'we still need to import and use system.xml, but don't really need to use many parts of the XML
3: 'functionality =)
4: Imports System.Xml
5: Partial Public Class _Default
6: '' 'So for this example, we're going to use the sheboygan sample package available from
7: '' ' http://mapguide.osgeo.org/download/releases/2.0.x-samples. Be sure to grab both the
8: '' ' dotnetviewstample.zip as well as the sheboygan.mgp. Import the package using
9: '' ' the mapguide site administrator. I've tried to use the default resource paths
10: '' ' but some tweaking of map will be needed
11: '' '
12: '' ' Open the map definition in Studio, and remove all the layers from Samples/Sheboygan/Maps/Sheboygan.MapDefinition
13: '' ' we're going to add them dynamically
14:
15: Inherits System.Web.UI.Page
16:
17: 'set some contants up - webconfig.ini, map viewer url, Map, Layout and Layer locatinos
18: Private Const gszWebConfig As String = "C:\inetpub\MapGuideEnterprise2009\WebServerExtensions\www\webconfig.ini"
19: Private Const gszViewerUrl As String = "http://localhost/mapguide2009/mapviewerdwf"
20: Private Const gszMapResID As String = "Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition"
21: Private Const gszLayerFolderResID As String = "Library://Samples/Sheboygan/Layers.Folder"
22: Private Const gszLayoutResID As String = "Library://Samples/Sheboygan/Layouts/SheboyganAsp.WebLayout"
23: Private Const gszMGUser As String = "Administrator"
24: Private Const gszMGPass As String = "admin"
25:
26: ''' <summary>
27: ''' Page_Load does everything =) Be sure to copy the dll files from your mapviewernet\bin folder to this projects bin folder.
28: ''' I did not include them as that might have violated some autodesk license.
29: ''' </summary>
30: ''' <param name="sender"></param>
31: ''' <param name="e"></param>
32: ''' <remarks></remarks>
33: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
34:
35: 'setup our siteconnection
36: Dim siteConnection As New MgSiteConnection
37: siteConnection = CreateMGSession(gszMGUser, gszMGPass, gszWebConfig)
38: Dim szSessionId As String = siteConnection.GetSite.CreateSession()
39:
40: 'create our connection to the resource service
41: Dim resSvc As MgResourceService
42: resSvc = siteConnection.CreateService(MgServiceType.ResourceService)
43:
44: 'get or set the resourceid of the map to load - in this case i'm just going to hard code it
45: Dim mapResourceID As New MgResourceIdentifier(gszMapResID)
46:
47: 'load the existing map from the libary into an XML document
48: Dim mapXML As XmlDocument = GetResourceXML(resSvc, mapResourceID)
49:
50: 'so at this point we have an XML document. Let's try using our new OSGeo.Mapguide.Object classes
51: Dim newMapDefinition As New OSGeo.MapGuide.Objects.MapDefinition
52:
53: 'to load the xml - call the shared/static method of MapDefinition.Parse on the OuterXML of the XMLDocument
54: newMapDefinition = OSGeo.MapGuide.Objects.MapDefinition.Parse(mapXML.OuterXml)
55:
56: 'at this point we have a loaded .NET Object containing the map. Try using Intellisense to see the different methods
57: 'Lets add a layer group now
58:
59: 'add any needed layer groups to the map. In this example we're only going to add one.