Practical Introduction to MapGuide

Tom Fukushima FOSS4G 2008 Cape Town, South Africa October 3, 2008

1 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 2 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 3 What is MapGuide?

Open Source web-based geospatial platform

• Dynamic data visualization • Feature selection and attribute display • Uniform data query and update • Geometric analysis • Comprehensive API • Support for Open Geospatial Consortium standards • Support for Google Earth

© 2006 Autodesk 4 Historical Context

© 2006 Autodesk 5 Project Goals and Players

Mission: To provide an all in one web-based platform that enables users to quickly develop and deploy applications and geospatial web services.

Project Goals: Players:  easy to configure, deploy, and manage  Autodesk, Inc.  fast, scalable, and cross platform  DM Solutions Group  support rich access to spatial data both  Spatial Integrators, Inc. vector and raster  SL-King Spatial Solutions  provide a full suite of spatial analysis  GEOGRAF A/S  produce visually stunning cartographic maps  provide the highest degree of map interactivity possible  support open standards

© 2006 Autodesk 6 Backend Features

• Fast, Scalable, Secure • Fully multi-threaded and takes Server Platform advantage of multi-core / multi- processor technology • Support for load balancing multiple servers to improve scalability • Apache mod and ISAPI extensions • Database connection pooling • Map tile caching • Connection-oriented, access-based security • Configurable logging • Web-based site administration allows remote server configuration, and log file access

© 2006 Autodesk 7 Backend Features

• Fast, Scalable, Secure •Provides hierarchical storage of Server Platform XML resource documents that define maps, layers, data • Built-in Resource Database connections, symbology, and for Manageability viewer layout •Allows you to define data sources and layers once and then reference them from multiple maps •Provides an access-based security model with inheritable permissions •Permits metadata and binary data to be associated with resource documents

© 2006 Autodesk 8 Backend Features

• Fast, Scalable, Secure •Use of the Feature Data Objects Server Platform (FDO) API for vector and raster • Built-in Resource Database feature data access for Manageability  ESRI SHP and SDF vector file formats  PostGIS, Oracle, SQL Server, ESRI ArcSDE, MySQL, and ODBC database • Uniform Data Access formats  Other vector formats via OGR  Raster file formats via GDAL  OGC WMS and WFS

•Use of DWF for CAD-based data access

© 2006 Autodesk 9 Backend Features

• Fast, Scalable, Secure • Create, query, read, and write Server Platform resource documents • Query and update feature data • Built-in Resource Database • Perform coordinate re-projection and for Manageability great circle distance computation • Uniform Data Access • Create, manipulate, and analyze geometry with support for spatial • Extensive Server-Side predicates based on the DE-9IM model, overlay functions (intersection, union, difference, symmetric difference), buffer, convex hull, area, and distance functions • Produce stylized vector and raster maps and legends • Manipulate runtime maps and layers

© 2006 Autodesk 10 Backend Features

• Fast, Scalable, Secure •Extensive support for defining Server Platform custom data-driven symbology for Points, Lines, and Fills • Built-in Resource Database •Scale-dependent detail for Manageability •Rule-driven thematic layer • Uniform Data Access stylization • Extensive Server-Side APIs •Dynamic labeling with overpost detection, labels that follow the • Quality Cartographic path of a line, and automatic Output label resizing •Anti-aliased image rendering using AGG •True color support •TrueType font support

© 2006 Autodesk 11 Frontend Features

• Highly Interactive and •Uses template driven Fusion Flexible AJAX Viewer technology with Open Layers •Allows feature selection by point, rectangle, radius, or polygon •Displays feature properties in multi-line tool tips •Displays properties of the selected feature in a property browser panel •Supports feature buffering, query within polygon, distance measuring tools •Provides printing and plotting support

© 2006 Autodesk 12 Frontend Features

• Highly Interactive and •Support for Web Map Service Flexible AJAX Viewer Specification • No SLD support • Limited Support for OGC •Support for Web Feature Service Standards Specification • No WFS/T

© 2006 Autodesk 13 Frontend Features

• Highly Interactive and •Supports dynamic generation of Flexible AJAX Viewer KML/KMZ via 3 CGI operations • GetMapKml • Limited Support for OGC • GetLayerKml Standards • GetFeaturesKml • Support for Google Earth •Can be used directly in Google Earth via Network Links

© 2006 Autodesk 14 Frontend Features

• Highly Interactive and Flexible AJAX Viewer • Limited Support for OGC Standards • Support for Google Earth • Maestro Map Authoring Application

© 2006 Autodesk 15 Creating a MapGuide Web Application MapGuide applications are defined in terms of XML documents called resources

Web Layout Define application functionality and layout

Map Definition Combine layers to make a map

Layer Definition Define the presentation of a feature class

Data Connection Define connections to data files / databases

© 2006 Autodesk 16 MapGuide components

© 2006 Autodesk 17 MapGuide supported configurations

Windows only © 2006 Autodesk 18 Application Development

Web tier • PHP, ASP.NET or Java/JSP • A rich API that is 100% identical in all three programming languages

Client tier • CSS to separate presentation from contents • JavaScript API that allows manipulation of the viewer and supports interaction with the map (e.g. selection, digitize operations, etc).

© 2006 Autodesk 19 Application Interaction Command invocation results in Web Browser HTTP Get or Post request that MapGuide Viewer executes server-side page logic. Application HTML + DWF HTML or Web Server HTML + Image(s) Web Application

PHP/ASP.NET/JSP Page Logic MapGuide Site HTTP MapGuide API Resource Service

MapGuide MapAgent TCP/IP Feature Service

Drawing Server-side page Service

Response may includelogic may new call any Mapping Service HTML for displaynumber in a frame, of MapGuide APIs to query data, client-side script, XML or text for Rendering AJAX clients, or a combination.change layer Service visibility, create new Tile data and/or layers, Service etc.

© 2006 Autodesk 20 Server-Side APIs

System data types thatServices enable thatcommon perform Runtime objects for APIs inserver-side different data analysis, operationslanguages. such as transformation,data query, update, and System mapand viewmap updates.rendering. Runtime Services

© 2006 Autodesk 21 Questions?

© 2006 Autodesk 22 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 23 Install from c:\mgos\Software…

MapGuide Open Source Server • Run MgServerSetup-2.0.2.3006.exe • Use defaults for everything

MapGuide Open Source Web Tier • Run MgWebServerExtensionsSetup-2.0.2.3006.exe • Use defaults for everything • Open http://localhost:8008 in your web browser

Maestro • Run MapGuide Maestro 1.0.9.msi • Use defaults for everything

© 2006 Autodesk 24 Verify install

To quickly verify the install • Start > All Programs > MapGuide Maestro • Change server to http://localhost:8008/mapguide/mapagent/mapagent.fcgi

• Press OK to connect

© 2006 Autodesk 25 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 26 Server Admin pages

Point your browser at http://localhost:8008/mapguide/mapadmin/login.

Default credentials for administrator/root: Username: Administrator Password: admin

Demo…

© 2006 Autodesk 27 Exercise 1: Load the Redding package

1. Copy c:\mgos\Data\Redding.mgp to C:\Program Files\MapGuideOpenSource2.0\Server\Packages 2. Start up the Server Admin pages 3. Select “Manage Packages” 4. Load the package

© 2006 Autodesk 28 Exercise 2: Add an alias for external files 1. Bring up the Server Admin pages 2. Select “Add Alias” under “Configure External Files” 3. Alias Name: ReddingData 4. Path to External Folder: C:\mgos\Data\Redding 5. Press Save 6. Restart the Server service

© 2006 Autodesk 29 Questions?

© 2006 Autodesk 30 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 31 Publishing a Map

Goal: Publish a Redding map that has roads and hospitals

© 2006 Autodesk 32 Publishing a Map: Data

Goal: Publish a Redding map that has roads and hospitals

© 2006 Autodesk 33 Exercise 3: Create a feature source

• Start Maestro and connect • Create a new folder in the site and call it MyRedding • Create a Dataconnection and select the SHP provider • In the SHP feature source editor, select “File on the server (Unmanaged)” • Browse and select the “City_Boundary.shp” file • Save the feature source and call it “City boundary” in he MyRedding folder

© 2006 Autodesk 34 Publishing a Map: Layer

Goal: Publish a Redding map that has roads and hospitals

© 2006 Autodesk 35 Exercise 4: Create a layer

• In Maestro create layer • In the layer editor select the City Boundary feature source • Preview the layer • Style the layer to have a “no fill” • Save the layer and call it City Boundary in the MyRedding folder

© 2006 Autodesk 36 Publishing a Map: Map

Goal: Publish a Redding map that has roads and hospitals

© 2006 Autodesk 37 Exercise 5: Create a map

• In Maestro create a map • Add the layer City Boundary to the map • “Set view to current layer extents” • Set the coordinate system • Save the map as Redding in the MyRedding folder

© 2006 Autodesk 38 Publishing a Map: Layout

Goal: Publish a Redding map that has roads and hospitals

© 2006 Autodesk 39 Exercise 6: Create a layout

• In Maestro create a layout • Set the Map Resource to be the Redding map • Save the layout as Redding in the MyRedding folder • Click “View in Browser” and try out your application

© 2006 Autodesk 40 Exercise 7: Roads

Add the roads data (Roads.shp) to our map • Bonus: Label the roads with the road name (ST_NAME) • Bonus: Use ST_TYPE to style FWY and HWY differently • Bonus: Only show the roads when zoomed into scales larger than 1:20,000 • Bonus: Make it so that roads are selectable and that all the properties are shown

© 2006 Autodesk 41 Exercise 8: Hospitals

Add the hospitals data (Hospital.shp) to our map • Label the hospitals with their names • Bonus: Show the hospital as a red cross • Bonus: Make sure the cross is centered over the location of the hospital

© 2006 Autodesk 42 Exercise 9: Drawing order

Make the fill of the City boundary layer a light grey color Bonus: Fix any draw order problems

© 2006 Autodesk 43 Demo

Look at the Redding package that we loaded earlier

© 2006 Autodesk 44 Resource Database => Manageability

• Provides storage for resource XML documents that define maps, layers, data connections, symbology, viewer appearance, etc.

• Allows you to define data sources and layers once and reuse them in multiple maps / applications

• Provides an access based security model

• Permits metadata to be associated with each resource

© 2006 Autodesk 45 Resource Types, References, and Data

© 2006 Autodesk 46 Uniform Data Access with FDO

Mainstream GIS Applications Business Applications

FDO API (C++ and .Net)

FDO Registry Provider FDO Providers FDO Schema Manager Access Registry Vector file format Raster file format Relational Database Web Services Providers Providers Providers Providers

VanBuren Jetson Berry Runner Tomato Franklin Warren Lang Campbell` BananaCarrot Apple Lincoln Regan Peach Beet Carter Bradshaw Clinton Pear Grape JacksonJefferson Orange Fraiser Plum WilsonKennedy MillerArmeyBaker DiegoHarvard RooseveltFord Dartmouth Adams VarneyJonesSmith Zoe YaleCornellMerrit WashingtonTrumanEisenhower

WFS WMS

© 2006 Autodesk 47 FDO Providers

Vector File Format Providers  SDF, ESRI SHP, OGR (20+ data formats) Raster File Format Providers  GDAL (50+ formats) Relational Database Providers  ODBC, Oracle, SQL Server, PostGIS, OGR Web Service Providers  OGC WMS, WFS

© 2006 Autodesk 48 Drawing source

• Use DWF to display already-styled data • Maestro does not have an interface for this yet

© 2006 Autodesk 49 Fusion layouts

• Open source project from DM Solutions Group • Support for all major browsers on Windows, Mac and • Support added in MapGuide Open Source 2.0 • Uses CSS to make highly configurable UI • Templates to define the look • Widgets for functionality

© 2006 Autodesk 50 Questions?

© 2006 Autodesk 51 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 52 Applications

• Create, manipulate and analyze • Built-in analysis • Building your own • Viewer API • Server-side API

© 2006 Autodesk 53 Built-in analysis

• Measure distance • Buffer • Search

© 2006 Autodesk 54 Application Development Tools and Technologies

 MapGuide applications are developed in the web-tier using PHP, ASP.NET or Java/JSP technologies and in the client-tier using JavaScript.

 At the web-tier MapGuide exposes a rich API that is 100% identical in all three programming languages, allowing developers to choose the platform they are most comfortable with.

 At the client-tier MapGuide exposes a viewer agnostic JavaScript API that allows manipulation of the viewer and supports interaction with the map (e.g. selection, digitize operations, etc).

© 2006 Autodesk 55 Application Structure and Interaction

Command invocation results in Web Browser HTTP Get or Post request that MapGuide Viewer executes server-side page logic. Application HTML + DWF HTML or Web Server HTML + Image(s) Web Application

PHP/ASP.NET/JSP Page Logic MapGuide Site HTTP MapGuide API Resource Service

MapGuide MapAgent TCP/IP Feature Service

Drawing Server-side page Service

Response may includelogic may new call any Mapping Service HTML for displaynumber in a frame, of MapGuide APIs to query data, client-side script, XML for AJAX Rendering clients, or a combination.change layer Service visibility, create new Tile data and/or layers, Service etc.

© 2006 Autodesk 56 Exercise 10: Hello World

1. Create a PHP page on the server that displays Hello World Hello World! 2. Save the file as C:\Program Files\MapGuideOpenSource2.0\WebServerExtensions\ www\myscripts\HelloWorld.php 3. Quick test by browsing to http://localhost:8008/mapguide/myscripts/HelloWorld.php

© 2006 Autodesk 57 Exercise 10: Hello World (cont)

4. Start up Maestro and connect 5. Edit the Redding basic layout 6. Click on the Task frame menu 7. Create a new Custom command and select Invoke URL 8. Add the new Invoke URL command to the task frame

© 2006 Autodesk 58 Exercise 10: Hello World (cont)

9. Click on the Extra properties tab 10.Enter ../myscripts/HelloWorld.php as the URL 11.Preview the layout 12.Select the Tasks drop down and select Invoke URL

© 2006 Autodesk 59 MapGuide Web API - Overview

System data types that enableServices common that perform Runtime objects for APIs in differentserver-side data analysis, languages.operations such as transformation, and System data query, update, mapand viewmap updates.rendering. Runtime Services

© 2006 Autodesk 60 The Library and Session Repositories

Two distinct types of Resource Repositories exist in MapGuide Open Source:

 The Library repository is shared by all users and stores resource documents for an indefinite period of time.  MapGuide Web Studio creates, edits, and manages resources in the Library repository.

 The Session repository stores transient resources that exist only for the lifetime of a client session.  A unique session repository is created for client session and only that client may access it.  When the client session ends that sessions repository is deleted along with its content.

© 2006 Autodesk 61 Resource Identifiers

A Resource Identifier specifies the location, name, and type of a resource or folder. RepositoryType:[RepositoryName]// [ResourcePath/][ResourceName.ResourceType]

Examples:

 Library://MyStuff/MyLayer.LayerDefinition

 Session:{SessionId}//MyTempLayer.LayerDefinition

 Library://MyFolder/ Replace with Unique Session Identifier Trailing Slash is Required!

© 2006 Autodesk 62 Exercise 11: Road report

Use the Web API to show the length of the selected roads. 1.Copy the C:\mgos\Exercise\11\RoadReport.php page to your myscripts directory 2.Create an Invoke URL command for this script in the Redding layout  Add an additional URL parameter with Key=Selection and Value=$CurrentSelection 3.Execute the script and see what it does 4.Modify the script so that it calculates the length of the roads

© 2006 Autodesk 63 Exercise 12: Generic tasks

Goal: to install and use some generic tasks 1. Copy the C:\mgos\Apps\phpgenerictasks directory to the MapGuide web tier www directory (the same directory where your myscripts directory is) 2. In Maestro, open the Library://Redding/Layouts/ReddingPhp layout and preview it 3. Try the Query, Theme and Markup tasks

© 2006 Autodesk 64 Exercise 13: Manipulating data

Use the Web API to delete the selected roads. 1.Copy the C:\mgos\Exercise13\RoadDeleter.php page to your myscripts directory 2.Create an Invoke URL command for this script in the Redding layout 3.Execute the script and see what it does 4.Modify the script and move the commented out “delete” code at the top of the file to the right spot. 5.Test it out and see what it does

© 2006 Autodesk 65 Basic Viewer Structure

© 2006 Autodesk 66 MapGuide Basic Viewer API - Overview

 Main Frame  Provides named access to all other frames.  Supports command execution  Map Frame  Access to Map and Display information.  Get / Set / Clear selection.  Operations for digitizing geometry.  Zoom to view and refresh map content.  Coordinate display control and Lat/Lon conversion.  Legend / Property / Toolbar / Status Frames  Access to model and user interface elements.

© 2006 Autodesk 67 Exercise 14: Refreshing the map

The RoadDeleter.php file does not refresh the map after the road is deleted. • Modify the RoadDeleter.php file so that it refreshes the map. • One way to do this is to add the line parent.parent.Refresh(); to the code. (This is a Viewer API.)

© 2006 Autodesk 68 Demo

Lightweight editing application in Fusion

© 2006 Autodesk 69 Workshop Outline

 Introduction  MapGuide Open Source overview  Install MapGuide Open Source  Administration/system configuration  Publishing a map  Creating an application

© 2006 Autodesk 70 Questions?

© 2006 Autodesk 71