コード例 #1
0
 public MapImage GetTile(string mapName, TileInfo tileInfo, ImageOutputOption imageOutputOption)
 {
     int scale = (int)Math.Floor(1 / tileInfo.Scale);
     string url = string.Format("{0}/output/cache/{1}_{2}x{3}/{4}/{5}/{6}.png",
         this._serviceUrl, mapName, tileInfo.Width, tileInfo.Height, scale, tileInfo.TileIndex.RowIndex, tileInfo.TileIndex.ColIndex);
     MapImage mapImage = null;
     if (imageOutputOption == null || (imageOutputOption != null && imageOutputOption.ImageReturnType == ImageReturnType.URL))
     {
         mapImage = new MapImage()
         {
             ImageUrl = url
         };
     }
     else
     {
         byte[] imageData = SynchHttpRequest.GetRequestBytes(url);
         mapImage = new MapImage()
         {
             ImageData = imageData
         };
     }
     return mapImage;
 }
コード例 #2
0
        /// <summary>
        /// 根据查询结果资源ID,获取查询结果高亮图片,图片只支持PNG格式。
        /// </summary>
        /// <param name="mapName">地图名称。</param>
        /// <param name="queryResultID">查询结果资源ID。</param>
        /// <param name="style">高亮风格设置。</param>
        /// <param name="mapParameter">地图参数。</param>
        /// <param name="imageOutputOption">图片输出设置。</param>
        /// <returns>高亮图片对象。</returns>
        public MapImage GetHighlightImage(string mapName, string queryResultID, Style style, MapParameter mapParameter, ImageOutputOption imageOutputOption)
        {
            if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull);
            if (string.IsNullOrEmpty(queryResultID)) throw new ArgumentNullException("queryResultID", Resources.ArgumentIsNotNull);
            string strImageFormat = "png";
            bool returnUrl = false;
            if (imageOutputOption != null)
            {
                strImageFormat = imageOutputOption.ImageOutputFormat.ToString().ToLower();
                if (imageOutputOption.ImageReturnType == ImageReturnType.URL)
                {
                    returnUrl = true;
                }
            }
            string url = string.Format("{0}/maps/{1}/highlightImage.{2}?", this._serviceUrl, HttpUtility.UrlEncode(mapName), strImageFormat);
            StringBuilder requestParamBuilder = new StringBuilder();
            requestParamBuilder.Append(string.Format("queryResultID={0}&", queryResultID));
            requestParamBuilder.Append(string.Format("style={0}&", JsonConvert.SerializeObject(style)));
            if (imageOutputOption != null)
            {
                requestParamBuilder.Append(string.Format("transparent={0}&", imageOutputOption.Transparent));
            }
            if (mapParameter != null)
            {
                requestParamBuilder.Append(GetMapRequestByMapParameter(mapName, mapParameter, true, false, false, false));
            }
            url = url + requestParamBuilder.ToString();
            MapImage mapImage = new MapImage();
            if (returnUrl)
            {
                mapImage.ImageUrl = url;
            }
            else
            {
                mapImage.ImageData = SynchHttpRequest.GetRequestBytes(url);
            }

            return mapImage;
        }
コード例 #3
0
        /// <summary>
        /// 根据地图参数、图片输出设置获取地图图片。
        /// </summary>
        /// <param name="mapName">地图名。【必设参数】</param>
        /// <param name="mapParameter">地图参数。【必设参数】</param>
        /// <param name="imageOutputOption">图片输出设置。</param>
        /// <returns>所获取的地图图片对象。</returns>
        public MapImage GetMapImage(string mapName, MapParameter mapParameter, ImageOutputOption imageOutputOption, bool returnMapParameter)
        {
            string strImageFormat = "png";
            bool returnUrl = false;
            if (imageOutputOption != null)
            {
                strImageFormat = imageOutputOption.ImageOutputFormat.ToString().ToLower();
                if (returnMapParameter)
                {
                    strImageFormat = "json";
                }
                if (imageOutputOption.ImageReturnType == ImageReturnType.URL)
                {
                    returnUrl = true;
                }
            }
            string url = string.Format("{0}/maps/{1}/image.{2}?", this._serviceUrl, HttpUtility.UrlEncode(mapName), strImageFormat);
            StringBuilder requestParamBuilder = new StringBuilder();

            if (imageOutputOption != null)
            {
                requestParamBuilder.Append(string.Format("transparent={0}&", imageOutputOption.Transparent));
            }
            if (mapParameter != null)
            {
                requestParamBuilder.Append(this.GetMapRequestByMapParameter(mapName, mapParameter, false, false, false, false));
            }
            MapImage mapImage = new MapImage();
            url = url + requestParamBuilder.ToString(); //用GET请求发送。
            if (returnMapParameter)
            {
                string requetResponse = SynchHttpRequest.GetRequestString(url, HttpRequestMethod.GET, "");
                Dictionary<string, object> jsonItems = JsonConvert.DeserializeObject<Dictionary<string, object>>(requetResponse);
                mapImage.ImageUrl = jsonItems["imageUrl"].ToString();
                mapImage.MapParameter = JsonConvert.DeserializeObject<MapParameter>(JsonConvert.SerializeObject(jsonItems["mapParam"]));
                return mapImage;
            }
            else if (returnUrl)
            {
                mapImage.ImageUrl = url;
            }
            else
            {
                mapImage.ImageData = SynchHttpRequest.GetRequestBytes(url);
            }

            return mapImage;
        }
コード例 #4
0
        /// <summary>
        /// 根据地图分块信息和地图参数设置,获取格网图片。
        /// </summary>
        /// <param name="mapName">地图名。【必设参数】</param>
        /// <param name="tileInfo">地图分块信息。【必设参数】</param>
        /// <param name="imageOutputOption">图片输出设置。</param>
        /// <param name="mapParameter">地图参数。</param>
        /// <returns>所获取的格网图片信息。</returns>
        public MapImage GetTile(string mapName, TileInfo tileInfo, ImageOutputOption imageOutputOption, MapParameter mapParameter)
        {
            string strImageFormat = "png";
            bool returnUrl = false;
            if (imageOutputOption != null)
            {
                strImageFormat = imageOutputOption.ImageOutputFormat.ToString().ToLower();
                if (imageOutputOption.ImageReturnType == ImageReturnType.URL)
                {
                    returnUrl = true;
                }
            }
            if (tileInfo == null || tileInfo.TileIndex == null)
            {
                return null;
            }
            string url = string.Format("{0}/maps/{1}/tileImage.{2}?", this._serviceUrl, HttpUtility.UrlEncode(mapName), strImageFormat);
            StringBuilder requestParamBuilder = new StringBuilder();
            requestParamBuilder.Append(string.Format("scale={0}&x={1}&y={2}&width={3}&height={4}", tileInfo.Scale,
                tileInfo.TileIndex.ColIndex, tileInfo.TileIndex.RowIndex, tileInfo.Width, tileInfo.Height));
            if (imageOutputOption != null)
            {
                requestParamBuilder.Append(string.Format("&transparent={0}&", imageOutputOption.Transparent));
            }
            if (mapParameter != null)
            {
                requestParamBuilder.Append(this.GetMapRequestByMapParameter(mapName, mapParameter, false, true, true, true));
            }
            //进行重定向
            MapImage mapImage = new MapImage();
            url = url + requestParamBuilder.ToString();
            if (returnUrl)
            {
                mapImage.ImageUrl = url;
            }
            else
            {
                mapImage.ImageData = SynchHttpRequest.GetRequestBytes(url);
            }

            return mapImage;
        }