Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Maps in VFP
Message
De
02/07/2007 07:00:27
 
 
À
01/07/2007 22:33:43
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Divers
Thread ID:
01237073
Message ID:
01237097
Vues:
19
Any way to display a map in VFP and call a method if user clicks in the given area (polygonal).
Any third party utility to do the same


Here is some sample code for automating Map Point. All you need to do is create a VFP Handler class that implements the correct interface in Map Point and write some code in the approriate method to handle what happen when the user clicks on the map. See DEFINE CLASS and EVENTHANDLER() in the on-line help for a more complete explanation on how to do the event binding.
*** Instantiate the Mappoint Application
loMP = CREATEOBJECT('MapPoint.Application')

*** Create a new map
loMap = loMP.NewMap()

********************************************************************
*** Create a route from One Point to Another
********************************************************************
*** Set the start point and create a pushpin for it
loStart = loMap.FindAddress( "555 Westminster Circle", "Akron", "OH")
loStartPin = lomap.AddPushpin( loStart.Location, 'Home' )
*** Make the pushpin visible and add it to the route
loStartPin.BalloonState= 2 
loMap.ActiveRoute.Waypoints.Add( loStartPin )
loEnd = loMap.FindAddress( "23905 Woodway Road", "Beachwood", "OH")
loEndPin = loMap.AddPushpin( loEnd.Location, "Nancy's House" )
*** Make the pushpin visible and add it to the route
loEndPin.BalloonState= 2 
loMap.ActiveRoute.Waypoints.Add( loEndPin )
*** Add another Waypoint - by place name, not address
loLannings = loMap.FindPlaceResults( 'Lannings Restaurant' )
*** Did we find anything
IF loLannings.Count = 0
  MESSAGEBOX( "Could not find 'Lannings'" )
ELSE
  *** Enumerate what we found...
  llFound = .F.
  FOR lnCnt = 1 TO loLannings.count
    loItem = loLannings.Item[lnCnt]
    loAddr = loItem.StreetAddress
    IF UPPER( ALLTRIM( loAddr.City )) == "AKRON"
      *** This is the right city, but what about the state
      IF ALLTRIM( GETWORDNUM( loAddr.Value, 3, ',' )) = "OH"
        *** It's the one we want!
        llFound = .T.
        EXIT
      ENDIF
    ENDIF
  NEXT
  *** If we found the place add it as a waypoint
  IF llFound
    loEatPin = lomap.AddPushpin( loItem.Location, 'Lannings' )
    *** Make the pushpin visible and add it to the route
    loEatPin.BalloonState= 2 
    *** Note, this adds the waypoint to the END of the existing route
    loStop = loMap.ActiveRoute.Waypoints.Add( loItem.Location, 'Lannings' )
    *** Now let map point know that we are stopping 2 hours for
    *** a liesurely lunch - times are in parts of a day between 0 and 1
    loStop.StopTime = 1/12
  ENDIF
ENDIF

*** Add another stop - you need at least 4 stops to
*** optimize the route
loAirport = loMap.FindPlaceResults( 'Cleveland-Hopkins International Airport' )
loItem = loAirport.Item[ 1 ]
loFlyPin = lomap.AddPushpin( loItem.Location, 'Airport' )
*** Make the pushpin visible and add it to the route
loFlyPin.BalloonState= 2 
*** Note, this adds the waypoint to the END of the existing route
loMap.ActiveRoute.Waypoints.Add( loFlyPin )
*** We are starting the trip at 12:30 PM on March 3rd
loFirstStop = loMap.ActiveRoute.Waypoints[ 1 ]
loFirstStop.PreferredDeparture = {^2006-03-03 12:30:00} 
*** Now we want to opttimize the route and re-calculate it
loMap.ActiveRoute.Waypoints.Optimize()
loMap.ActiveRoute.Calculate() 
*** Print the directions
loWord = CREATEOBJECT( [Word.application] )
loDoc = loWord.Documents.Add()
loWord.DisplayAlerts = 0  && wdAlertsNone 
loMap.CopyMap()
loWord.Selection.Paste()
loMap.CopyDirections()
loWord.Selection.Endkey( 6 )
loWord.Selection.Paste()

*** Make word visible so we can see the result
loWord.Visible = .T.
lnDist = lomap.ActiveRoute.Distance     && This is in Miles by default
lnTim = lomap.ActiveRoute.DrivingTime  && This is in Days
lnTim = INT( lnTim * 24 * 60 )

*** Fool Mappoint into thinking the map was saved
*** so that we do not get locked up because of the
*** invisible save dialog
loMap.Saved = .T.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform