Page 2
PURCHASE PRICE OF THE MATERIALS DESCRIBED HEREIN. Autodesk, Inc. reserves the right to revise and improve its products as it sees fit. This publication describes the state of this product at the time of its publication, and may not reflect the product at all times in the future.
About the Autodesk MapGuide Viewer API Autodesk MapGuide Viewer API Help . Autodesk MapGuide Web Site . What Is an Autodesk MapGuide Viewer API Application . Viewing Maps . Querying and Updating Data . Creating an Autodesk MapGuide Viewer API Application .
Page 4
Map Access for the Java Edition . Map Access from HTML . Map Access Using Java . Required Software for the Java Edition . Java Edition Differences . Communicating with the Plug-In from a Java Applet . Accessing Secure Data . Handling Busy State and Map Refresh .
Page 5
Municipal Application Example Code . Facility Management Application . Facilities Management Application Example Code . DWG Filtering Application . Understanding Layers in Autodesk MapGuide . Changing Map Layer Data Source Properties . DWG Filtering Application Example Code SDF Component Toolkit Applications .
I About the Autodesk MapGuide Viewer API maps and associated attribute data over the Web. The I What is an Autodesk Autodesk MapGuide Developer’s Guide is a complete guide MapGuide Viewer API application to Autodesk MapGuide customization and development I Creating an Autodesk MapGuide Viewer API features.
What’s New in Release 6 This release of the Autodesk MapGuide Viewer API includes one new object and several new and changed methods and properties to support new and enhanced features. For detailed information about the new object, and the methods and properties that were added or changed, choose Help ➤...
Familiarity with Autodesk MapGuide You need to be very familiar with Autodesk MapGuide. In particular, you should read the first few chapters of the Autodesk MapGuide User’s Guide to make sure you understand the product, especially emphasizing the following sections: Chapter 2, “Understanding Autodesk MapGuide.”...
SDF files, Dynamic Map Authoring, and more. Use Java, JavaScript, JScript, Visual Basic, or VBScript with the Autodesk MapGuide Viewer API to develop applications that programmatically access and control Autodesk MapGuide Viewer. This document covers what you need to know to develop such applications.
Help pages. You can then set up the map to point to your customized Help system instead of the default Autodesk MapGuide Viewer Help when users click the Help button or access Help from the popup menu. For more information, refer to the Autodesk MapGuide Help.
Page 12
This two-way interaction between the map and controls on the Web page allows you to create very powerful applications. In this context, an Autodesk MapGuide Viewer application is a Web page containing one or more maps, each of which is displayed in a separate instance of the Autodesk MapGuide Viewer.
The site provides many examples of applications developed with Autodesk MapGuide, both demo applications and real customer sites. You will also find links to resources, such as Autodesk MapGuide Viewer API Help, API exam- ples, general product documentation, and discussion groups.
You can do this by embedding a map in an HTML page, in which case the Autodesk MapGuide Viewer runs within the user’s Web browser to display the map, or you can run the Autodesk MapGuide Viewer from within a stand-alone application that you create.
Creating an Autodesk MapGuide Viewer API Application The following table summarizes tasks involved when creating an Autodesk MapGuide Viewer API application. For examples of real-world applications, also see Chapter 7, “Applications.” Application Type Task For more information... Simple Display maps by either See Chapter 2, “Displaying...
I Overview This chapter describes how to link to or embed a map in I Map display for ActiveX ® a Web page for display in Autodesk MapGuide Viewer Control and Plug-In I Map display for the Java ActiveX Control, Autodesk MapGuide Viewer Plug-In, or...
(Autodesk MapGuide Viewer ActiveX Control, Autodesk MapGuide Viewer Plug-In, or Autodesk MapGuide Viewer, Java Edition), depending on which ones you support. If your users are unable to download or install an Autodesk MapGuide Viewer, or if they do not need query or more advanced function- ality provided by Autodesk MapGuide Viewers, they can use Autodesk ®...
Page 19
Browser/Viewer Configurations Operating Browser Client-Side Programming System Viewer or Scripting Language Windows Internet Explorer Autodesk HTML, VBScript, MapGuide Viewer JScript, JavaScript ActiveX Control Autodesk HTML, JScript, MapGuide Viewer, JavaScript, Java Java Edition Netscape Autodesk HTML, JavaScript Navigator MapGuide Viewer Plug-In...
Create the link just like any other link in HTML, using the <A> tag with the HREF parameter. Set the HREF value to the URL of your Autodesk MapGuide Server, along with the maps directory alias and the MWF file for the map: <A HREF="http://www.yourserver.com/maps/usa.mwf">United States...
Page 21
The TARGET parameter can also specify the name of a frame. Displaying a Specific Area of the Map In an Autodesk MapGuide Viewer, you can adjust the view of the map window so that it displays only the area you want.
HTML page, choose Help ➤ Contents ➤ Advanced Topics ➤ URL Parameters in the Autodesk MapGuide Viewer Help. Be sure that the values you use are the same for both the OBJECT and EMBED parameters.
Page 23
To see an example of a map within a simple frame-based HTML page, choose Help ➤ Contents ➤ Examples Basic ➤ Simple Frameset example in the Autodesk MapGuide Viewer API Help. The following is an example of an HTML page for frame set layout: <HTML>...
Web browser). For information about applet wrappers, see “Map Access Using Java” on page 38. If you are using Autodesk MapGuide Viewer, Java Edition, you cannot link to a map. Instead, you must embed the map in the HTML page. To do this, use the <APPLET>...
Page 25
Autodesk MapGuide Viewer, Java Edition. Setting the CODE parameter to MGApplet instantiates Autodesk MapGuide Viewer, Java Edition. 3 Set the VALUE parameter to the URL of your Autodesk MapGuide Server and the path to the MWF file for the map. For example: <HTML>...
Web browsers from your Web page. It is not a type of Autodesk MapGuide Viewer. Autodesk MapGuide LiteView is useful when users need only to display the map and do not need the more advanced queries and other functionality of Autodesk MapGuide Viewer.
Installing Viewers on Client Machines If users accessing your Web site don’t have an Autodesk MapGuide Viewer installed on their system, they need to download one in order to view the map you have displayed in the Web page. You can include code in your...
Page 28
To install the Autodesk MapGuide Viewer Plug-In 1 To install the latest version of Autodesk MapGuide Viewer Plug-In for Netscape Navigator users, write additional code to prompt the user to download Autodesk MapGuide Viewer Plug-In, as follows: To download Autodesk MapGuide Viewer Plug-In...
Page 29
<PARAM NAME="Installer" VALUE="http://www.autodesk.com/mapguideviewerdownload"> </APPLET> If Autodesk MapGuide Viewer, Java Edition is not found, the user is given the option to download it from the Autodesk MapGuide download page. For this code to work, the CheckInstall.class file must reside in the same directory as the Web page that contains this code.
Accessing Maps I Overview This chapter describes how to programmatically access I Map Access for ActiveX maps you have embedded in a Web page. Once your Control and Plug-In I Map Access for the Java application can access a map, you can begin to expand Edition I Communicating with the your application to work with map layers, map features,...
Autodesk MapGuide Viewer API. Once you’ve obtained the map object, your application code uses that instance when it calls methods in the Autodesk MapGuide Viewer API. In most cases, the code for either browser will be identical.
Page 33
= getMap(); You can then apply methods to that variable to work with the map. For example, the following function displays an Autodesk MapGuide report called Parcel Data: function runReport() var jb_map = getMap();...
Warning Because Netscape Communicator 4.x contains the Same Origin secu- rity policy, the map object cannot be accessed by the Autodesk MapGuide Viewer API code in a different frame. This occurs only when the code is written in Java or JavaScript and is on a different domain from the one where the map window file (MWF) resides.
Using JavaScript or JScript The JavaScript or JScript techniques for accessing maps described in “Map Access for ActiveX Control and Plug-In” on page 32 also work for Autodesk MapGuide Viewer, Java Edition since the object hierarchy is determined by the browser, not by the version of the Autodesk MapGuide Viewer.
Page 36
MGMap methods. If you need to use any of these methods, implement Autodesk MapGuide Viewer, Java Edition from Java instead of JavaScript or JScript:...
Page 37
If you need more interactivity with the map, you will need to use Java instead, as described below. This is particularly important if you need to support Macintosh users, as they will need to use the Autodesk MapGuide Viewer, Java Edition with Internet Explorer, which doesn’t have full JScript support.
Example6 in the Autodesk MapGuide Viewer API Help. Peer Java Applet You can write a peer Java applet that runs Autodesk MapGuide Viewer, Java Edition. This approach is slightly simpler than driving Autodesk MapGuide Viewer, Java Edition from a wrapper applet, because, with a peer java applet, Autodesk MapGuide Viewer, Java Edition is automatically provided with browser services such as showDocument.
Required Software for the Java Edition To work with Autodesk MapGuide Viewer, Java Edition, you may need to download certain Java files provided with Autodesk MapGuide. Specifically, you will need to access the Autodesk MapGuide Viewer, Java Edition API, which resides in the com.autodesk.mgjava package. You can find this package in the mgjava.jar archive file, which contains all Autodesk MapGuide Viewer,...
/home/username/.autodesk/mapguide/6.0 Browser Differences with Java Edition If a user with Internet Explorer requests data beyond a firewall, Autodesk MapGuide Viewer, Java Edition fails unless the browser has already been through proxy authorization. A simple workaround for this is to set the browser’s home page to a site outside the firewall.
Page 41
MAYSCRIPT> </APPLET> 4 If you have not already done so, embed Autodesk MapGuide Viewer Plug- In in the HTML page as shown in the following example (for more infor- mation, see “Embedding a Map,” on page 22). Use the following code: <EMBED...
Page 42
For instance: Public void getViewerInfo() myUSAMap.aboutDlg(); The API is available from Autodesk MapGuide classes in the npmapv32.zip file you copied in Step 1. Calling JavaScript Functions from a Java Applet You can call JavaScript functions in your HTML page from a Java applet.
Write a Java applet that makes a request for the passkey to your Autodesk MapGuide Server and then returns the passkey to the script in the Web page.
Page 44
To avoid errors, you need to make sure that Autodesk MapGuide Viewer is not in a busy state when your application calls one of the methods that are affected by the busy state.
Controlling Map Refresh Operations You can ensure that Autodesk MapGuide Viewer will not enter a busy state by controlling when display refreshes occur. The first step is to remember that display refreshes always occur in the following instances: When the autoRefresh flag is set to True with MGMap.setAutoRefresh, and the application calls an API method that requires an automatic refresh such as MGMap.zoomSelected.
Page 46
You can write event-handling code in your application to respond to these events (see Chapter 5, “Handling Events”). However, before the Autodesk MapGuide Viewer fires these events, it disables the autoRefresh flag. When writing your event-handling code for onViewChanging, be sure to avoid methods that don’t work when the...
Viewer API has error tracking methods and properties you can use to debug your applications. Getting Error Codes Every time an API method is run or a property is accessed, Autodesk MapGuide updates the MGError object. This object contains error informa- tion for the most recently executed method or property.
MGMap.enableApiExceptions and MGMap.disableApiExceptions methods to throw or not throw exceptions. When exceptions are enabled and the MGError code is set to a non-zero value, Autodesk MapGuide throws an exception. Depending on your development environment, the exception will halt your code and send an error message containing the line number of the error to the screen.
Map Features, and Printing I Overview This chapter shows you how to write code for common I Working with map layers tasks your application can perform with the Autodesk I Working with map features ® I Working with printing MapGuide Viewer API.
Autodesk MapGuide Viewer API. Also note that although spatial data on the map consists of map features, the methods and properties in the Autodesk MapGuide Viewer API that work with map features use the term object instead of feature. This difference in terminology exists because map features were called map objects in previous releases of Autodesk MapGuide.
Next, the countLayers function calls the getMapLayersEx method, an Autodesk MapGuide Viewer API method that returns an MGCollection object containing all the layers defined in the map. The layer collection is assigned to the layers variable: var layers = map.getMapLayersEx();...
Page 52
Next, the listLayers function uses a for loop to cycle through the layer collection, placing all the layer names in the single msg variable: var msg; // empty variable to hold layer names var i; // counter variable; used by loop for (i = 0;...
Using Autodesk MapGuide Author, you can set map layer attribute properties for specific display ranges. (Refer to “Setting Style Properties for Layers” in the Autodesk MapGuide User’s Guide.) For example, you might set a layer to be invisible when a user zooms out. Using the Autodesk MapGuide Viewer API, you can extend this functionality by linking layers to one or more designated control layers.
Page 54
The function is named onViewChanging because it’s triggered by the Autodesk MapGuide Viewer API event of the same name. Whenever an event is triggered, Autodesk MapGuide Viewer checks for a function whose name matches the event name. If the function is found, Autodesk MapGuide Viewer invokes it, passing arguments that vary by event.
Toggling Map Layer Visibility On and Off The layerToggle function toggles the visibility of a map layer that is spec- ified when the function is invoked: function layerToggle(l_name) var map = getMap(); var layer = map.getMapLayer(l_name); if (layer == null) alert("layer not found.");...
Working with Map Features This section describes common tasks your application can perform with Autodesk MapGuide map features. Getting Keys of Selected Map Features In this example, the doGetKey function displays a dialog box showing the keys of selected map features (keys are unique values that are used to identify individual map features).
Page 57
Next, the doGetKey function calls the getMapObjectsEx method and passes its return value (a collection of the selected map features) to a variable called objs. Note that if you use getMapObjectsEx with a map layer, it returns an MGCollection object made up of map features of a map layer, but by using the method with the selection object, and by passing it null as a parameter, it returns the map features in the current selection only: var objs = sel.getMapObjectsEx(null);...
The following screen shows keys of the selected features displayed in the alert box. alert box displaying keys of selected features Getting Coordinates of a Selected Map Feature The doGetCoordinates function displays a dialog box showing the coordi- nates of a selected map feature: doGet Coordinates Function function doGetCoordinates() var map = getMap();...
Page 59
doGet Coordinates Function var cntVertices = map.createObject("MGCollection"); var res = obj.getVertices(vertices, cntVertices); if (res == 0) alert("No access to coordinate information."); return; msg = "Parcel:" + obj.getKey() + "\n"; msg = msg + "Coordinates in MCS unit\n"; for(var i = 0; i < cntVertices.item(0); i++) var pnt = vertices.item(i);...
Page 60
Otherwise, the function creates some more variables. The obj variable contains the first (and only) object in the current selection. The vertices and cntVertices variables hold empty MGCollection objects: var obj = sel.getMapObjectsEx(layer).item(0); var vertices = map.createObject("MGCollection"); var cntVertices = map.createObject("MGCollection"); Then doGetCoordinates uses the getVertices method to get the coordi- nates and number of vertices of obj, our selected parcel feature.
Next, zoomSelect uses the size method to see how many features are selected. If one or more features are selected, the zoomSelected method is invoked, causing Autodesk MapGuide Viewer to zoom to those features, as shown in the illustrations following the example. Otherwise, an alert displays: if (selected.size() >...
Before calling zoomSelected() After calling zoomSelected() Counting Map Features The showFeatureCount function counts the features on each map layer and adds that count to the legend: var legendSet; // Global variable, declared outside of function function showFeatureCount() if (legendSet) return; var map = getMap();...
Page 63
The showFeatureCount function starts by checking the status of the global variable, legendSet. If legendSet is set to True, showFeatureCount terminates: if (legendSet) return; This keeps showFeatureCount from printing multiple messages to the legend if the user clicks the button more than once. Next, showFeatureCount creates an instance of the map and checks to see if the map is in a busy state (see “Handling Busy State and Map Refresh”...
The first event, onBeginLayout, is fired after a user clicks OK in the Print dialog box but before Autodesk MapGuide Viewer lays out the page elements that will be sent to the printer. The second event, onEndLayout, is called after Autodesk MapGuide Viewer lays out the page elements but before the elements are sent to the printer.
Setting the Print Priority As shown above, you can write an onEndLayout event handler that uses MGPrintLayout, MGPageElement, and MGExtentEx to control the place- ment of printed page elements. It is possible, and sometimes desirable, to place page elements on top of each other. For example, you might want to place the North arrow on top of an empty spot of ocean in your map.
For Autodesk MapGuide Viewer Plug- In and Autodesk MapGuide Viewer, Java Edition, you will also need to use the setPrintingObserver method to specify the event observer. Here is one way to write a JavaScript function that enables print events: function enable_print_events() var map = getMap();...
Positioning Page Elements with Page Coordinate System Units Page element extents specified through the API are expressed in Page Coor- dinate System (PCS) units. The origin (0,0) of this system is located at the upper-left corner of the paper. Its exact location depends on the current left and top margins.
Author. Refer to the topics “Adding Symbols for Use with the Viewer API” and “API Symbol Manager dialog box” in the Autodesk MapGuide Help for more information. The following example shows an onEndLayout event handler, written in JavaScript, that adds a custom logo to the top left corner of the printout. Note °...
Once your application can han- dle Autodesk MapGuide Viewer events, you may want to add data query and update capabilities, as described in Chapter 6, “Using Reports to Query and Update Data...
Overview Just as the Web browser has events that are triggered in response to actions within the browser, Autodesk MapGuide has its own events that are triggered by actions within Autodesk MapGuide Viewer. For example, if the user selects a feature on the map, the onSelectionChanged event is triggered.
MapGuideObserver6J.class You can use the same instance of the observer applet for all events. To call an Autodesk MapGuide method Internet Explorer knows how to find the that triggers an event, you pass the event handler without being passed its...
If your application is supporting both Autodesk MapGuide Viewer Plug-In and Autodesk MapGuide Viewer, Java Edition, you need to detect which Autodesk MapGuide Viewer is present on the client’s system. You can do this by embedding a detection applet provided by Autodesk MapGuide. This applet is included in an archive file called MGDetectClass.zip.
Page 73
(Autodesk MapGuide Viewer Plug-In or Autodesk MapGuide Viewer, Java Edition) is running on the client machine. 3 Once you have detected which Autodesk MapGuide Viewer is running on a client machine, invoke the event observer applet by calling a set observer method like setSelectionChangedObserver or a method that invokes an event, such as digitizePolylineEx.
Page 74
(navigator.appName() == "Netscape") getMap().setSelectionChangedObserver(document.obsJava); function onSelectionChanged(map) alert("Selection Changed"); // Autodesk MapGuide Viewer, Java Edition was not // installed so we check to see if the browser is Netscape else if (navigator.appName() == "Netscape") // The browser is Netscape, so we embed the // Autodesk MapGuide Viewer Plug-In Observer Applet document.write("<Java Applet CODE=\"MapGuideObserver6.class\"...
ActiveX Control Event Handlers You can handle events from the Autodesk MapGuide Viewer ActiveX Control within Microsoft Internet Explorer by defining VBScript functions. Define VBScript functions in the HTML file where the <OBJECT> tag resides. Define a function for each of the events that you want to handle. Function names must begin with the name of the MGMap object, followed by an under- score (_), followed by the event name and parameter list.
Page 76
(a browser event) calls a function you created, DigitizeIt. The DigitizeIt function calls the digitizePoint method, an Autodesk MapGuide Viewer API method that waits for the user to click a point on the map and then captures that point. For Netscape Navigator, the digitizePoint method requires an event observer as a parameter, whereas Internet Explorer does not.
Page 77
MGMap, providing the Autodesk MapGuide Viewer Plug-In and its observer applet with the observer object that handles selection changed events. Finally, the map_onSelectionChanged function is implemented to handle the event in JavaScript.
</SCRIPT> Writing Event Handlers To make an Autodesk MapGuide observer work properly, always give your event handler the same name as the event it is handling. When the event is fired, the code in the corresponding observer is executed automatically. This section describes how to write JavaScript and Java event handlers for the onBeginLayout and onEndLayout events.
Page Setup Event Handler Example If you want your application to control settings from the Autodesk MapGuide Viewer Page Setup dialog box, you can write event handling code that responds to the onBeginLayout event. When onBeginLayout is trig- gered, it automatically passes two objects, the MGPageSetup and...
Page 80
3 Write the event handler. It goes in the HTML page (or the JavaScript .js file), just like any other JavaScript function. This function is executed automatically every time the onBeginLayout event fires. Note that the function takes an MGPageSetup object and an MGPrintInfo object as its parameters: function onBeginLayout (pgSetup, info) if (map_only == "true")
Print Event Handler Example If you want your application to change the title font, you can add a custom symbol, or control the position and size of any page element. To do this, you need to write event handling code that responds to the onEndLayout event. When onEndLayout is triggered, it automatically passes two objects, MGPrintLayout and MGPrintInfo objects: void onEndLayout (MGPrintLayout prLayout, MGPrintInfo info)
Page 82
3 Write the event handler. It goes in the HTML page (or the JavaScript .js file), just like any other JavaScript function. This function is executed automatically every time the onEndLayout event fires. Note that the function takes an MGPrintLayout object and an MGPrintInfo object as its parameters: function onEndLayout (layout, info) if (new_symbol == "true")
Plug-In Event Handler Example To handle events in an applet for the Autodesk MapGuide Viewer Plug-In, you need to implement the corresponding Autodesk MapGuide Viewer event handler interfaces in your applet. To implement event handler interfaces 1 Implement the interface of the event that you want to handle in your applet.
I Creating report scripts with information associated with a map. This chapter explains ColdFusion I Creating report scripts with how Autodesk MapGuide generates reports and shows you how to create report scripts using two popular server- ® ® side technologies, Macromedia ColdFusion ®...
How Reports Are Generated The role of Autodesk MapGuide in generating reports is to construct a URL dynamically and send it as an HTTP request to a Web server. This URL is composed of a path to an application on the Web server along with a set of parameters.
URL as characters. However, if you specify another data type for the key col- umn, Autodesk MapGuide will send the keys as that type instead. You set the key column type by selecting it from the Type list box on the Data Sources tab of the Map Layer Properties dialog box in Autodesk MapGuide Author.
Perl scripts or Visual Basic/C++ DLLs, and because these products are by far the most common platforms for Autodesk MapGuide server-side application develop- ment. ColdFusion is available from Macromedia, and ASP is included as part of Windows 2000 and Windows NT Server 4.0 with the Windows NT 4.0...
This example shows a simple template that lists the contents of a map resource database. Note that this template accesses the database directly, instead of using the Autodesk MapGuide reporting feature. Later, we’ll see how Autodesk MapGuide fits into the picture.
Page 90
Setting Up the Query First we’ll build the <CFQUERY> statement. If your map links to a table called Parcel_Data through a data source Assessor, <CFQUERY> will look like this: <CFQUERY NAME="get_parcel_info" DATASOURCE="Assessor"> SELECT * FROM Parcel_Data </CFQUERY> The NAME attribute specifies the name of the ColdFusion query. This name can be anything you want, as long as it matches the name specified later in <CFOUTPUT>.
Page 91
</HTML> The following shows the page as it appears in a browser. The HTML output In this example, the database happens to be an Autodesk MapGuide resource, ® but it could be anything: a Microsoft Access database listing employees and ®...
In most cases, you’ll want to access your database resources through Autodesk MapGuide Viewer, by linking them to features and layers in the map. The next two examples show you how to do this. Querying and Displaying Data via the Map with ColdFusion Now that we’ve seen how ColdFusion works, let’s use it with Autodesk...
Page 93
We’ve selected the Autodesk MapGuide Author default, OBJ_KEYS. When a user selects one or more features from the Assessment layer and runs the Parcel Data (CF) report, Autodesk MapGuide constructs a URL that invokes parcel_report.cfm and tells it to generate a report on the selected features, which are identified by their OBJ_KEY values.
Page 94
Creating the Report Script Now let’s create the ColdFusion template that will process the Autodesk MapGuide report. The following code listing is for the parcel_report.cfm file: <HTML> <HEAD><TITLE>ColdFusion Report Data</TITLE></HEAD> <BODY> ColdFusion-- ColdFusion query --> <CFQUERY DATASOURCE="assessor" NAME="get_parcel_info"> SELECT * FROM Parcel_Data Where APN IN (#PreserveSingleQuotes(OBJ_KEYS)#) </CFQUERY>...
Page 95
The last step is to create an HTML page to display our map. The following is for the parcel_map.htm file: <HTML> <HEAD><TITLE>ColdFusion Example</TITLE></HEAD> <BODY> <H1>Querying and Displaying Data via the Map</H1> <P>This example uses <b>ColdFusion</b> to access an Autodesk MapGuide Report</P> <!-- embedded map --> <OBJECT ID="map" WIDTH=600 HEIGHT=250 CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME="URL"...
Page 96
Go back to the parcel_map.htm file and modify the embedded map code: <OBJECT ID="map" width=600 height=250 CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME="URL" VALUE="http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self> <EMBED src="http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self NAME="map"WIDTH=600 HEIGHT=250> </OBJECT> Notice that we’ve added a Autodesk MapGuide Viewer URL parameter to the map reference: http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self Chapter 6 Using Reports to Query and Update Data Sources...
Page 97
ReportTarget specifies the window or frame in which you’d like your report to display. By specifying _self, we redirect the report output so that it displays in the current window. Displaying the parcel data report in the current window At first glance this appears to be a good solution, but it has some problems. Users might get confused about where they are.
Page 98
Start by creating a standard HTML file that defines a frameset. The frameset should display the map on the left and a blank page on the right: <HTML> <HEAD> <TITLE>ColdFusion Report Data</TITLE> </HEAD> <!-- frames --> <FRAMESET COLS="65%,*"> <FRAME NAME="Left" SRC="parcel_map.htm" MARGINWIDTH="10" MARGINHEIGHT="10"...
Page 99
The following illustration shows the map and the report in two frames of the same window. Displaying the map and report in frames Users can now invoke as many reports as they want, without losing their place in the map or calling a new instance of the browser. Creating Report Scripts with ColdFusion...
Page 100
Adding a Button with the Viewer API An Autodesk MapGuide report is generated by right-clicking the map and then choosing View ➤ Reports from the popup menu. This interface is not immediately apparent to users, so we’ll make it easier by creating a Parcel Report button that will display the report.
Page 101
Data (CF)'); </SCRIPT> </HEAD> <BODY> <H1>Querying and Displaying Data via the Map</H1> <P>This example uses <b>ColdFusion</b> to access an Autodesk MapGuide Report</P> <!-- embedded map --> <OBJECT ID="map" WIDTH=600 HEIGHT=250 CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME="URL"...
MapGuide, display a form that takes additional user input, and add the point data to a database on the server. An Autodesk MapGuide report (and later, a custom menu item) that passes digitized point coordinates to the getpoint.cfm file. Chapter 6 Using Reports to Query and Update Data Sources...
Page 103
Dialog box specifications for Incidents (CF) report Here are descriptions of how we used the options on the Reports tab: Report—Specifies the name of the report as it appears in the Autodesk MapGuide Viewer. Our report is named Incidents (CF).
Page 104
When a user runs the Incidents (CF) report, Autodesk MapGuide prompts the user to specify a point. Then it invokes getpoint.cfm, passing the point’s lat/lon coordinates as URL parameters. For example, if the user specified a point with coordinate values of 37.721,-121.943, the URL would be: http://www.yourserver.com/getpoint.cfm?LAT=37.721&LON=-121.943...
Page 105
The next line creates a new browser window, using the loc variable to supply the URL. The last line shifts browser focus to the new window we just created. Now, let’s look at the second CFM file, the showform.cfm file: <HTML>...
Page 106
The following illustration shows the showform.cfm form, as displayed in the window created by getpoint.cfm. Data entered in the showform.cfm form Specifying the lat/lon point 37.721,-121.943 by clicking the map and filling out the form as shown in the illustration will result in the following URL being constructed and passed to the insert.cfm file: insert.cfm?rpt_lat=37.721&rpt_lon=- 121.943&rpt_info=A+hat+was+stolen&rpt_by=J+Bigby...
Page 107
The <CFQUERY> element contains a single SQL Insert statement, which is used to add the form data to the map resource database. The SQL Insert statement adds data to a database resource, in this case the Inci- dents table in the assessor DSN. The parenthetical values lat, lon, description, and reported_by are the names of the database fields we want to supply values for.
Page 108
Popup Menu list. Name— Specifies the name of the menu item as it will appear in the Autodesk MapGuide Viewer. Our menu item is named Incident Log. Action— Specifies the task to be performed by the menu item. We selected GetPointAndSendToURL from the drop-down list.
To solve this problem and to avoid the need for the user to reload the map manually, you can use the Autodesk MapGuide Viewer API to access the Inci- dent Log application. Instead of creating a report or custom menu item, add a button or other interface element to the HTML page hosting the map (or to a frame or child window with access to that page).
Summary of ASP Objects, Components, and Events The following tables summarize and describe objects, components, and events you use to create a report script with ASP. Note You can also create your own custom ActiveX Control components for ASP. Objects Used to Create a Report Script Object Description Application...
This example shows a simple server page that lists the contents of a map- resource database. Note that this page accesses the database directly, instead of using the Autodesk MapGuide reporting feature. Later, we’ll see how Autodesk MapGuide fits into the picture.
Page 112
Specifying a Scripting Language ASP scripts are written in VBScript, a lightweight Visual Basic-like scripting language, or in JScript, the Microsoft version of JavaScript. ASP files should begin with a line telling ASP which language you’re using (although a default of VBScript is assumed if the line is omitted).
Page 113
The third line creates a variable that holds a SQL statement specifying the database records for houses built in 1963: SQLQuery = "SELECT * FROM Parcel_Data Where Year_Built = '1963'" The last line puts it all together, creating a Recordset object and assigning it to an object variable named RS.
Page 114
This is a good start, but not quite what we want. To cycle through the records, we’ll need to add some sort of looping code. That’s what the two scripts are for. The beginning script contains a single line, which operates on the RS object. RS.EOF represents RS object’s end-of-file property.
The examples that follow show you how to do this. Querying and Displaying Data via the Map with Now that we’ve seen how ASP works, let’s use it with Autodesk MapGuide. This example uses the StarterApp.mwf file from the Autodesk MapGuide Web site.
Page 116
Dialog box specifications for Parcel Data (ASP) Here are descriptions of how we used the options on the Reports tab: Report—Specifies the name of the report as it appears in the Autodesk MapGuide Viewer. Our report is named Parcel Data (ASP).
Page 117
HTML form element. As we’ll see in the next section, ASP processes it accordingly. Creating the Report Script Now let’s create the ASP file that will process the Autodesk MapGuide report. The following code listing is for the parcel_report.asp file: <HTML>...
Page 118
URL. Form is a collection representing the URL parameters, which can be accessed from the collection by name. In this case, the collection has only one member, the OBJ_KEYS parameter we specified in Autodesk MapGuide Author. The SQL statement is basically saying to select in Parcel_Data all records whose APN field matches OBJ_KEYS.
Page 119
Seeing the Results We’re ready to view parcel_map.htm in our Web browser, as shown in the following illustration. Now, users can generate a report on one or more map features by selecting the features, right-clicking and selecting View ➤ Reports from the popup menu, and then selecting Parcel Data (ASP).
Page 120
VALUE="http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self> <EMBED src="http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self NAME="map"WIDTH=600 HEIGHT=250> </OBJECT> Notice that we’ve added a Autodesk MapGuide Viewer URL parameter to the map reference: http://www.yourserver.com/maps/StarterApp.mwf?ReportTarget=_self ReportTarget specifies the window or frame in which you’d like your report to display. By specifying _self, we redirect the report output so that it displays in the current window.
Page 121
At first glance this appears to be a good solution, but it has some problems. Users might get confused about where they are. Worse yet, when they click the Back button, they will find that the map has been reloaded and the loca- tion they zoomed to has been lost.
Page 122
Displaying the map and report in frames Adding a Button with the Viewer API An Autodesk MapGuide report is generated by right-clicking the map and then choosing View ➤ Reports from the popup menu. We’ll create a Parcel Report button that will display the report.
Page 123
The second statement uses the viewReport method to run our report and begins by calling getMap, which returns the appropriate map feature. That feature is then passed to viewReport, which directs Autodesk MapGuide to display Parcel Data (ASP). Now that our function is defined, to call it we’ll add a <FORM> element to parcel_map.htm:...
Page 124
Data (ASP)'); </SCRIPT> </HEAD> <BODY> <H1>Querying and Displaying Data via the Map</H1> <P>This example uses <b>ASP</b> to access an Autodesk MapGuide Report</P> <!-- embedded map --> <OBJECT ID="map" WIDTH=600 HEIGHT=250 CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME="URL"...
MapGuide, display a form that takes additional user input, and add the point data to a database on the server. An Autodesk MapGuide report (and later, a custom menu item) that passes digitized point coordinates to the getpoint.asp file. An HTML page to host the map (except for minor text changes, this page will be identical to parcel_map.htm from the previous example).
Page 126
Dialog box specifications for Incidents (ASP) report The following show how we used the options on the Reports tab: Report—Specifies the name of the report as it appears in the Autodesk MapGuide Viewer. Our report is named Incidents (ASP). URL —Specifies the name and location of the report script, in this case getpoint.asp on www.yourserver.com.
Page 127
In this case, the collection has two members: the LAT and LON parameters that were posted to the file by the Autodesk MapGuide Viewer. After the ASP code is processed, a line similar to the following is sent to the browser: var loc = "showform.asp?LAT="...
Page 128
The effect of this line is to create a variable called loc and to assign it the value showform.asp?LAT=37.721&LON=-121.943. The next line creates a new browser window, using the loc variable to supply the URL. The last line shifts browser focus to the new window we just created. Now, let’s look at the second ASP file, the showform.asp file: <HTML>...
Page 129
In short, an HTML form collects data from the user and sends that data to a program in the form of a URL. The form in showform.asp calls yet another ASP file, insert.asp, passing it the following parameters: The latitude value obtained from the ASP variable <%=Request.QueryString("lat")%>;...
Page 130
Specifying the lat/lon point 37.721,-121.943 by clicking the map and filling out the form as shown in the illustration will result in the following URL being constructed and passed to the insert.asp file: insert.asp?rpt_lat=37.721&rpt_lon=- 121.943&rpt_info=A+cat+was+stolen&rpt_by=J+Appell Now we’ll see how insert.asp handles the URL: <% Set dbConnection = Server.CreateObject("ADODB.Connection") dbConnection.Open("assessor")
Page 131
Note If a user enters an apostrophe (like the one found in can’t, won’t, and doesn’t) into the showform.asp form, it will cause a syntax error when ASP tries to execute the SQL statement. To avoid this, add code to replace a single apostro- phe with two apostrophes as follows: Change Request.Form("rpt_info") to Replace(Request.Form("rpt_info"),"'","''").
Page 132
Popup Menu list. Name— Specifies the name of the menu item as it will appear in the Autodesk MapGuide Viewer. Our menu item is named Incident Log. Action— Specifies the task to be performed by the menu item. We selected GetPointAndSendToURL from the drop-down list.
Page 133
To solve this problem and to avoid having the need for the user to reload the map manually, you can use the Autodesk MapGuide Viewer API to access the Incident Log application. Instead of creating a report or custom menu item, add a button or other interface element to the HTML page hosting the map (or to a frame or child window with programmatic access to that page).
Applications I Overview This chapter demonstrates various features of the I Custom redlining ® Autodesk MapGuide Viewer API by describing and application I Municipal application including source code for several applications. I Facility management application I DWG filtering application I SDF Component Toolkit...
Redlining applications allow a user to add annotations to a drawing or map without using the original authoring application or modifying the original document. You can use the Autodesk MapGuide Viewer API to create a custom redlining application that allows users to mark up a map using the Autodesk MapGuide Viewer.
4 Use the MGMap.saveMWF method to save the map file to an MWF on the user’s machine or a network server. MGMap.saveMWF is not available for Autodesk MapGuide Viewer, Java Edition. Note For information about adding and deleting features from the data source itself (such as an SDF file), rather than saving changes to an MWF, see “SDF Com-...
Page 138
The Add/Update Polygon button calls a JavaScript function that lets the user draw a polygon by digitizing points on the map. The function first checks to see if there’s a value in the Polygon Name check box. If there is a value, the function calls either the digitizePolygon or digitizePolygonEx method.
Page 139
To learn more about these topics, refer to the following sections in the Autodesk MapGuide Viewer API Help: For information about creating primitives, look up the MGMapObject add methods (addCirclePrimitive, addPolygonPrimitive, and so on).
Municipal Application This Municipal Application demonstrates how you can monitor the water and sewer systems of a city. In the event of water distribution system prob- lems, the application can notify the user, or a user can add an incident to the map and generate reports.
To view the source code for the other frames in this application, go to the application online at www.autodesk.com/mapguidedemo. Municipal Application Example Code <HTML>...
Page 142
Municipal Application Example Code (continued) // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // Function: notify() // Description: Turns on Incident Monitor by calling // CreateInWindow() function, below // Arguments: none // Returns: nothing // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // function notify() // Call function CreateInWindow(); // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // Function: CreateInWindow() // Description: Calls a ColdFusion file and generates the // resulting incident report in a new window (called by 'On'...
Page 143
// Tell the Autodesk MapGuide Viewer to rebuild layer // when map is refreshed; then refresh map mapLayer1.setRebuild(true); map.refresh(); // If Autodesk MapGuide Viewer is busy, don't do the stuff above; // instead, display alert else alert("The Autodesk MapGuide Viewer is busy. Please try again in a few seconds.");...
Page 144
(i=2; i<20; i++;) mapLayer[i].setVisibility(false); // ...otherwise, make the following layers visible else for (i=2; i<20; i++;) mapLayer[i].setVisibility(true); // Tell the Autodesk MapGuide Viewer to rebuild the following layers // when the map is refreshed for (i=2; i<20; i++;) mapLayer[i].setRebuild(true); Chapter 7 Applications...
Page 145
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // function raster(type) map = getMap(); // Get instance of MGMap // If Autodesk MapGuide Viewer is not busy get current map scale, then assign // "San Rafael" layer to mapRastLayer variable... if (map.isBusy() == false) var CurrentScale = map.getScale();...
Page 146
(browserId == 1) // Get instance of MGMap, assign to map variable map = parent.main.document.embeds[0]; // If Autodesk MapGuide Viewer is not busy, call digitizePoint() method; // otherwise display alert (because digitizePoint() fires // the onDigitizedPoint event, we must pass the observer // as a function argument) if (map.isBusy() == false)
Page 147
// If Autodesk MapGuide Viewer is busy, don't do the stuff above; // instead, display alert else alert("The Autodesk MapGuide Viewer is busy. Please try again in a few seconds.");...
Page 148
Autodesk MapGuide Viewer API. Please \n download the latest Autodesk MapGuide Viewer from the Autodesk MapGuide\n Web site (www.autodesk.com/mapguideviewerdownload)."); // If user has recent copy of Autodesk MapGuide Viewer (API version 6.0 // or greater)... else // Assign array of possible drop-down list options // to selValue variable;...
Page 149
Municipal Application Example Code (continued) if (temp == 'showAll') var whereClause1 = "Status is not null"; // If user selected any other drop-down item, assign // whereClause1 the string "Status=" plus the list item name // (i.e., "Status='New'" or "Status='Old'") else var whereClause1 = "Status='"...
Page 150
// Returns: nothing // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // function pageSetup() map = getMap(); // Get instance of MGMap // If Autodesk MapGuide Viewer is not busy, display Page Setup dialog; // otherwise display alert if (map.isBusy() == false) map.pageSetupDlg(); else alert("The Autodesk MapGuide Viewer is busy. Please try again in a few seconds.");...
Page 151
// If Autodesk MapGuide Viewer is not busy, display Print dialog; // otherwise display alert if (map.isBusy() == false) map.printDlg(); else alert("The Autodesk MapGuide Viewer is busy. Please try again in a few seconds."); //--> </SCRIPT> <-! Rest of page is straight HTML, with the exception of FORM elements that call the JavaScript functions defined above.
Facility Management Application The Facility Management application demonstrates how you can create a Web-based facility management application to manage and maintain various facilities. Its layout is similar to the Municipal Application, but it has more advanced navigation controls at the right of the window. It also allows you to select features in various ways, generate reports, and even search for an employee and update his or her information.
To view the source code for the other frames in this application, go to the Demos and Customers section of the Autodesk MapGuide Web site at www.autodesk.com/mapguidedemo, click Interactive Demos, and then click the Facility Management application.
Page 158
Facilities Management Application Example Code (continued) else map = null; // none if other browser return map; //return map object // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // // Function: Pan(direction) // Description: pans in the specified direction // Arguments: direction // Return: nothing // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // function Pan(direction) // Get MGMap object var map = getMap();...
Page 159
Facilities Management Application Example Code (continued) xyPt.setY(xyPt.getY() + delta) if (direction == 'Ur') { xyPt.setX(xyPt.getX() + delta) xyPt.setY(xyPt.getY() + delta) if (direction == 'Down') { xyPt.setY(xyPt.getY() - delta) if (direction == 'Ld') { xyPt.setX(xyPt.getX() - delta) xyPt.setY(xyPt.getY() - delta) if (direction == 'Rd') { xyPt.setX(xyPt.getX() + delta) xyPt.setY(xyPt.getY() - delta) // Zoom to the new location...
Page 160
//get MGMap if (map.isBusy() == false) if (type == 'Scale') map.zoomScaleDlg(); else map.zoomWidthDlg(); else alert("The Autodesk MapGuide Viewer is busy ... please\n try again in a few seconds"); /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Function: selMapObj() Description: select by object, uses the Select Map Objects dialog...
Page 161
Facilities Management Application Example Code (continued) Function: ObjSelChanged() Description: on change of selection, highlight room selected Arguments: none Return: none +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ function ObjSelChanged() // Get MGMap object var map = getMap(); if (map.isBusy() == false){ var selOptions = document.Selection.roomnum.options; var collection = map.createObject("MGCollection"); var sel = map.getSelection();...
Page 162
Facilities Management Application Example Code (continued) if (selValue[i].selected){ var temp = selValue[i].value; if (temp == 'showAll'){ var whereClause = "Space_Status is not null"; else{ var whereClause = "Space_Status='"+temp+"'"; var mapLayer = map.getMapLayer("Offices"); mapLayer.setSQLWhere(whereClause); map.refresh(); /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Function resetForm() + Description: resets the values in the form to the default values + Arguments: none...
When a user selects one or more filters from the list box, the corre- sponding Autodesk DWG layer(s) is displayed on the map. The user can also select one or more features on the map and display properties, including names and keys, and DWG layer properties for the current map layer.
Understanding Layers in Autodesk MapGuide When working with DWG data especially, it is important to understand the difference between Autodesk DWG layers, Autodesk MapGuide map layers, and Autodesk DWG map layers. These are not the same and are defined as follows: Layer Type...
This example illustrates some basic tasks an application can perform when working with DWG data. It primarily focuses on setting DWG filters and getting DWG data, but it can easily be modified to change other Autodesk MapGuide map layer properties, such as the DWG file, the DWG data source, and so on.
Page 167
7 Set the layer filter from the selected filter list using the dwgMapLayerDataSource.setLayerFilter(filterList) method. 8 Refresh the map using the map.refresh method. DWG Filtering Application selChanged Example Code Selection Changed Function // Called whenever items are selected or deselected in the list box function selChanged() var map = getMap();...
Page 168
Show Properties Function (showProperties) The following are excerpts from the showProperties() function. This function gets and displays properties of selected map features in a table in the output frame of the Web page, including DWG properties associated with the DWG map layer. The basic operational flow of this function is as follows: 1 Write JavaScript and style sheet selection code to output frame.
Page 169
DWG Filtering Application showProperties Example Code (continued) parent.outputframe.document.write ("<TD>"); parent.outputframe.document.write ("<h3>Map Feature</h3>"); parent.outputframe.document.write ("</TD>"); parent.outputframe.document.write ("</TR>"); // Get the map and selected features var map = getMap(); var sel = map.getSelection(); var mapObjects = sel.getMapObjectsEx(null); // Write the feature(s) properties to the table for (var i = 0;...
You can use the SDF Component Toolkit to add points, polylines, or poly- gons to an SDF file when the user clicks the map. Note that Autodesk MapGuide contains a similar functionality called redlining. This means that users can add features to the map without using the SDF Component Toolkit (see “Custom Redlining Application”...
Page 172
This example is called “Points of Interest.” It uses Active Server Pages (ASP) and SDF Component Toolkit commands to allow users to add points of interest to the map, which will also be added to the corresponding SDF data source. SDF Component Toolkit Points of Interest application Notice that the map is at the left and the controls are at the right.
Page 173
Example Code <HTML> <HEAD> <TITLE>Points of Interest Map</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE="VBScript"> // Send onDigitizedPoint events from Autodesk MapGuide Viewer ActiveX Control // to the event-handling function Sub map_onDigitizedPoint(Map, Point) onDigitizedPoint Map, Point End Sub </SCRIPT> <SCRIPT LANGUAGE="JavaScript"> // Determine browser...
Page 174
map.htm Example Code (continued) bVer = parseInt(navigator.appVersion); if (bName == "Netscape" && bVer >= 4) ver = "n4"; else if (bName == "Microsoft Internet Explorer" && bVer >= 4) ver = "e4"; else ver = "other"; // ...if Netscape, embed event observer if (ver == "n4") document.write("<APPLET CODE=\"MapGuideObserver6.class\"...
Page 175
map.htm Example Code (continued) <PARAM NAME="ErrorTarget" VALUE=""> <PARAM NAME="ObjectLinkTarget" VALUE=""> <PARAM NAME="ReportTarget" VALUE=""> <PARAM NAME="URLList" VALUE="Off"> <PARAM NAME="URLListTarget" VALUE=""> <PARAM NAME="AutoLinkLayers" VALUE=""> <PARAM NAME="AutoLinkTarget" VALUE=""> <PARAM NAME="AutoLinkDelay" VALUE="20"> <!-- in actual source, EMBED tag is on a single line --> <EMBED SRC="http://yourserver.com/maps/poi.mwf?URL= http://yourserver.com/maps/poi.mwf&Lat=0&Lon=0&MaScale=0 &Width=0&Units=M&ToolBar=On&StatusBar=On&LayersViewWidth=150...
Page 176
(pointName != "") // Create an instance of the SDF Component Toolkit var sdfToolKit = Server.CreateObject("Autodesk.MgSdfToolkit.1"); // If the command is Add or Remove, open the SDF for read/write. // If the command is Find, open the SDF as read-only.
Page 177
poi.asp Example Code (continued) sdfObject.SetGeometry(0, sdfGeometry); sdfObject.Name = pointName; sdfObject.Key = pointName; sdfObject.Url = ""; // The object is built. Now add it to the SDF. sdfToolKit.BeginUpdate(); sdfToolKit.AddObject(sdfObject); sdfToolKit.EndUpdate(); clearVars(); actionOp = "UpdateMap"; msgText = "Point added, updating map."; else // Invalid lat/lon values msgText = "Lat and Lon floating point quantities must be specified."...
Page 178
poi.asp Example Code (continued) zoomToLon = sdfPoint.X; zoomToLat = sdfPoint.Y; clearVars(); actionOp = "ZoomToPoint"; // Zooms to the point on the map msgText = "Zooming to point."; else msgText = "Point not found."; sdfToolKit.Close(); else msgText = "A name must be specified." else if (Request.Count >...
Page 180
poi.asp Example Code (continued) function getMap() if (ver == "n4") return parent.mapFrame.document.map; else return parent.mapFrame.map; // Following is the function called by the Digitize button. If the // browser is Navigator, it will send the onDigitizedPoint event to // the MapGuideObserver6.class observer (the obs variable). If the // browser is Internet Explorer, it will know to look for an observer // method with the same name as the event, which we defined with // VBScript in map.htm.
Toolkit is very straightforward. This example used ASP, but you can apply similar techniques using ColdFusion or another language. Please go to the customer sites page at www.autodesk.com/mapguidedemo to see more appli- cations and add your own applications to share with others.
Page 182
ConvertSDF Example Code (continued) Caption "Convert" Height Left 4440 TabIndex Width 1212 Begin VB.CommandButton btnBrowseTxt Caption "Browse" Height Left 4440 TabIndex Width 1212 Begin VB.TextBox txtTxtName Height Left TabIndex Text "d:\work\mapguide\water.txt" Width 4212 Begin VB.CommandButton btnExit Caption "Exit" Height Left 4440 TabIndex 3000...
Page 183
ConvertSDF Example Code (continued) Begin VB.CommandButton btnBrowseSdf Caption "Browse" Height Left 4440 TabIndex Width 1212 Begin RichTextLib.RichTextBox txtMsg Height 2292 Left TabIndex Width 4212 _ExtentX 7430 _ExtentY 4043 _Version 393217 Enabled 'True ReadOnly 'True ScrollBars TextRTF $"frmLab2.frx":0000 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name "Courier New"...
Page 184
ConvertSDF Example Code (continued) ErrHandler: 'Cancel was selected 'Just exit after resetting errhandler On Error GoTo 0 End Sub Private Sub btnBrowseTxt_Click() On Error GoTo ErrHandler cdOpen.Filter = "Text Files (*.TXT)| *.TXT" cdOpen.FilterIndex = 1 cdOpen.DialogTitle = "Open SDF File" 'Show the open dialog box cdOpen.ShowOpen txtTxtName.Text = cdOpen.FileName...
Page 185
ConvertSDF Example Code (continued) oTlkt.BeginUpdate j = 0 'Read from txt file till eof Do While Not EOF(1) 'Get the feature data Line Input #1, strObjType Line Input #1, strKey 'Key Line Input #1, strName 'Name Line Input #1, strUrl 'Url Line Input #1, strCnt 'Vertex count...
Page 186
ConvertSDF Example Code (continued) Close #1 ShowMessage txtTxtName.Text & " converted to " & txtSdfName.Text ShowMessage "Total features converted: " & j Exit Sub ErrHandler: 'Display the error number/message MsgBox Err.Number & " : " & Err.Description 'Reset the handler before exiting On Error GoTo 0 End Sub Private Sub btnDelete_Click()
Page 187
ConvertSDF Example Code (continued) objFound = Not (oObj Is Nothing) If Not (oObj Is Nothing) Then ShowMessage "Following feature is deleted" ShowMessage "Feature: " & i & " " & GetObjectTypeString(oObj.Type) ShowMessage " Key : " & oObj.Key ShowMessage " Name: "...
ConvertSDF Example Code (continued) GetObjectTypeString = "POLYGON" Case sdfPolylineObject: GetObjectTypeString = "POLYLINE" Case sdfPolyPolylineObject: GetObjectTypeString = "POLYPOLYLINE" Case sdfPolyPolygonObject: GetObjectTypeString = "POLYPOLYGON" End Select End Function Getting SDF File Information—a Visual Basic Example The SDFInfo example code shows how to open and access an SDF file to retrieve its information, such as precision, key length, bounding box, etc.
Page 189
SDFInfo Example Code (continued) TabIndex 1800 Width 1212 Begin VB.CommandButton btnSrchSpat Caption "Spatial Search" Height Left 4440 TabIndex 1440 Width 1212 Begin VB.CommandButton btnSrchSeq Caption "Seq Search" Height Left 4440 TabIndex 1080 Width 1212 Begin VB.CommandButton btnShowInfo Caption "Show Info" Height Left 4440...
Page 190
SDFInfo Example Code (continued) Height Left 4440 TabIndex Width 1212 Begin RichTextLib.RichTextBox txtMsg Height 2652 Left TabIndex Width 4212 _ExtentX 7430 _ExtentY 4678 _Version 393217 Enabled 'True ReadOnly 'True ScrollBars TextRTF $"frmLab1.frx":0000 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name "Courier New" Size Charset Weight Underline 'False...
Page 191
SDFInfo Example Code (continued) Private Sub btnExit_Click() End Sub Private Sub btnShowInfo_Click() 'Check if there is a file name in edit box If txtSdfName.Text = "" Then ShowMessage ("Select an SDF file first!") Exit Sub End If Dim oTlkt As New SdfToolkit Dim oBox As SdfBoundingBox Dim strMsg As String...
Page 192
SDFInfo Example Code (continued) 'Get total count of features strMsg = oTlkt.TotalObjects ShowMessage "Total features: " & strMsg 'Check for feature classes present in this sdf ShowMessage "Contains Points: " & oTlkt.ContainsObjectClass(sdfPointClass) ShowMessage "Contains Polylines: " & oTlkt.ContainsObjectClass(sdfPolylineClass) ShowMessage "Contains Polygons: " & oTlkt.ContainsObjectClass(sdfPolygonClass) 'Close the toolkit oTlkt.Close...
Page 193
SDFInfo Example Code (continued) On Error GoTo ErrHandler 'Open the sdf file in read-only mode oTlkt.Open txtSdfName.Text, sdfOpenRead, True 'Begin spatial search for polylines oTlkt.BeginKeyIndexSearch (Key) 'Get first feature Set oObj = oTlkt.SearchToNextObject() objFound = Not (oObj Is Nothing) i = 1 Do While Not (oObj Is Nothing) ShowMessage "Feature: "...
Page 194
SDFInfo Example Code (continued) Dim oTlkt As New SdfToolkit Dim oObj As SdfObject Dim strMsg As String Dim i As Long On Error GoTo ErrHandler 'Open the sdf file in read-only mode oTlkt.Open txtSdfName.Text, sdfOpenRead, True 'Begin sequential search oTlkt.BeginSequentialSearch 'Get first feature Set oObj = oTlkt.SearchToNextObject() i = 1...
Page 195
SDFInfo Example Code (continued) Dim oTlkt As New SdfToolkit Dim oBox As SdfBoundingBox Dim oObj As SdfObject Dim strMsg As String Dim i As Long On Error GoTo ErrHandler 'Open the sdf file in read-only mode oTlkt.Open txtSdfName.Text, sdfOpenRead, True 'Get the SDF extents Set oBox = oTlkt.BoundingBox 'Begin spatial search for polylines...
SDFInfo Example Code (continued) txtMsg.Text = txtMsg.Text & Msg & vbCrLf End Sub Function GetObjectTypeString(ObjType As SdfObjectType) As String Select Case ObjType Case sdfPointObject: GetObjectTypeString = "POINT" Case sdfPolygonObject: GetObjectTypeString = "POLYGON" Case sdfPolylineObject: GetObjectTypeString = "POLYLINE" Case sdfPolyPolylineObject: GetObjectTypeString = "POLYPOLYLINE" Case sdfPolyPolygonObject: GetObjectTypeString = "POLYPOLYGON"...
Page 197
CopySDF Example Code (continued) Begin VB.CommandButton btnBrowseInSdf Caption "Browse" Height Left 4440 TabIndex Width 1212 Begin VB.TextBox sdfInName Height Left TabIndex Text "d:\work\mapguide\redline.sdf" Width 4212 Begin VB.CommandButton btnExit Caption "Exit" Height Left 4440 TabIndex 3000 Width 1212 Begin MSComDlg.CommonDialog cdOpen Left 4920 2520...
Page 198
CopySDF Example Code (continued) Width 1212 Begin RichTextLib.RichTextBox txtMsg Height 2292 Left TabIndex Width 4212 _ExtentX 7430 _ExtentY 4043 _Version 393217 Enabled 'True ReadOnly 'True ScrollBars TextRTF $"frmLab3.frx":0000 BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} Name "Courier New" Size Charset Weight Underline 'False Italic 'False Strikethrough 'False...
Page 199
CopySDF Example Code (continued) End Sub Private Sub btnBrowseOutSdf_Click() On Error GoTo ErrHandler cdOpen.Filter = "SDF Files (*.SDF)| *.SDF" cdOpen.FilterIndex = 1 cdOpen.DialogTitle = "Save SDF File" 'Show the open dialog box cdOpen.ShowSave sdfOutName.Text = cdOpen.FileName ErrHandler: 'Cancel was selected 'Just exit after resetting errhandler On Error GoTo 0 End Sub...
Page 200
CopySDF Example Code (continued) yMin = oBox.MinY + Abs((Abs(oBox.MaxY) - Abs(oBox.MinY)) / 3) yMax = oBox.MaxY - Abs((Abs(oBox.MaxY) - Abs(oBox.MinY)) / 3) oBox.SetExtent xMin, yMin, xMax, yMax 'Start searching from insdf and writing to outsdf oTlktIn.BeginSpatialIndexSearch sdfAllObjectClasses, oBox oTlktOut.BeginUpdate Set oObj = oTlktIn.SearchToNextObject i = 0 Do While Not (oObj Is Nothing) oTlktOut.AddObject oObj...
Page 201
CopySDF Example Code (continued) Function GetObjectTypeString(ObjType As SdfObjectType) As String Select Case ObjType Case sdfPointObject: GetObjectTypeString = "POINT" Case sdfPolygonObject: GetObjectTypeString = "POLYGON" Case sdfPolylineObject: GetObjectTypeString = "POLYLINE" Case sdfPolyPolylineObject: GetObjectTypeString = "POLYPOLYLINE" Case sdfPolyPolygonObject: GetObjectTypeString = "POLYPOLYGON" End Select End Function SDF Component Toolkit Applications...
ActiveX Control 11 ActiveX Control detecting with CODEBASE 27 Autodesk MapGuide Viewer Plug-In. See Plug-In displaying a map in 20 Autodesk MapGuide Viewer, Java Edition. See Java embedding a map 22 Edition installing on client machines 27 Autodesk MapGuide Viewer. See Viewer...
Page 204
ColdFusion 10 DWG (continued) about 89 filtering layers 164 and Autodesk MapGuide LiteView 26 MapGuide map layer, defined 165 creating reports with 85, 86, 89, 142, 146, Dynamic Authoring Toolkit 10 defined 88 listing database contents with 89, 92, 102...
Page 205
Java Edition support 36 Plug-In and Java Edition 72 operating system support 36 setting up 72 help for Autodesk MapGuide Viewer API 13 for users 11 HTML pages Key Index Files (KIFs). See SDF Component Toolkit creating 90, 95, 104, 114, 118, 127...
Page 206
MacOS, supported configurations 19 Netscape Navigator embedding a map 22 accessing event handling 71 from ActiveX Control 32 event observers in 70 from Java Edition with Java 38 JavaScript support in 36 from Plug-In 32 map access 32 from Plug-In with applet 40 new features 8 busy state, detecting change in 46 DWG support 8...
Page 207
85, 86 VBScript 10, 112 and server-side scripting 85 defined 70 creating in Autodesk MapGuide Author 92, event handler example 75, 78 103, 116, 126 setting up event handlers 70, 71, 75 creating with ASP 109...
Page 208
visibility of DWG layers 164 Windows of map layers 55 supported configurations 19 Visual Basic 10 SDF Component Toolkit example 181, 188, stand-alone Windows applications 19 XML 10 zooming 61 Index...
Need help?
Do you have a question about the 15606-011408-9330 - MAPGUIDE R6.3 SITE LIC-UPG R6 and is the answer not in the manual?
Questions and answers