Пример #1
0
        public static byte[] GetMap(MapSpecification map)
        {
            // Declare the map image array and get the map
            MapImage[] mapImageArray = null;

            try
            {
                mapImageArray = renderService.GetMap(map);
            }
            catch (System.Net.WebException) {
                // Better error handling?
                return(null);
            }

            // Careful return
            if (null != mapImageArray && null != mapImageArray[0])
            {
                return(mapImageArray[0].MimeData.Bits);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// This method will return a image representing a map
        /// </summary>
        /// <param name="location">result from the FindLocation method</param>
        /// <param name="imageWidth">width of image used to display the map</param>
        /// <param name="imageHeight">height of the image used to display the map</param>
        /// <param name="zoom">floating point number > 0 respresent amount of zoom on the returned map</param>
        /// <returns>Address</returns>
        public System.Drawing.Image GetMap(Location location, int imageWidth, int imageHeight, double zoom)
        {
            MapImage[]            mapImage;
            System.Drawing.Bitmap theImage = null;

            try
            {
                if (location == null)
                {
                    throw new System.ArgumentNullException("Location cannot be null");
                }

                if (imageWidth <= 0)
                {
                    throw new System.ArgumentNullException("Image width should be > then 0");
                }

                if (imageHeight <= 0)
                {
                    throw new System.ArgumentNullException("Image Height should be > then 0");
                }
                if (zoom <= 0)
                {
                    throw new System.ArgumentNullException("Zoom should be great then 0");
                }

                // now get a map
                MapSpecification mapSpec = new MapSpecification();

                //ViewByScale[] myViews = new ViewByScale[1];
                MapView[] myViews = new MapView[1];
                myViews[0] = location.BestMapView.ByHeightWidth;

                mapSpec.Views                 = myViews;
                mapSpec.DataSourceName        = "MapPoint.NA";
                mapSpec.Options               = new MapOptions();
                mapSpec.Options.Format        = new ImageFormat();
                mapSpec.Options.Format.Height = imageHeight;
                mapSpec.Options.Format.Width  = imageWidth;
                mapSpec.Options.Zoom          = zoom;

                //	setup pushpin
                Pushpin[] ppArray = new Pushpin[1];

                // set up a sample push pin
                ppArray[0] = new Pushpin();
                ppArray[0].IconDataSource = "MapPoint.Icons";
                ppArray[0].IconName       = "168";
                ppArray[0].LatLong        = location.LatLong;
                ppArray[0].Label          = "You are here";
                ppArray[0].ReturnsHotArea = true;
                // PinID contains the db key and the ADE NAME seperated by a tilde
                ppArray[0].PinID = "where I am now";

                mapSpec.Pushpins = ppArray;

                mapImage = theMapPointRenderService.GetMap(mapSpec);

                // let sure an MapImage was returned
                if (mapImage != null && mapImage.Length > 0)
                {
                    theImage = new System.Drawing.Bitmap(new System.IO.MemoryStream(mapImage[0].MimeData.Bits));
                }
                else
                {
                    throw new System.Exception("Unable to build a map for this route");
                }
            }
            catch (ArgumentNullException e)
            {
                throw e;  // rethrow for app to handle
            }
            catch (Exception e)
            {
                throw e;  // rethrow for app to handle
            }

            return(theImage);
        }