示例#1
0
    /*
    *********************************************************************************************************
    *                                              GetRouteFromGps()
    *
    * Description : Cette fonction effectue le trajet de génère la carte en bitmap
    *
    * Argument(s) : OrigLat         Coordonnée GPS Latitude du point d'origine
    *               OrigLong        Coordonnée GPS Longitude du point d'origine
    *               DestLat         Coordonnée GPS Latitude du point de destination
    *               DestLong        Coordonnée GPS Longitude du point de destination
    * 
    *********************************************************************************************************
    */
    public static MemoryStream GetRouteFromGps(double OrigLat, double OrigLong, double DestLat, double DestLong)
    {
        Location LocDepart = new Location();
        LocDepart.LatLong = new LatLong();
        LocDepart.LatLong.Latitude = OrigLat;
        LocDepart.LatLong.Longitude = OrigLong;

        Location LocArrivee = new Location();
        LocArrivee.LatLong = new LatLong();
        LocArrivee.LatLong.Latitude = DestLat;
        LocArrivee.LatLong.Longitude = DestLong;

        SegmentSpecification[] routeSegment;
        routeSegment = new SegmentSpecification[2];

        routeSegment[0] = new SegmentSpecification();
        routeSegment[0].Waypoint = new Waypoint();
        routeSegment[0].Waypoint.Name = "Depart";
        routeSegment[0].Waypoint.Location = LocDepart;

        routeSegment[1] = new SegmentSpecification();
        routeSegment[1].Waypoint = new Waypoint();
        routeSegment[1].Waypoint.Name = "Arrivee";
        routeSegment[1].Waypoint.Location = LocArrivee;


        RouteSpecification routeSpecs = new RouteSpecification();
        routeSpecs.DataSourceName = "MapPoint.NA";
        routeSpecs.Segments = routeSegment;
 
        RouteServiceSoap routeService = new RouteServiceSoap();
        routeService.Credentials = new System.Net.NetworkCredential("124624", "PDALE_projets5");
        routeService.PreAuthenticate = true;
        // routeService.Proxy = myProxy;

        Route route = new Route();
        route = routeService.CalculateRoute(routeSpecs);

        // Generate the Route Map
        MapSpecification mapSpec = new MapSpecification();
        mapSpec.Options = new MapOptions();
        mapSpec.Options.Format = new ImageFormat();

        //Set the map width and height 
        //according to the PictureBox
        mapSpec.Options.Format.Height = 248;
        mapSpec.Options.Format.Width = 240;

        //Set the Map Datasource
        mapSpec.DataSourceName = "MapPoint.NA"; ;

        mapSpec.Route = route;

        MemoryStream stream;

        // Get the map image
        RenderServiceSoap renderService = new RenderServiceSoap();
        renderService.Credentials = new System.Net.NetworkCredential("124624", "PDALE_projets5");
        MapImage tempImage = renderService.GetMap(mapSpec)[0];

        Bitmap myMap = new Bitmap(new MemoryStream(tempImage.MimeData.Bits, false), true);

        stream = new MemoryStream();
        myMap.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);

        return stream;

        //System.Threading.Thread.Sleep(1000);
        //System.Diagnostics.Process.Start("c:\\map\\bmpcvt.exe","c:\\map\\map.bmp -convertintobestpalette -saveasmap,3 -exit");
        //System.Diagnostics.Process.Start("c:\\map\\bmpcvt.exe", "c:\\map\\map.bmp -convertintobestpalette -saveasc:\\map\\toto.c,1 -exit");
        //stsMain.Text = "Done";//BmpCvt logo.bmp -convertintobestpalette -saveaslogo,1 -exit

    }
示例#2
0
    //GetRoute:Calculates the Route and 
    //also generates the Map
    /*
    *********************************************************************************************************
    *                                              GetRoute()
    *
    * Description : Cette fonction effectue le trajet et génère la carte dans un fichier bitmap.
    *
    * Argument(s) : sResults        Le résultat de la recherche fait par MapPoint pour l'adresse de départ
    *               eResults        Le résultat de la recherche fait par MapPoint pour l'adresse de destination
    * 
    *********************************************************************************************************
    */
    public static void GetRoute(FindResults sResults, FindResults eResults)
    {
        SegmentSpecification[] routeSegment;
        routeSegment = new SegmentSpecification[2];

        routeSegment[0] = new SegmentSpecification();
        routeSegment[0].Waypoint = new Waypoint();
        routeSegment[0].Waypoint.Name = sResults.Results[0].FoundLocation.Entity.Name;
        routeSegment[0].Waypoint.Location = sResults.Results[0].FoundLocation;

        routeSegment[1] = new SegmentSpecification();
        routeSegment[1].Waypoint = new Waypoint();
        routeSegment[1].Waypoint.Name = eResults.Results[0].FoundLocation.Entity.Name;
        routeSegment[1].Waypoint.Location = eResults.Results[0].FoundLocation;


        RouteSpecification routeSpecs = new RouteSpecification();
        routeSpecs.DataSourceName = "MapPoint.NA";
        routeSpecs.Segments = routeSegment;

        RouteServiceSoap routeService = new RouteServiceSoap();
        routeService.Credentials = new System.Net.NetworkCredential("124624", "PDALE_projets5");
        routeService.PreAuthenticate = true;
        // routeService.Proxy = myProxy;

        Route route = new Route();
        route = routeService.CalculateRoute(routeSpecs);

        // Generate the Route Map
        MapSpecification mapSpec = new MapSpecification();
        mapSpec.Options = new MapOptions();
        mapSpec.Options.Format = new ImageFormat();

        //Set the map width and height 
        //according to the PictureBox
        mapSpec.Options.Format.Height = 260;
        mapSpec.Options.Format.Width = 240;

        //Set the Map Datasource
        mapSpec.DataSourceName = "MapPoint.NA";

        mapSpec.Route = route;

        try
        {
            // Get the map image
            RenderServiceSoap renderService = new RenderServiceSoap();
            renderService.Credentials = new System.Net.NetworkCredential("124624", "PDALE_projets5");
            MapImage tempImage = renderService.GetMap(mapSpec)[0];
            Bitmap myMap = new Bitmap(new MemoryStream(tempImage.MimeData.Bits, false), true);
            //pcMap.Image = myMap;
            FileStream stream = new FileStream("c:\\map\\map.bmp", FileMode.OpenOrCreate);
            myMap.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
            stream.Close();
            System.Threading.Thread.Sleep(1000);
            //System.Diagnostics.Process.Start("c:\\map\\bmpcvt.exe","c:\\map\\map.bmp -convertintobestpalette -saveasmap,3 -exit");
            System.Diagnostics.Process.Start("c:\\map\\bmpcvt.exe", "c:\\map\\map.bmp -convertintobestpalette -saveasc:\\map\\toto.c,1 -exit");
            //stsMain.Text = "Done";//BmpCvt logo.bmp -convertintobestpalette -saveaslogo,1 -exit
        }
        catch (Exception e)
        {
            //MessageBox.Show(e.ToString());
        }
    }