+ All Categories
Home > Documents > How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide...

How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide...

Date post: 13-Aug-2020
Category:
Upload: others
View: 8 times
Download: 0 times
Share this document with a friend
27
November 30 – December 3, 2004 Las Vegas, Nevada How to Create Custom Applications using Autodesk MapGuide® Michael Schlosser -- Autodesk GI41-2 The Autodesk MapGuide product suite includes all the tools you need to create a custom web-based mapping application. This session will help you harness the power of MapGuide for your own needs. We'll use practical examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development techniques. We'll demonstrate tips and tricks for data loading, map authoring, designing web pages and dynamic reports, and customizing application menus. This course is designed for existing MapGuide users and anyone interested in learning how to develop custom applications for Autodesk MapGuide. Who Should Attend Users of Autodesk MapGuide Topics Covered Introduction to creating custom applications using Autodesk MapGuide Review scope definition, design, and development Development aspects including HTML, JavaScript, ColdFusion, MapGuide Live demo About the Speaker: Mike is geospatial project manager for Autodesk Canada. With 12 years of experience, he is an expert in the design, development, and implementation of GIS systems. He has worked with a wide variety of clients on their GIS and web- mapping implementations, including telecommunications firms, utilities, transportation, and government departments. He is skilled in project management, creating GIS-based simulations and demonstrations, and developing innovative solutions to business problems. Mike is also a skilled educator and trainer whose works are published in both trade and academic publications. [email protected]
Transcript
Page 1: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

November 30 – December 3, 2004 ◊ Las Vegas, Nevada

How to Create Custom Applications using Autodesk MapGuide® Michael Schlosser -- Autodesk

GI41-2 The Autodesk MapGuide product suite includes all the tools you need to create a custom web-based mapping application. This session will help you harness the power of MapGuide for your own needs. We'll use practical examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development techniques. We'll demonstrate tips and tricks for data loading, map authoring, designing web pages and dynamic reports, and customizing application menus. This course is designed for existing MapGuide users and anyone interested in learning how to develop custom applications for Autodesk MapGuide.

Who Should Attend • Users of Autodesk MapGuide

Topics Covered • Introduction to creating custom applications using Autodesk MapGuide • Review scope definition, design, and development • Development aspects including HTML, JavaScript, ColdFusion, MapGuide • Live demo

About the Speaker: Mike is geospatial project manager for Autodesk Canada. With 12 years of experience, he is an expert in the design, development, and implementation of GIS systems. He has worked with a wide variety of clients on their GIS and web-mapping implementations, including telecommunications firms, utilities, transportation, and government departments. He is skilled in project management, creating GIS-based simulations and demonstrations, and developing innovative solutions to business problems. Mike is also a skilled educator and trainer whose works are published in both trade and academic publications.

[email protected]

Page 2: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

How to Create Custom Applications Using Autodesk MapGuide

1.0 Summary The Autodesk MapGuide® product suite includes all the tools you need to create a custom web-based mapping application. This session will help you harness the power of MapGuide for your own needs. The tutorial uses practical examples to expose you to the Autodesk MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development techniques, tips, and tricks that encompass data loading, map authoring, web page design, dynamic reports, and custom application menus.

2.0 Need MapGuide application development is pursued for a variety of reasons:

• Adapt existing data for use with specific software • Increase usefulness of data and software • Streamline steps involved in accomplishing repetitive tasks • Promote standardization • Enhance software functionality and ease of use • Differentiate and promote corporate “look”

3.0 Tools MapGuide application development involves the use of a variety of software:

• MapGuide Server, Author and Viewer • MapGuide Raster Workshop • MapGuide SDF Loader • MapGuide SDF Component Toolkit • MapGuide Dynamic Authoring Toolkit • HTML, JavaScript, VBScript, ColdFusion, Active Server Pages (ASP) • Other (ie CAD, GIS, graphics, web authoring, etc)

4.0 Resources MapGuide application development encompasses multiple disciplines and skills including:

• GIS Technicians and Cartographers: • Spatial data creation, conversion and manipulation, map to attribute linkages • Map design and creation

• Web Designers and Graphic Artists: • Page layout, user interface, functionality and other behavior elements • Splash pages, graphics, logos, buttons and other visual elements

• Programmers: • Web development in HTML, JavaScript, VBScript, ColdFusion, ASP, etc

• Database Technicians and Administrators: • Database design, creation and maintenance, attribute to map linkages

2

Page 3: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

5.0 Scope Definition Definition of scope is a crucial part of any project in that it defines what your project is about and sets the stage for all remaining tasks. During scope definition, you identify and prioritise your needs while ensuring that the MapGuide project is sized for success. Brain storming sessions, formal interviews and a review of past studies and similar projects are useful mechanisms for determining project scope.

• Identify purpose • Describe the purpose of the application in a couple of sentences.

• Identify intended users • GIS, mapping technicians versus clerical, counter personnel • Casual, intermittent versus frequent, regular users • Internal versus external users • Consultants, partners, clients versus general public

• Identify acceptable map delivery mechanisms • Operating system: Windows? MacOS? Solaris? • Platform: Standalone desktop? Web browser? • Web browser: Internet Explorer? Netscape? • Is downloading a plug-in acceptable to your users? • What type of map related functionality will be required? • Which scripting language will you be using for development? • Viewer choices:

• MapGuide Viewer ActiveX Control for Internet Explorer • MapGuide Viewer Plug-in for Netscape • MapGuide Viewer Java Edition • MapGuide Liteview • OnSite Enterprise and OnSite View for PDA and mobile applications

• Determine platform related limitations • Intranet, Internet, Desktop (via ActiveX control) • Minimum browser support • Minimum screen resolution • Minimum color depth • Plug-in requirements

• Identify performance expectations • The 3-second rule? The 10-second rule? • Traffic expectations • Server hardware • Network/Internet • Type of data • Database management system • Spatial data volume, spatial data density, • Dynamic and static map layers • Other

• Identify security expectations • Windows NT File System (NTFS) Security • Web Server Security • Database Management System Security • MapGuide Security (User name and password, Access keys, MapGuide Authors groups)

3

Page 4: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

• Determine data requirements • Establish data inventory (Is data dictionary available?) • Establish geographic scope • Determine spatial data format: SDF, DWG, SHP, Oracle, other • Determine attribute data format: MS Access, SQL Server, Oracle, other • Assess data conversion requirements • Assess data readiness (structure, linkages, topology)

• Determine search requirements • Query attribute information via the map • Query the map via attributes • Simple versus comprehensive

• Determine reporting needs • Custom: specially formatted reports designed to satisfy a specific need. • Generic: rows and columns of numbers and text to satisfy a general need. • Linkages to other attribute and additional types of documents (ie GIF, JPEG, AVI, DWF)

• Identify Zoom Goto needs • Enable map-related searches and allow users to find a specific map object by name. • Any map object that must be located by name is a potential candidate for a zoom goto

definition. Examples include: • Property polygons • Points of interest • Street intersections • Above- and below-ground infrastructure

6.0 Design and Development Design and development incorporates your ideas and requirements as determined during the scope definition process to design and build a working MapGuide application.

Design involves planning the way components fit together and requires careful co-ordination to:

• Ensure consistency in presentation and style of published maps and reports • Ensure consistency in data quality (ie currency, completeness and correctness) • Minimize duplicate data collection efforts • Reduce cost and effort of application development • Ensure performance expectations can be met • Ensure sufficient resources are available for on-going application maintenance

Development puts your design (ie the plan) into action and encompasses:

• Creation and manipulation of spatial and attribute data • Preparation of various application specific files • Creation of supporting graphics • Programming • Quality assurance and testing

While working through the design process, consider the following:

• How will users interact with the Web page? • How will users interact with the Map? • Which MapGuide functions will you need to satisfy functional requirements? • How will the design impact on-going maintenance of the application?

4

Page 5: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

A MapGuide application design will typically need to address the following:

• Splash page

The splash page introduces users to the application. It’s designed to inform users where they are and prepares them for what’s ahead. The page should include a brief overview of the application’s purpose and capabilities. The screen also serves to ensure that application prerequisites are satisfied and reports on missing components.

• Core page

The core page is the heart of the application and the intended destination of its users. It addresses all functional requirements of the application and typically includes: menu, map, legend, report, header and footer areas.

• Navigation (ie links, menus)

Application menus give users easy access to map-related and other functionality. Menus should satisfy user expectations regarding terminology and functionality. Other navigation tools should provide quick and simple access to map features and related information.

• Appearance • fonts, colors, graphics, buttons, links

• Map data and authoring issues • Key, Name, Url • Object type (point, line, polygon, poly-polyline, poly-polygon) • Are multiple versions (ie generalized versus detailed) of the same layer needed? • Layer groups, layers and corresponding naming conventions • Layer visibility • Feature selection • Reporting and associated map linkages • Scale • Style

• Project directory structures • Helps ensure that project specific data, maps and application programs remain organized so

that they do not conflict with other projects hosted under the same environment.

• Development Guidelines (Programming Style) • Display requirements (ie screen resolution and color depth) • Naming conventions for files, labels, controls, variables, functions • Style sheets for consistency of font faces, font sizes, color, text alignment and other

characteristics • Dialogue box layout conventions • Programming languages to be used • Commenting requirements • Code formatting • Error handling

• Quality assurance and testing requirements • Based on expectations established by the requirements definition • Does the application meet requirements?

• Compatibility, Functionality, Navigation, Presentation, Usability, Performance • Considers design and development guidelines • More than finding and squashing bugs.

5

Page 6: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

7.0 Project Directory Structure A MapGuide project consists of a collection of files. A standardized project directory structure helps ensure that project specific data, maps and application programs remain organized so that they do not conflict with other projects hosted under the same environment. Consider the following example:

• MGProjects The MapGuide project folder. This folder will contain multiple MapGuide projects. • Project Name1 The specific MapGuide project folder. • Admin Contains project details to support project maintenance (eg project charter,

maintenance procedures, project specifications, and authoring guidelines). • Dbms Contains file-based database management systems files such as Dbase (DBF)

and MS Access (MDB) files specific to the project. • Dwg Contains DWG files pertaining to this project. • Mwf Contains working copies of Map Window Files (MWF) as created by MapGuide

Author. By locating this folder above the Web folder, the Mwf folder is NOT accessible to Web users. MapGuide Authors must be granted Read and Write permissions to be able to edit the files in this folder.

• Sdf Contains Spatial Data Format (SDF) files pertaining to this project. • Shp Contains SHP data files pertaining to this project. • Web Contains files and folders that will be accessed via the Intranet/Internet. • Images Contains various raster image (ie GIF, JPG) files in support of the Web

application. • Maps Contains published versions of the Map Window Files as created by MapGuide

Author. By making this folder a subfolder of the Web folder and giving Read access to the Web folder, all Web users with access rights to the Web folder will also have access rights to view maps. Note that only password protected MWF files should be placed in this folder.

• Reports Contains server-side scripts (ie ASP, CFM) used to generate reports and other Web content. By making this folder a subfolder of the Web folder and giving Execu e access to the Web folder, all Web users with access rights to the Web folder will also have access rights to run reports and other scripts stored in this folder.

t

6

Page 7: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

8.0 Security A MapGuide implementation relies on several layers of security to control access to programs and data. The type of access permissions granted to a user depends on the user’s role (ie browser versus administrator) and the type of file being accessed. Autodesk MapGuide security exists at four levels:

• Windows NT File System (NTFS) Security • Web Server Security • Database Management System Security • Autodesk MapGuide Security

The following tables summarize typical access permissions.

Browser User NTFS Web Database MapGuide

Web Content (html, jpg, gif)

Read Read NA NA

MapGuide maps (mwf)

Read Read NA Password protected MWF

Reports (cfm) Read Read/execute NA NA

Databases Read Read Read NA

Map Layers NA NA NA Access Keys

Administrator User NTFS Web Database MapGuide

Web Content (html, jpg, gif)

Read/write Read NA NA

MapGuide maps (mwf)

Read/write Read NA Password protected MWF

Reports (cfm) Read/write Read/execute NA NA

Databases Read/write Read/write Read/write NA

Map Layers NA NA NA Access Keys

MapGuide SDF Read/write NA NA NA

MapGuide Raster Read/write NA NA NA

MapGuide DWG Read/write NA NA NA

7

Page 8: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

The Autodesk MapGuide Server manages resources such as Spatial Data Format (SDF) files, raster images, Zoom Goto categories, and Data Sources/Tables. By default, access to all resources via the Autodesk MapGuide Server is controlled through NTFS, web server security and database management security protocols. However, access to any particular resource can also be controlled by MapGuide via the following mechanisms:

• User name and password

The Autodesk MapGuide Server Administrator can be used to establish a set of Autodesk MapGuide Server users and groups. Individual users and groups can then be granted access to certain MapGuide resources. When using a map containing a layer that requests a resource controlled by user-groups/password security a user must enter a valid user name and password once at the beginning of the session for each layer requiring a user name and password.

• Access keys

Access keys are passwords that are created using the Autodesk MapGuide Server Administrator. When a map is authored, access keys can be embedded within a map layer or zoom goto definition. When the resource referenced by the map layer or zoom goto definition is requested, the access key accompanying the request must be validated against the access key defined on the Autodesk MapGuide Server. Two attractive features of access key security are that the authentication process requires no interaction by the map user and the access key can be made valid for pre-set periods of time. As a minimum security measure, MapGuide access keys should be implemented for all MapGuide resources.

• Authors groups

When creating a layer in a MWF file with Autodesk MapGuide Author, users in the Authors group, after entering their user name and password, will be presented with a pick list of all available SDF files, raster image files and SQL data sources that can be used. The ability to choose a resource from a list makes authoring maps much easier than for users who have to enter a known path to a resource on the Autodesk MapGuide Server.

9.0 Data Loading Data loading is the process of accessing and/or converting spatial data for use with MapGuide.

MapGuide is capable of accessing and manipulating many different file formats. Several data formats can be accessed by MapGuide directly (ie without conversion) including:

• MapGuide Spatial Data File (SDF) • AutoCAD DWG, Autodesk GIS Design Server • Oracle Spatial • ESRI Shapefile (SHP) • Data residing in OLE DB data source • Georeferenced and non-georeferenced raster • Other CAD and GIS formats via third-party Spatial Data Providers (SDP) for MapGuide

Some implementations require that certain file formats first be converted to the MapGuide SDF format before they can be used by MapGuide. A number of options for creating SDF files exist:

• Autodesk Map • MapGuide SDF Loader • Third-party software

8

Page 9: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

9.1 MapGuide SDF File Format • Contains list of coordinates defining map object geometry (Feature_Geom): points,

polylines, polygons, poly-polylines, poly-polygons

• Each SDF file should contain only one object type

• Each map object has three attribute values

• Feature_Id: Unique identifier (ie key) used to link object to attributes in a database

• Feature_Name: Used as the object label, as well as the contents of the map tool tip

• Feature_Url: Hyperlink used to link to another page

9.2 Creating SDF Files via Autodesk Map The creation of SDF files via Autodesk Map relies on the Autodesk MapGuide Export feature. The conversion process is typified by the following steps:

Step 1. Access map features to be exported (ie open/attach/import/retrieve as required)

Step 2. Ensure Global Coordinate System is assigned

Step 3. Zoom to extents

Step 4. Connect to data source, if required

Step 5. Create link template, if required

Step 6. Create topology, if required

Step 7. Generate SDF file for use by MapGuide

Step 8. Publish newly created SDF files to appropriate directory

Tip: Use AutoLisp expressions to specify the values of the Feature_Id, Feature_Name and Feature_Url fields:

Action Syntax Example To specify a SQL column value: &field@mylpn

&rollnum@assessment

To specify an Object Data value: :namefield@objecttable

:watmainid@watermain

To specify an AutoCAD property: .propertyname

.layer

9

Page 10: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

Action Expression Fly-out/Label

Result To concatenate multiple values: (strcat A B C) ABC

To concatenate more than three items, nest multiple strcat statements:

(strcat A “ “ (strcat B “ “ C)) A B C

To concatenate items so that they appear on separate lines, use “\n”:

(strcat A “\n” (strcat B “\n” C))

A B C

9.3 Creating SDF Files via the SDF Loader The SDF Loader is a command-line utility that converts map data into the SDF format from a variety of spatial formats including:

• Autodesk DXF, DWG • ESRI ArcInfo coverage • ArcView Shapefile (SHP) • Atlas BNA • MapInfo Interchange (MID, MIF) • Intergraph/Microstation (DGN) • Comma-separated values (CSV)

To use the SDF Loader, you enter commands via the MS-DOS command prompt. Batch files can also be used to simplify the use of the SDF Loader and help automate the creation of SDF files.

Syntax: SDFLD32I /I{B|C|D|H|L|M|S|V|W|X} /O{O|S|L} [OtherSwitches] InputFile OutputFile

Example: SDFLD32I /Iw /Os parcels.dwg parcels.sdf

Switches /I Specifies format of the input file. Examples include:

H – ArcView Shapefile (SHP) M – MapInfo Interchange Format (MIF) W – AutoCAD (DWG) X – AutoCAD (DXF)

/O Specifies the format of the output file to be generated: O – no SDF or SDL (table only) L – SDL format S – SDF format

/Coordprec: Specifies the coordinate precision: 32 – accurate to 7 digits 64 – accurate to 13 digits

/Coordsys: Uses the specified cscode to establish the coordinate system for input and output files

10

Page 11: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

/Generalize: Reduces the vertex count of each map feature by the specified percentage. /Info Returns information about the input file. Note that no conversion is performed

when this switch is used. Typical information returned includes: - name, number of tables, layers, blocks, columns - precision, coordinate system

/Key: Specifies the value of the Feature_Id for each object /Layer: Extracts specified layers from the input file and writes corresponding objects

to the output file. /Link: Specifies the value of the Feature_Link for each object /Name: Specifies the value of the Feature_Name for each object /PL2PG Converts closed polylines to polygons. /Type: Specify the feature type to be written to the output file

L – lines, polylines, poly-polylines M – points P – polygons, poly-polygons

/W Specifies how to handle the output file if it already exists: A – Append O – Overwrite Q – Quit

Tip: Use special syntax for the key, link and name swi ches to include values from multiple columns, concatenate text, and create multi-line tool tips.

t

Examples /Name:"1" Specifies first column in table (when there is only

one table) /Name:"1@TableName" Specifies first column in TableName table /Name:"COL:ColumnName" Specifies column by name from table (when there

is only one table) /Name:"COL:ColumnName@TableName" Specifies column and table by name /Name:"1/2 "

Use the forward slash (/) to separate multiple columns. Concatenates the values of the first and second columns of the default table.

/Name:”1/TEXT:\nParcel No. /2/” Use the TEXT: parameter to include text (such as spaces, dashes, etc.) in the concatenation. Concatenates the first column with the text “Parcel No.” and the second column. The text and the second column are placed on a new line as indicated by the new line sequence (\n).

Command Examples

Use the /Info switch to save information about the AutoCAD DWG file to a text file for subsequent review.

sdfld32i.exe /IH /INFO Sample.shp > Sample.txt

11

Page 12: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

Convert parcel polygons from AutoCAD DWG format to SDF. Use the /PL2PG switch to ensure that map features are interpreted as polygons by MapGuide.

sdfld32i.exe /IW /OS /PL2PG Parcel.dwg Parcel.sdf

Convert zoning polygons from MapInfo MIF format to SDF using a coordinate precision of 32 and an input coordinate system of IL83-EF. The name field will contain the value of the first column in the default table.

sdfld32i.exe /IM /OS /WO /COORDPREC:32 /COORDSYS:IL83-EF /NAME:"1" /TYPE:P Zone.MIF Zone.sdf

Convert sanitary lines from AutoCAD DWG format to SDF using the default coordinate system and precision. The key field will contain the value of the Key column from the object table named Sanitary. The name field will contain the value of the Pipesize column from the same object data table. The text “Diameter:” will be used as the prefix for the Pipesize value.

sdfld32i.exe /IW /OS /TYPE:l /KEY:”COL:Key@Sanitary” /NAME:"Text:Diameter: /COL:Pipesize@Sanitary " Sanitary.dwg Sanitary.sdf

10.0 Map Authoring Map authoring refers to using MapGuide Author to create a map consisting of various data layers, map display properties, zoom goto definitions and report linkages. The map authoring process separates map information into different layers and themes; assigns color, symbology and labels to spatial objects; links map elements to attribute databases; and results in the creation of Map Window Files (MWF) which contain all of the properties necessary for users to view and interact with your map via the MapGuide Viewer.

Map authoring involves the following:

• Establish general properties (map name, background color, map extents)

• Specify coordinate system

• Set MWF password

• Create map layers

12

Page 13: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

• Establish general layer properties

• Type of map layer (text, point, polyline, polygon, raster, AutoCAD DWG and DWF) • Map layer name • Legend label • Displayed in viewer legend versus not displayed in legend • Make map features selectable versus non-selectable • Make map layers dynamic versus static • Draw priority • Make layers active by default versus not active by default

• Establish data source properties

• Map server URL • Data source • Feature table • Key • Geometry • Name • URL • SQL Where clause

• Establish map display styles

• Always visible versus visible according to specified scale range • Thematic based on individual values, a range of values, or not themed • Display properties dependant on type of map object (color, line style and thickness, text size,

font, polygon fill styles, etc) • Labelling style • Layer security settings (access keys, API security)

• Establish linkage between map features and reports

• Create Zoom Goto definitions

A well authored map has the following characteristics: • Easy to interpret and use • Predictable • Flexible and functional • Performs well • Easy to maintain

10.1 Authoring Tips • Map extents should be chosen with end user requirements in mind. For example, map

extents for state/provincial maps should extend slightly beyond state/provincial boundaries; for urban maps, map extents should extend slightly beyond municipal boundaries.

• Water features should be displayed in blue as per user expectations. Lakes should appear as solid-filled polygons to differentiate them from linear water features (ie rivers, streams, creeks).

• Major features should be annotated with visible text to enhance map interpretation. Text font, color, size and rotation should be chosen carefully to avoid over-posting and promote readability.

13

Page 14: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

• All map features should include object labels (ie names) that appear as a map fly-out (ie tooltip) to aid in map interpretation.

• The default background color should be chosen carefully to help offset the subject data from the background.

• Feature colors should be chosen for viewing in color and black and white. Certain color combinations when printed via a black and white printer will generate unreadable output; Test color combinations for readability.

• When creating themed layers, consider choice of symbology: • Point objects can be themed by color, size and/or choice of symbol • Line objects can be themed by color, line width and/or line type • Polygon objects can be themed by color and/or fill pattern

• When theming non-discrete values by color, use gradients of the same color for each value category; when theming discrete values by color, use established color conventions where possible (ie hot/cold = red/blue; good/bad = green/red).

• Consider including a single-line street network to aid in interpretation. The single line street network should also be categorized into major and minor roads. Major roads can then be themed separately from minor roads. For example, major roads could be the only roads visible in the initial map view; minor roads could be activated after zooming in. Major roads could be displayed in a slightly wider line than minor roads; major and minor roads could also be labelled differently depending on zoom scale.

• Avoid activating raster layers by default. Raster layers require more server resources than vector layers. Raster layers also require increased time to display compared to vector layers. For most MapGuide applications, users should be the ones to decide whether to view the raster layers.

• The amount of information that appears during each successive zoom should be carefully controlled to maintain interest and relevance while maintaining performance and responsiveness. For example, because each press of the [Zoom In] button increases the map magnification by a factor of two, a corresponding increase in map detail should also be revealed.

• Standardize layer priorities. Layer priority is directly related to how the layers are presented in the MapGuide legend. Similar to overhead transparencies, objects on a layer with a high priority would appear on top of objects on a layer with a low priority. Layer priorities should be established based on a documented set of rules to help avoid the situation where objects on one layer obscure objects on another layer. Layer priorities range from 1 to 100; decimal values are permitted. Suggested layer priorities are as follows:

Layer Type Priority Range

Text 81-100Points 61-80Lines 41-60Polygons 21-40Raster 1-20

• Carefully control object selection. By default, MapGuide Author assumes that all map layers contain selectable objects. Only objects that are used for selecting other objects or for generating reports should be selectable.

14

Page 15: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

• Ensure that the correct object is selectable. For example, avoid situations in which users are forced to select a polygon centroid (because it contains the link to the database) rather than the polygon itself.

• Consider hiding the single-line street layer (but keep it active) when zoomed in close (ie scales up to 1:1000) so that the streets do not distract from other line work. Streets can be hidden by selecting a display color that blends with or is only slightly different in color from the background color. By keeping the layer active, users can continue to use the map tool tip to display street names if required. Alternatively, streets could be deactivated completely and only the street name text shown.

• Much of the performance in MapGuide is impacted by MapGuide Author. MapGuide Author includes a feature in the interface window to determine how much data is transferred during downloads. Monitoring the data transferred will help determine the impact on performance as layers are activated.

The following table provides recommended maximums for reasonable response times. Values are based on reasonable efficiency at each connection type – individual performance varies.

Connection Type Maximum Number of Bytes Returned

14.4 KBps modem 20 Kbytes 28.8 KBps modem 35 Kbytes ADSL or CABLE 150 Kbytes Internet/T1 (~1.5 MBps) 200 Kbytes Local Network 400 Kbytes

• Performance can sometimes be enhanced through the use of static map layers. Static map layers are embedded entirely in the MWF file (increasing its initial download size per session), and will not query the MapGuide Server for map features. This means the spatial data for static layers is transferred initially when the MWF is downloaded from the Web server. Once in the client’s local cache, static layers are immediately available at all times, and no further requests are sent to the MapGuide Server for the layer during that session.

The initial map view (or key map) is a good candidate for a static layer. Other suitable candidates include:

• Layers that will be immediately visible as soon as the map is loaded. • Layers that contain data that rarely change (eg political boundaries). • Layers that do not contain a lot of data (i.e. <20Kb).

• Geographic features such as contour lines and water boundaries are inherently complex and consequently large amounts of spatial data are required to represent them. Any polyline or polygon feature can be represented at different data densities. Multiple representations of spatial data sets can be generated from a dense data set by using the MapGuide SDF Loader or other third-party products. Through a process called generalization, the dense data set can be thinned to provide an alternate representation of the same features. This way, when zoomed out, generalized data should be used and when zoomed in, detailed data should be used. Generalization or filtering sub layers appropriate for the scale will greatly increase performance.

• Ensure MapGuide zoom gotos are defined in terms of a bounding box rather than a point. The bounding box can easily be created by modifying the Zoom Goto definition’s SQL statement.

• Consider introducing a zoom goto definition based on street intersection.

15

Page 16: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

11.0 HTML The Hypertext Markup Language (HTML) provides Web browsers with the instructions required to control how documents are viewed and how they relate to each other. HTML is more than a language for displaying text, images and other Web elements; it also helps tie together various parts of a Web application including MapGuide. The power of HTML is in the use of markup tags!

Consider the following…

<HTML> <HEAD>

<TITLE> Sample 1</TITLE> </HEAD> <BODY> Welcome to the world of HTML. </BODY> </HTML>

Note that…

• Tags begin and end with angle-brackets

• Tags are often used in pairs, a starting tag and an ending tag, as in <HTML> and </HTML>, respectively. Note the use of the forward slash which indicates an ending tag.

• Every HTML document begins and ends with the <HTML> and </HTML> tags to inform Web browsers that the file contains HTML text.

• The basic HTML document contains two parts: the head indicated by <HEAD> and </HEAD>, as well as, the body indicated by <BODY> and </BODY>.

How to format text…

<HTML> <HEAD>

<TITLE> Sample 2</TITLE> </HEAD> <BODY> <CENTER> <H1>Text Formatting</H1><BR> This text is <B>BOLD</B>.<BR> This text is <I>ITALIC</I><BR> This text is <U>UNDERLINED</U>.<BR><BR> </CENTER> </BODY> </HTML>

16

Page 17: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

Now add a URL link and an image and then combine the two to create a clickable image…

<HTML> <HEAD>

<TITLE>Sample 3</TITLE> </HEAD> <BODY> <CENTER> <H1>Welcome to the world of HTML.</H1><BR> This text is <B>BOLD</B>.<BR>This text is <I>ITALIC</I>.<BR> This text is <U>UNDERLINED</U>.<BR><BR> <A HREF=”http://www.autodesk.com/”>Autodesk, Inc</A><BR><BR> <IMG SRC=”blueball.gif”><BR><BR> <A HREF=”http://www.autodesk.com/au/”>

<IMG SRC=”aulogo.jpg” alt=”Autodesk University”></A><BR><BR> <CENTER> </BODY> </HTML>

How to create a table…

<HTML> <HEAD>

<TITLE>Sample 4</TITLE> </HEAD> <BODY> <TABLE align=center border=1> <TR>

<TD>one</TD> <TD>two</TD> <TD>three</TD>

</TR> <TR>

<TD>four</TD> <TD>five</TD> <TD>six</TD>

</TR> </TABLE> </BODY> </HTML>

You can divide your window into vertical and horizontal areas called frames…

<HTML> <HEAD>

<TITLE>Sample 5</TITLE> </HEAD> <FRAMESET ROWS=”*,25%”>

<FRAMESET COLS=”*,*”> <FRAME NAME=”sample1” SRC=”sample1.htm”>

<FRAME NAME=”sample6” SRC=”sample6.htm”> </FRAMESET>

<FRAME NAME=”bottom” SRC=”blank.htm”> </FRAMESET> </HTML>

17

Page 18: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

You can change the contents of a specific frame by using targets…

<HTML> <HEAD>

<TITLE>Sample 6</TITLE> </HEAD> <BODY> <CENTER> <H1>Welcome to the world of HTML.</H1><BR> This text is <B>BOLD</B>.<BR>

This text is <I>ITALIC</I>.<BR> This text is <U>UNDERLINED</U>.<BR><BR>

<A HREF=”http://www.autodesk.com/” TARGET=”bottom”>Autodesk, Inc</A><BR><BR> <IMG SRC=”blueball.gif”><BR><BR> <A HREF=”http://www.autodesk.com/au/” TARGET=”bottom”>

<IMG SRC=”aulogo.jpg” alt=”Autodesk University”></A><BR><BR> </CENTER> </BODY> </HTML>

You can embed the MapGuide ActiveX version of the Viewer in a web page by using the <OBJECT> tag as follows…

<HTML> <HEAD>

<TITLE>Sample Map</TITLE> </HEAD> <BODY> <CENTER> <H1>Sample Map</H1> <OBJECT ID=”sampleMap”

WIDTH=80% HEIGHT=80% CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME=”URL” VALUE=”http://www.myurl.com/maps/mymap.mwf”>

</OBJECT> </CENTER> </BODY> </HTML>

12.0 Cold Fusion Macromedia Cold Fusion is a Web application development environment. Similar to HTML, the Cold Fusion programming language also relies on the use of tags. Therefore, if you know HTML, Cold Fusion is very easy to learn and use. However, unlike HTML, Cold Fusion is a server-side programming language that includes functions and variables and, therefore, is much more powerful than simple HTML. Cold Fusion also simplifies the task of querying database information and generating dynamic reports.

18

Page 19: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

Dynamic Reports

Dynamic reports are extremely useful in that their contents can be driven by the contents of a database. Consequently, a dynamic report will change as the contents of the database are updated.

In the simple dynamic report that follows, note the use of the HTML tags (ie <HTML>, <HEAD>, <BODY> and <TABLE>). Also, note the use of the Cold Fusion tags <CFQUERY> and <CFOUTPUT>. Cold Fusion tags are easily distinguishable from HTML tags because Cold Fusion tag names start with the letters “CF”.

<CFQUERY name=”Info” datasource=”AU”> SELECT * from PARCEL_DATA where PARCEL_ID in (#PreserveSingleQuotes(OBJ_KEYS)#) </CFQUERY> <HTML> <HEAD> <TITLE>Sample Dynamic Report</TITLE> </HEAD> <BODY> <CENTER> <H1>Sample Dynamic Report</H1> <TABLE border=1> <TR> <TD><B>Parcel Id</B></TD> <TD><B>Assessment Value ($)</B></TD> </TR> <CFOUTPUT QUERY=”Info”> <TR> <TD>#PARCEL_ID#</TD> <TD>#PARCELVALUE#</TD> </TR> </CFOUTPUT> </TABLE> </CENTER> </BODY> </HTML>

In the above example, the <CFQUERY> tag is used to retrieve data from an attribute data source. Every query is assigned a name so that the results of the query can be used later. The name we assigned to the query above is “Info”. The query will retrieve information from the data source named “AU”. The statement within the <CFQUERY> tags is a SQL statement that retrieves all columns (ie *) from the table named “PARCEL_DATA” where the unique identifer (ie PARCEL_ID) matches the values in the list defined by the variable OBJ_KEYS. The “PreserveSingleQuotes” function stops the single quotes that are wrapped around each value as indicated by the OBJ_KEYS variable from being omitted.

The <CFOUTPUT> tag is used to generate the dynamic output. Note that the <CFOUTPUT> tags wrap around the <TR> tags. The <CFOUPUT> will loop over each record retrieved by the query named “Info” and will generate a new table row for each record. The # signs wrapped around the values within the <TD> tags result in Cold Fusion outputting the values of the columns rather than interpreting the column name as a character string.

To test the above dynamic report, you can enter the URL of the report together with values for the OBJ_KEYS parameter in the address area of your browser.

http://www.myurl.com/SampleReport.cfm?OBJ_KEYS=504304039,508116018,508116024

19

Page 20: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

Dynamic Menus

Dynamic menus are similar to dynamic reports in that a database can be used to control the contents of the menu. Menu maintenance is easier because database updates instead of programming can be used to change the contents of the menu. That is, standard HTML tags establish the look and feel of the menus, Cold Fusion’s <CFQUERY> tag retrieves information from a database to configure the menu and the <CFOUTPUT> tag populates the menu. Consider the following…

<CFQUERY name=”Action” datasource=”AU”> SELECT * from MENU_CONFIG order by ACTION_SORT </CFQUERY> <HTML> <HEAD> <TITLE>Sample Dynamic Menu</TITLE> </HEAD> <BODY> <H1>Sample Dynamic Menu</H1> <FORM NAME="Menu"> <SELECT NAME="Items" SIZE="1>

<CFOUTPUT QUERY=Action> <OPTION VALUE=#ACTION.Action_Code#>#ACTION.Action_Name#

</CFOUTPUT> </SELECT> <FORM> </BODY> </HTML>

In this example, the <CFQUERY> tag retrieves the items from the database to be used to populate the dynamic menu and stores the results in a query named “ACTION”. The <FORM> and <SELECT> tags create a pop-up menu; the <OPTION> tag defines each pop-up menu item. The <CFOUTPUT> tags wrap around the <OPTION> tag to create a pop-up menu item for each record retrieved by the query named “ACTION”. Note: the menu does not do anything yet – we’ll cover that in the next chapter.

13.0 JavaScript JavaScript is a client-side programming language used to provide additional control and functionality of your web pages. The HTML <SCRIPT> tag identifies the portion of your HTML code that is reserved for writing JavaScript code. Consider the following…

<HTML> <HEAD>

<TITLE>Hello World</TITLE> </HEAD> <SCRIPT LANGUAGE=”JavaScript”> function helloWorld() { alert(“Hello World!”); } </SCRIPT> <BODY ONLOAD=”JavaScript:helloWorld();”> <CENTER> <H1>Hello World</H1> </CENTER> </BODY> </HTML>

20

Page 21: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

In the above example, note the syntax of the <SCRIPT> tag. Also note the function named helloWorld(). In JavaScript, the contents of a user-defined function begin and end with “{“ and “}”, respectively; statements end with semicolons; and function names, variables and more are case sensitive. The alert(“Hello World!”) portion displays a dialog box with a brief message. The message is activated automatically upon loading the Web page via the ONLOAD parameter within the <BODY> tag.

Now, let’s revisit our dynamic menu and add some JavaScript so that the menus actually do something…

<CFQUERY name="Action" datasource="AU"> SELECT * from MENU_CONFIG order by ACTION_SORT </CFQUERY> <HTML> <HEAD> <TITLE>Sample Dynamic Menu</TITLE> </HEAD> <SCRIPT LANGUAGE="JavaScript"> function doAction() {

var selOptions = document.Menu.Items.options; for (var i=0; i < selOptions.length; i++) {

var theValue = selOptions[i].value; if (selOptions[i].selected) {

eval(theValue);} }

} </SCRIPT> <BODY> <H1>Sample Dynamic Menu</H1> <FORM NAME="Menu"> <SELECT NAME="Items" SIZE="1" onChange="JavaScript:doAction();"> <CFOUTPUT QUERY=Action> <OPTION VALUE=#ACTION.Action_Code#>#ACTION.Action_Name# </CFOUTPUT> </SELECT> </FORM> </BODY> </HTML>

In the above example, the doAction() function steps through each option of the menu and determines if the option has been selected. If the option has been selected, the value of the option as set by the VALUE parameter and the <OPTION> tag is evaluated.

You can also use JavaScript to access your MapGuide map programmatically as shown in the next example. First, use the <OBJECT> tag as described previously to embed your map. Then create a function via JavaScript to create an instance of the map. The ONLOAD parameter and the alert() method is used within the <BODY> tag to show that an instance of the map has indeed been created.

Later, we will learn how to use the map instance for something more useful.

21

Page 22: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

<HTML> <HEAD>

<TITLE>Sample Map</TITLE> </HEAD> <SCRIPT LANGUAGE=”JavaScript”> function getMap() { return window.sampleMap; } </SCRIPT> <BODY onload=”JavaScript:alert(getMap());”> <CENTER> <H1>Sample Map</H1> <OBJECT ID=”sampleMap”

WIDTH=80% HEIGHT=80% CLASSID="CLSID:62789780-B744-11D0-986B-00609731A21D"> <PARAM NAME=”URL” VALUE=”http://www.myurl.com/maps/mymap.mwf”>

</OBJECT> </CENTER> </BODY> </HTML>

14.0 MapGuide API The MapGuide Application Programmer Interface (API) gives you programmatic access to the MapGuide Viewer and your maps. You use the MapGuide API to control user interaction with your maps and to extend out-of-the-box functionality. The API includes a variety of methods, properties and events. The following samples show you how you can use JavaScript together with the MapGuide API to perform some basic MapGuide Viewer tasks. (Remember to place these functions within the HTML <SCRIPT> tags.)

Count Map Layers

function countLayers() { var map = getMap(); var layers = map.getMapLayersEx(); var cnt = layers.size(); alert(“Number of layers: “ + cnt”); }

The above function first calls the getMap() function (the one we created earlier) to obtain an instance of the map; the instance of the map is stored in a variable named map. Next, the MapGuide Viewer API method getMapLayersEx() is used to return an MGCollection object that contains all of the layers defined in the map; the collection is stored in a variable named layers. The MGCollection size() method is used to obtain a count of the layers in the collection; the count is stored in the variable cnt. The result is displayed using the JavaScript alert() function.

22

Page 23: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

List Map Layers

function listLayers() {

var map = getMap(); var layers = map.getMapLayersEx(); var cnt = layers.size(); var msg = ""; for (i=0; i<cnt; i++) {

var layer = layers.item(i); msg = msg + layer.getName() + "\n";

} alert(msg);

}

This function expands on the countLayers() function by cycling through the layer collection to obtain layer names via a for loop. The item() API method selects a layer from the collection and stores the result in a variable named layer. Then the getName() API method is used to obtain the layer name; the layer name is stored in a variable named msg along with the previous value of msg and the new line character “\n”. The result is displayed using the JavaScript alert() function.

Toggle Map Layer On and Off

function toggleLayer(layerName) {

var map = getMap(); var layer = map.getMapLayer(layerName); if (layer == null)

alert("Layer " + layerName + " not found."); else {

layer.setVisibility(!layer.getVisibility()); map.refresh();

} }

This function accepts a single argument, layerName, which is passed to the getMapLayer() API method. The result is stored in the variable named layer. The setVisibility() method is used to toggle the layer on and off. The not operator “!” when used in conjunction with the getVisibility() function returns the opposite of the layer’s current state.

The following HTML code when inserted between the <BODY> tags is an example of how you can use the toggleLayer() function.

<FORM><INPUT TYPE=”button” VALUE=”Toggle Layer Streets” ONCLICK=”toggleLayer(‘Streets’);”></FORM>

Zoom to Map Object using Existing Zoom Goto Definition

function zoomTo(category, location, scale) { getMap().zoomGotoLocation(category,location,scale); }

This function accepts three arguments corresponding to the zoom goto category, location and scale. The zoomGotoLocation() method is then invoked to zoom to the indicated object.

23

Page 24: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

Zoom to Selected Map Objects

function zoomSelect() {

var map = getMap(); var selectObj = map.getSelection().getMapObjectsEx(null); if (selectObj.size()>0)

map.zoomSelected(); else

alert("No Objects were selected."); }

The getSelection() method returns a selection object which is passed to the getMapObjectsEx() method which returns objects in the current selection set; the result is stored in the variable named selectObj. The size method is then used to determine the number of objects that were selected. If at least one object is selected, the zoomSelected() method is invoked which results in the map zooming to the selected objects.

15.0 More MapGuide API Examples Delete Selected Layer

function deleteSelectedLayer() {

var map = getMap(); var selectObj = map.getSelection().getMapObjectsEx(null); if (selectObj.size()==1) {

var lay=selectObj.item(0).getMapLayer().getName(); map.removeMapLayer(lay);

} else alert("Select one and only one object on layer that is to be removed.");

} Compute Length of Selected Object

function getTotalLength() {

var map = getMap(); var selectObj = map.getSelection().getMapObjectsEx(null); var cnt=selectObj.size(); if (cnt>0) {

var myLength=0.0; for (i=0; i<cnt; i++) {

var myObj=selectObj.item(i); myLength=myLength+myObj.getLength();

} myLength=myLength * map.getMCSScaleFactor(); alert("Total length of selected line objects:\n" + Math.ceil(myLength) + " m.");

} else

alert("No Objects were selected."); }

24

Page 25: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

Compute Area of Selected Object

function getTotalArea() {

var map = getMap(); var selectObj = map.getSelection().getMapObjectsEx(null); var cnt=selectObj.size(); if (cnt>0) {

var myArea=0.0; for (i=0; i<cnt; i++) {

var myObj=selectObj.item(i); myArea=myArea+myObj.getArea();

} myArea=myArea * map.getMCSScaleFactor() * map.getMCSScaleFactor(); alert("Total area of selected polygon objects:\n" + Math.ceil(myArea) + " sq.m.");

} else

alert("No Objects were selected."); }

View Object Coordinates

function getVertexInfo() {

var map = getMap(); var selectObj = map.getSelection().getMapObjectsEx(null); // Make sure just one is selected if (selectObj.size() != 1)

alert ("Please select one, and only one, feature."); else {

// Create collections to hold vertex info verts = map.createObject('MGCollection'); vertNum = map.createObject('MGCollection'); // Get vertices of first (and only) item in selected collection result = selectObj.item(0).getVertices(verts, vertNum); // Display results if (result == 0)

alert ("Unable to access feature's coordinate information"); if (result == 1) {

var msg="This is a polyline, polygon, point, or text feature.\n\n"; showVertex(verts,vertNum,msg);

} if (result > 1) {

var msg="This is a poly-polyline or poly-polygon.\n\n"; showVertex(verts,vertNum,msg);

} }

}

25

Page 26: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide® Michael Schlosser

// This function displays the first few coordinates of the specified // object. The number of coordinates displayed is indicated by variable vmax. function showVertex(vlist,vnum,msg) {

var vmax=40; var cmax=0; var cnt=vnum.size(); for (i=0; i<cnt; i++) {

var cnt2=vnum.item(i); for (j=0; j<cnt2; j++) {

if (cmax<vmax) {

var pointObj=vlist.item(j); var msg=msg + (i+1) + "-" + (j+1) + ": " var msg=msg + pointObj.getX()+ " , " + pointObj.getY() + "\n"; var cmax=cmax+1;

} else {

var j=cnt2; var i=cnt; msg=msg + ".\n.\n."; }

} var msg=msg + "\n";

} alert(msg);

}

Launch Report Via Double-click Event

<HTML> <HEAD><TITLE>Map</TITLE></HEAD> <SCRIPT language="VBScript">

Sub sampleMap_onDoubleClickObject (obj) launchReport obj

End Sub </SCRIPT> < SCRIPT language="JavaScript">

function getMap() {

return sampleMap } function launchReport (obj) {

getMap().viewReport("SampleReport"); }

</ SCRIPT > <BODY> - - </BODY> </HTML>

26

Page 27: How to Create Custom Applications using Autodesk MapGuide® · examples to discuss the MapGuide API, ColdFusion, HTML, JavaScript, and a variety of MapGuide-related application development

How to Create Custom Applications Using Autodesk MapGuide Michael Schlosser

Draw Redline via Digitize Polygon Event

<HTML> <HEAD><TITLE>Map</TITLE></HEAD> <SCRIPT language="VBScript">

Sub sampleMap_onDigitizedPolygon (map, numPoints, points) digitizeRedlinePolygon map,numPoints,points

End Sub </ SCRIPT > < SCRIPT language="JavaScript"> function getMap() {

return sampleMap; } function createRedlinePolygon() {

getMap().digitizePolygon(); } function digitizeRedlinePolygon (map,numPoints,points) {

var myLayer=map.getMapLayer("MarkupPolygon"); if (myLayer == null)

myLayer = map.createLayer("Redline","MarkupPolygon");

var myRedline=map.getRedlineSetup();

var myEdge=myRedline.getEdgeAttr(); myEdge.setColor(5); myEdge.setStyle("Solid"); myEdge.setThickness(4); myEdge.setVisible("true"); var myFill=myRedline.getFillAttr(); myFill.setBackColor(0); myFill.setBackMode("Transparent"); myFill.setColor(6); myFill.setStyle("DiagonalCross");

var obj=myLayer.getMapObject("MarkupPolygon"); if (obj == null)

var obj=myLayer.createMapObject("MarkupPolygon","MarkupPolygon",""); var user_vertices=map.createObject("mgcollection"); user_vertices.add(numPoints); obj.addPolygonPrimitive(points, user_vertices,false);

} - -

16.0 Live Demo: Putting it all Together A live demonstration is used to develop a MapGuide application using the concepts and techniques discussed above.

27


Recommended