MapGuide Application Development Series (11) -- create your first MapGuide Application

Source: Internet
Author: User

In the previous article, we talked about how to use MapGuide Studio to organize maps and webpage la S, and run the first subprogram for downloading. How can we develop our own MapGuide application? What are the steps? In this article, junqilian will talk about the basic steps that should be followed when developing based on MapGuide. We take. net development as an example. If you use java or php, the process is similar.

Developing a WebGIS application based on MapGuide is actually very simple. After GIS data is made up of data sources, layers, maps, and web pages through MapGuide Studio, you have a WEBGIS application with basic functions. This WebGIS platform provided by MapGuide allows you to scale, roam, measure the distance, and create a buffer. These common GIS operations are already included, and you can build a map publishing platform without writing a code. Isn't that cool? We have introduced every step in the previous article about how to use MapGuide Studio to organize maps. I believe that you can quickly publish your data to the Web.

Below is the webpage layout I have organized in MapGuide Studio:

Click the Go button to view it in the browser. However, the address is http: // localhost/mapguide2010/mapviewerajax /? WEBLAYOUT = Library % 3a % 2f % 2 fsuzhou % 2 fWebLayouts % 2fsuzhou. webLayout & LOCALE = en is long and difficult to remember. Of course, we still want to build our own website and embed the map into our own applications. Next we will introduce how to embed Mapguide into your Aspnet website.

Before proceeding, you must first know the ResourceID of this WebLayout. You can right-click this WebLayout and select attributes to view: Library: // suzhou/WebLayouts/suzhou. WebLayout.

 

First, use Visual Studio 2008 to create a website. For convenience, we choose to create a website directly on IIS, with the location HTTP and the URL http: // localhost/Welcome.

After creating a Web site, we Add a bin directory and right-click the site-Add asp.net folder-bin, which is no different from the normal Web site development.

 

Now we need to add reference related to MapGuide. This is slightly different from general website development, but it is also simpler, we only need to copy all the dll files in the mapviewernet \ Bin directory of the MapGuide site to the bin directory of our site.

 

Here we use the basic webpage layout. Ajax Viewer and Ajax Viewer are structured based on the Frame framework. Install the following code to create the homepage and embed the MapGuide map browser into the frameset.

 

<% @ Page Language = "C #" %> <% @ Import Namespace = "OSGeo. mapGuide "%> <% MapGuideApi. mgInitializeWebTier (@ "C: \ Program Files \ Autodesk \ mapguidepolicise2010 \ WebServerExtensions \ www \ webconfig. ini "); // Create user information MgUserInformation userInfo = new MgUserInformation (" Anonymous "," "); MgSite site = new MgSite (); site. open (userInfo); string sessionId = site. createSession (); // here is the resource ID of the webpage layout string w EbLayout = "Library: // suzhou/WebLayouts/suzhou. WebLayout"; %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

 

Well, just a few simple words, we can build a WebGIS application that can be released on the Internet. Let's take a look at the effect. Our address is like http: // localhost/Welcome/Default. aspx.

Now, this WebGIS application has basic functions. Common features such as map scaling, roaming, information query, measuring distance, and creating a buffer zone are all available. It is not a problem to deal with demonstration bidding :)

Of course, for a mature GIS platform, these built-in functions are still very limited, and the customer's needs are varied. How can we expand this WebGIS platform to meet different needs of customers? This is the problem we need to solve below.

Let's start with a simple one. After you are familiar with this process, you can customize MapGuide as needed. You need to add a button on the toolbar to display the basic information of the current map. When you click this button, a URL page is displayed. First, I made changes to WebLayout and added this command.

 

Then add a WebForm in VS2008 to create this page.

For details, refer to the Code:

 

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; // Add the namespace using OSGeo of MapGuide. mapGuide; public partial class MapInformation: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {// MapGuideApi. mgInitializeWebTier (@ "C: \ Program Files \ Autodesk \ MapGuideEnterprise2010 \ WebServerExtensions \ www \ webconfi G. ini "); // obtain the Session string, that is, the session Session string generated in the Default. aspx homepage. // Here, you must use the same session string as the homepage. Do not use the method in the homepage to generate a new one. Otherwise, there will be problems. // In the same application, we should use this session string. String sessionId = Request ["SESSION"]. toString (); MgUserInformation userInfo = new MgUserInformation (sessionId); MgSiteConnection site = new MgSiteConnection (); site. open (userInfo); MgResourceService resSvc = site. createService (MgServiceType. resourceService) as MgResourceService; MgMap map = new MgMap (); map. open (resSvc, "SuzhouMap"); // SuzhouMap is the map name, which can be found in MapGuide Studio // output the coordinate system Response of the current map. write ("Current Map's SRS is: <br>" + map. mapSRS + "<br>"); // outputs the number of layers on the current map. int layerCount = map. getLayers (). count; Response. write ("maps layer count is:" + layerCount + "<br>"); // name of the output layer at a time for (int I = 0; I <layerCount; I ++) {MgLayerBase layer = map. getLayers () [I]; Response. write (layer. name + "& nbsp; options:" + layer. selectable. toString () + "<br> ");}}}

All right, it's done. Run it and check it out!

 

 

So far, we have demonstrated how to add the URL-triggering command to the MapGuide application and implement it. You can also add a javascript-triggered command to call any javascript code or Ajax Viewer API. you can add custom commands and implementations as needed.

 

If you have any comments or suggestions, you can go to the MGDN forum to discuss technical issues during MapGuide development.

For more information, see the source link and author. Daniel Du)

 

Happy MapGuiding!

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.