260 likes | 460 Views
PWB 505: Using MS MapPoint in PowerBuilder. Arthur Hefti CEO arthur@catsoft.ch 17. August 2004. Content Overview. Speaker introduction Why GIS data MS MapPoint control in PowerBuilder OLE automation with MS MapPoint Presentation of a service application. Speaker Introduction.
E N D
PWB 505: Using MS MapPoint in PowerBuilder Arthur Hefti CEO arthur@catsoft.ch 17. August 2004
Content Overview • Speaker introduction • Why GIS data • MS MapPoint control in PowerBuilder • OLE automation with MS MapPoint • Presentation of a service application
Speaker Introduction • Arthur Hefti • PowerBuilder developer since 1993 • CPD Professional, CP Instructor • President Swiss PowerBuilder User Group for 5 years • CEO of CATsoft Development GmbH, Zurich, Switzerland • Custom made software development and consulting • Client / Server and Web • Web: http://www.catsoft.net or http://www.catsoft.ch • Email: arthur@catsoft.ch
Why GIS Data • Planning a route • Service technician • Sales person • Tracking position • Delivery of goods • Driving instructions • Detailed directions
Important Objects • MapPoint control • Map object • Pushpins • Route • Directions • WayPoints • DataSet • FindResults collection • Location object
MapPoint Control • Window painter ► Insert Control ► OLE ...
Loading Map Data • Load the map into the control ioo_Map = ole_Map.Object.NewMap( 2 ) // 1 = North America, 2 = Europe • Unload at the end • ole_Map.Object.CloseMap()
Finding Locations • Find the location • Returns a collection of locations including quality of the result loo_Found = ioo_Map.FindAddressResults( <Street>, <City>, <Othercity>, & <Region>, <Zip>, <Country> ) IF loo_Found.ResultsQuality = 1 /*geoFindResultGood*/ THEN loo_Location = loo_Found.Item(1) ELSE // Let the user manually select one location ..... • Add pushpins loo_Pin = ioo_Map.AddPushpin( loo_Location, “Pushpin 1” )
Working With DataSets And Pushpins • Pushpins are added to the „My Pushpins“ set loo_Pin = ioo_Map.AddPushpin( loo_Location, “Pushpin 1” ) • Create your own set ioo_Tour = ioo_Map.DataSets.AddPushPinSet( "MyTour" ) • Move pushpins between DataSets loo_Pin.MoveTo( ioo_Tour ) • DataSets allow to access groups of data ioo_Tour.FieldNamesVisibleInBalloon = TRUE
The Route • Get route object and reset it ioo_Route = ioo_Map.ActiveRoute loo_Route.Clear() • Get waypoint object and add pushpins loo_WayPoints = loo_Route.WayPoints loo_WayPoints.Add( loo_Pin1 ) loo_WayPoints.Add( loo_Pin2 ) • Draw the route Ioo_Route.Calculate()
User Interaction With The Map • Default behavior • Allow or overwrite • Events • Notification of Map Control • Methods • Managing the Map Control
Default Behavior • Right mouse button menu • Zoom • Export to Excel • Route creation • Show Pushpin Information • Left mouse button • Moving of Pushpins • Scrolling the map • Mouse wheel • Zoom
Events • Various events for interaction and state changes • Most important events for user interaction • beforeclick: Display some information about clicked object(s) • beforedblclick: Execute some action • mousedown: Save mouse pointer position • Other events • afterredraw • routeaftercalculate
Methods • Opening map data • NewMap() • Loading and saving maps • OpenMap() • SaveMap() • Closing • CloseMap()
OLE Automation With MapPoint • Used if no visual part is needed • Calculation of distance or driving time • Getting directions
Preparing The Map • Creating a new instance OleObject ioo_App, ioo_Map ioo_App = CREATE OleObject ioo_App.ConnectToNewObject( "MapPoint.Application" ) • Get active map ioo_Map = ioo_App.ActiveMap
Calculate Distance And Driving Time • Initialize route • Create route • Calculate the route • Return distance
Initialize Route • Initialize route loo_Route = ioo_Map.ActiveRoute loo_Route.Clear() loo_WayPoints = loo_Route.WayPoints
Create Route • Find the location • Returns a collection of locations including quality of the result loo_Found = ioo_Map.FindAddressResults( ls_Street, ls_City, "", ls_Region, & ls_PostalCode, ll_CountryCode ) IF loo_Found.ResultsQuality = 1 /*geoFindResultGood*/ THEN loo_Location = loo_Found.Item(1) ... • Add pushpins loo_Pin = ioo_Map.AddPushpin( loo_Location, "Item" + String( li_Counter ) ) loo_WayPoints.Add( loo_Pin )
Calculate The Route • Calculate and catch a possible runtime error TRY loo_Route.Calculate() CATCH (OLERuntimeError err) MessageBox( “Error”, “Calculating Route”, StopSign! ) END TRY
Get Distance Or Driving Time • Create route ll_Distance = loo_Route.Distance ll_DrivingTime = Long( loo_Route.DrivingTime * 24 * 60 )
Get Directions • Create and calculate route • Same as for getting distance and driving time • Get all direction information loo_Directions = loo_Route.Directions FOR li_Counter = 1 TO loo_Directions.Count loo_DirectionEntry = looDirections.Item( li_Counter ) ls_Dir = ls_Dir + loo_DirectionEntry.Instruction + Char(13) + Char(10) NEXT
Key Figures For Demo Application • Application is used in service company • 2200 places to visit by 35 technicans in peak month • 1200 places and 10 technicans planned at the same time • Used in different locations across Switzerland • Runing in LAN and on Citrix