public iServerProvider(string serviceUrl, string mapName, uint tileSize, string format, double[] scales, Utility.MapParameter mapParameter) { this._serviceUrl = serviceUrl; this._mapName = mapName; this._format = format; this._scales = scales; this._tileSize = tileSize; this.mapParameter = mapParameter; }
public SQLForm(string mapUrl, string mapName) { InitializeComponent(); this._mapName = mapName; this._mapUrl = mapUrl; _map = new Map(_mapUrl); defaultMapParameter = _map.GetDefaultMapParameter(mapName); InitializeSQL(); }
private void InitLayer(MapParameter mapParameter) { this.clbLayers.Items.Clear(); Map map = new Map(_mapUrl); if (mapParameter != null) { for (int i = 0; i < mapParameter.Layers.Count; i++) { this.clbLayers.Items.Add(new LayerItem(mapParameter.Layers[i].Name, mapParameter.Layers[i].Caption)); } } }
public SuperMapProvider(string serviceUrl, string mapName, uint tileSize, string format, MapParameter mapParameter) { Copyright = string.Format("© SuperMap iServer 6R(2012) - Map data ©{0} SuperMap iServer 6R(2012)", DateTime.Today.Year); this._serviceUrl = serviceUrl; this._tileSize = tileSize; this._mapName = mapName; this._mapParameter = mapParameter; this._map = new SuperMap.Connector.Map(serviceUrl); MapParameter defaultMapParameter = this._map.GetDefaultMapParameter(mapName); }
public SQLForm(string mapUrl, string mapName, MapControl mapControl) { InitializeComponent(); this._mapName = mapName; this._mapUrl = mapUrl; _map = new Map(_mapUrl); defaultMapParameter = _map.GetDefaultMapParameter(mapName); _mapControl = mapControl; publicResultForm = new PublicResultForm(); publicResultForm.Name = "QueryBySql"; publicResultForm.Text = "SQL查询结果"; publicResultForm.MapControl = mapControl; InitializeSQL(); }
public SuperMapProjection(double[] mapScales, MapParameter defaultMapParameter) { if (mapScales == null) throw new ArgumentNullException(); if (defaultMapParameter == null) { throw new ArgumentNullException(); } _mapScales = mapScales; _bounds = RectLatLng.FromLTRB(defaultMapParameter.Bounds.LeftBottom.X, defaultMapParameter.Bounds.RightTop.Y, defaultMapParameter.Bounds.RightTop.X, defaultMapParameter.Bounds.LeftBottom.Y); if (defaultMapParameter.Bounds == null) throw new ArgumentNullException(); _minX = defaultMapParameter.Bounds.LeftBottom.X; _minY = defaultMapParameter.Bounds.LeftBottom.Y; _maxX = defaultMapParameter.Bounds.RightTop.X; _maxY = defaultMapParameter.Bounds.RightTop.Y; if (defaultMapParameter.PrjCoordSys != null && defaultMapParameter.PrjCoordSys.CoordSystem != null && defaultMapParameter.PrjCoordSys.CoordSystem.Datum != null && defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid != null) { _axis = defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid.Axis; _flattening = defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid.Flatten; } double refMapScale = defaultMapParameter.Scale; double refResolution = (defaultMapParameter.ViewBounds.RightTop.X - defaultMapParameter.ViewBounds.LeftBottom.X) / (defaultMapParameter.Viewer.Width); _resolutions = new double[_mapScales.Length]; for (int i = 0; i < _mapScales.Length; i++) { _resolutions[i] = refResolution * refMapScale / mapScales[i]; } }
private void InitLayer(MapParameter mapParameter,bool isNew) { this.clbLayers.Items.Clear(); Map map = new Map(_mapUrl); if (mapParameter != null) { for (int i = 0; i < mapParameter.Layers.Count; i++) { this.clbLayers.Items.Add(new LayerItem(mapParameter.Layers[i].Name, mapParameter.Layers[i].Caption)); } } if (!isNew) { if (QuerySetting.LayerNames != null && QuerySetting.LayerNames.Count > 0) { var v = (from item in this.clbLayers.Items.Cast<LayerItem>() join l in QuerySetting.LayerNames on item.Name equals l select item).ToList(); foreach (var i in v) { clbLayers.SetItemChecked(clbLayers.Items.IndexOf(i), true); } } this.tbExceptionCount.Text = QuerySetting.ExceptionCount.ToString(); if (QuerySetting.QueryOption == QueryOption.ATTRIBUTE) { this.radioButton2.Checked = true; } else if (QuerySetting.QueryOption == QueryOption.GEOMETRY) { this.radioButton1.Checked = true; } else { this.radioButton3.Checked = true; } } else { clbLayers.SetItemChecked(0, true); } QuerySetting.Layers = mapParameter.Layers; }
private void btnThemeUnique_Click(object sender, EventArgs e) { UGCThemeLayer ugcThemeLayer = new UGCThemeLayer(); ugcThemeLayer.Type = LayerType.UGC; ugcThemeLayer.Visible = true; ugcThemeLayer.UgcLayerType = UGCLayerType.THEME; ugcThemeLayer.DatasetInfo = new DatasetInfo(); ugcThemeLayer.DatasetInfo.DataSourceName = "Jingjin"; ugcThemeLayer.DatasetInfo.Name = "BaseMap_R"; ugcThemeLayer.DatasetInfo.Type = DatasetType.REGION; //theme.graduatedMode = SuperMap.Web.iServerJava6R.GraduatedMode.SQUAREROOT; //theme.graphAxes.axesDisplayed = true; //theme.graphSize.maxGraphSize = 1; //theme.graphSize.minGraphSize = 0.35; //theme.graphText.graphTextDisplayed = true; //theme.graphText.graphTextFormat = SuperMap.Web.iServerJava6R.ThemeGraphTextFormat.VALUE; //theme.graphType = SuperMap.Web.iServerJava6R.ThemeGraphType.BAR3D; ThemeGraph themeGraph = new ThemeGraph(); themeGraph.Type = ThemeType.GRAPH; themeGraph.GraphType = ThemeGraphType.BAR3D; themeGraph.GraduatedMode = GraduatedMode.SQUAREROOT; themeGraph.AxesDisplayed = true; themeGraph.MaxGraphSize = 1; themeGraph.MinGraphSize = 0.35; themeGraph.GraphTextDisplayed = true; themeGraph.GraphTextFormat = GraphTextFormat.VALUE; themeGraph.BarWidth = 0.03; var item1 = new ThemeGraphItem(); item1.Caption = "1"; item1.GraphExpression = "Pop_Rate95"; var style1 = new SuperMap.Connector.Utility.Style(); style1.FillForeColor = new SuperMap.Connector.Utility.Color(211, 111, 240); item1.UniformStyle = style1; var item2 = new ThemeGraphItem(); item2.Caption = "人口"; item2.GraphExpression = "Pop_Rate99"; var style2 = new SuperMap.Connector.Utility.Style(); style2.FillForeColor = new SuperMap.Connector.Utility.Color(92, 73, 234); item2.UniformStyle = style2; themeGraph.Items = new ThemeGraphItem[] { item1, item2 }; ugcThemeLayer.Theme = themeGraph; SuperMap.Connector.Map map = new SuperMap.Connector.Map("http://localhost:8090/iserver/services/map-jingjin"); MapParameter defaultMapParameter = map.GetDefaultMapParameter("京津地区人口分布图_专题图"); List<SuperMap.Connector.Utility.Layer> layers = new List<SuperMap.Connector.Utility.Layer>(); layers.Add(ugcThemeLayer); //layers.Add(defaultMapParameter.Layers[11]); //layers.Add(defaultMapParameter.Layers[12]); MapParameter requestMapParameter = new MapParameter(); requestMapParameter.Name = "京津地区人口分布图_专题图"; requestMapParameter.Bounds = new SuperMap.Connector.Utility.Rectangle2D(defaultMapParameter.Bounds); requestMapParameter.CacheEnabled = false; requestMapParameter.ColorMode = MapColorMode.DEFAULT; requestMapParameter.RectifyType = RectifyType.BYCENTERANDMAPSCALE; requestMapParameter.CoordUnit = Unit.METER; requestMapParameter.OverlapDisplayed = true; requestMapParameter.PaintBackground = true; //requestMapParameter.MaxVisibleVertex = 3600000; requestMapParameter.Layers = layers; double defaultScale = defaultMapParameter.Scale; double[] scales = new double[] {defaultScale/16,defaultScale/14,defaultScale/12,defaultScale/10, defaultScale/8,defaultScale/6,defaultScale/4,defaultScale/2, defaultScale,defaultScale*2, defaultScale*4,defaultScale*6,defaultScale*8,defaultScale*10,defaultScale*12,defaultScale*14,defaultScale*16}; SuperMapTileSource tileSource = new SuperMapTileSource("http://localhost:8090/iserver/services/map-jingjin", "京津地区人口分布图_专题图", 256, "png", scales, requestMapParameter); TileLayer layer = new TileLayer(tileSource); layer.LayerName = "京津地区人口分布图_专题图1"; mapControl.Map = CreateMap(layer); }
public void GetMapImage_ReturnUrl() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); MapParameter mapParameter = new MapParameter() { Center = new Point2D(0, 0), Scale = 0.0000000013138464, Viewer = new Utility.Rectangle(0, 0, 256, 256) }; ImageOutputOption option = new ImageOutputOption() { ImageOutputFormat = ImageOutputFormat.GIF, ImageReturnType = ImageReturnType.URL }; MapImage mapImage = map.GetMapImage("世界地图", mapParameter, option); Assert.IsNotNull(mapImage); Assert.IsTrue(!string.IsNullOrWhiteSpace(mapImage.ImageUrl)); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(mapImage.ImageUrl); HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse(); Stream stream = response.GetResponseStream(); Assert.IsNotNull(stream); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { MapParameter mapParameter = new MapParameter(); reader.Read(); while (reader.TokenType == JsonToken.PropertyName) { string propertyName = reader.Value.ToString(); switch (propertyName) { case "name": reader.Read(); mapParameter.Name = reader.Value != null ? reader.Value.ToString() : string.Empty; break; case "center": reader.Read(); mapParameter.Center = serializer.Deserialize<Point2D>(reader); break; case "scale": reader.Read(); double scale = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out scale)) { mapParameter.Scale = scale; } break; case "maxScale": reader.Read(); double maxScale = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out maxScale)) { mapParameter.MaxScale = maxScale; } break; case "minScale": reader.Read(); double minScale = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out minScale)) { mapParameter.MinScale = minScale; } break; case "angle": reader.Read(); double angle = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out angle)) { mapParameter.Angle = angle; } break; case "antialias": reader.Read(); bool antialias = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out antialias)) { mapParameter.Antialias = antialias; } break; case "backgroundStyle": reader.Read(); mapParameter.BackgroundStyle = serializer.Deserialize<Style>(reader); break; case "bounds": reader.Read(); mapParameter.Bounds = serializer.Deserialize<Rectangle2D>(reader); break; case "clipRegion": reader.Read(); mapParameter.ClipRegion = serializer.Deserialize<Geometry>(reader); break; case "colorMode": reader.Read(); MapColorMode colorMode = MapColorMode.DEFAULT; if (reader.Value != null) { colorMode = (MapColorMode)Enum.Parse(typeof(MapColorMode), reader.Value.ToString(), false); mapParameter.ColorMode = colorMode; } break; case "clipRegionEnabled": reader.Read(); bool clipRegionEnabled = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out clipRegionEnabled)) { mapParameter.ClipRegionEnabled = clipRegionEnabled; } break; case "maxVisibleVertex": reader.Read(); int maxVisibleVertex = 0; if (reader.Value != null && int.TryParse(reader.Value.ToString(), out maxVisibleVertex)) { mapParameter.MaxVisibleVertex = maxVisibleVertex; } break; case "coordUnit": reader.Read(); Unit coordUnit = Unit.METER; if (reader.Value != null) { coordUnit = (Unit)Enum.Parse(typeof(Unit), reader.Value.ToString(), false); mapParameter.CoordUnit = coordUnit; } break; case "rectifyType": reader.Read(); RectifyType rectifyType = RectifyType.BYCENTERANDMAPSCALE; if (reader.Value != null) { rectifyType = (RectifyType)Enum.Parse(typeof(RectifyType), reader.Value.ToString(), false); mapParameter.RectifyType = rectifyType; } break; case "customEntireBounds": reader.Read(); mapParameter.CustomEntireBounds = serializer.Deserialize<Rectangle2D>(reader); break; case "customEntireBoundsEnabled": reader.Read(); bool customEntireBoundsEnabled = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out customEntireBoundsEnabled)) { mapParameter.CustomEntireBoundsEnabled = customEntireBoundsEnabled; } break; case "customParams": reader.Read(); mapParameter.CustomParams = reader.Value != null ? reader.Value.ToString() : string.Empty; break; case "description": reader.Read(); mapParameter.Description = reader.Value != null ? reader.Value.ToString() : string.Empty; break; case "distanceUnit": reader.Read(); Unit distanceUnit = Unit.METER; if (reader.Value != null) { distanceUnit = (Unit)Enum.Parse(typeof(Unit), reader.Value.ToString(), false); mapParameter.CoordUnit = distanceUnit; } break; case "dynamicProjection": reader.Read(); bool dynamicProjection = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out dynamicProjection)) { mapParameter.DynamicProjection = dynamicProjection; } break; case "markerAngleFixed": reader.Read(); bool markerAngleFixed = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out markerAngleFixed)) { mapParameter.MarkerAngleFixed = markerAngleFixed; } break; case "maxVisibleTextSize": reader.Read(); double maxVisibleTextSize = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out maxVisibleTextSize)) { mapParameter.MaxVisibleTextSize = maxVisibleTextSize; } break; case "minVisibleTextSize": reader.Read(); double minVisibleTextSize = 0.0; if (reader.Value != null && double.TryParse(reader.Value.ToString(), out minVisibleTextSize)) { mapParameter.MinVisibleTextSize = minVisibleTextSize; } break; case "overlapDisplayed": reader.Read(); bool overlapDisplayed = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out overlapDisplayed)) { mapParameter.OverlapDisplayed = overlapDisplayed; } break; case "paintBackground": reader.Read(); bool paintBackground = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out paintBackground)) { mapParameter.PaintBackground = paintBackground; } break; case "textAngleFixed": reader.Read(); bool textAngleFixed = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out textAngleFixed)) { mapParameter.TextAngleFixed = textAngleFixed; } break; case "textOrientationFixed": reader.Read(); bool textOrientationFixed = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out textOrientationFixed)) { mapParameter.TextOrientationFixed = textOrientationFixed; } break; case "prjCoordSys": reader.Read(); mapParameter.PrjCoordSys = serializer.Deserialize<PrjCoordSys>(reader); break; case "viewBounds": reader.Read(); mapParameter.ViewBounds = serializer.Deserialize<Rectangle2D>(reader); break; case "viewer": reader.Read(); mapParameter.Viewer = serializer.Deserialize<Rectangle>(reader); break; case "cacheEnabled": reader.Read(); bool cacheEnabled = false; if (reader.Value != null && bool.TryParse(reader.Value.ToString(), out cacheEnabled)) { mapParameter.CacheEnabled = cacheEnabled; } break; case "userToken": reader.Read(); mapParameter.UserToken = serializer.Deserialize<UserInfo>(reader); break; case "layers": reader.Read(); List<Dictionary<string, object>> layers = serializer.Deserialize<List<Dictionary<string, object>>>(reader); mapParameter.Layers = new List<Layer>(); if (layers != null && layers.Count > 0) { for (int i = 0; i < layers.Count; i++) { LayerType layerType = (LayerType)Enum.Parse(typeof(LayerType), layers[i]["type"].ToString(), false); switch (layerType) { case LayerType.UGC: UGCMapLayer ugcMapLayer = JsonConvert.DeserializeObject<UGCMapLayer>(JsonConvert.SerializeObject(layers[i])); //mapParameter.Layers.Add(ugcMapLayer); if (ugcMapLayer != null) { for (int j = 0; j < ugcMapLayer.SubLayers.Count; j++) { mapParameter.Layers.Add(ugcMapLayer.SubLayers[j]); } } break; default: break; } } } break; default: reader.Skip(); break; } reader.Read(); } return mapParameter; }
/// <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; }
/// <summary> /// 获取地图的鹰眼图片。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="mapParameter">地图参数。</param> /// <param name="imageOutputOption">图片输出设置。</param> /// <returns>鹰眼对象。</returns> public Overview GetOverview(string mapName, MapParameter mapParameter, ImageOutputOption imageOutputOption) { if (string.IsNullOrEmpty(mapName)) throw new ArgumentNullException("mapName", Resources.ArgumentIsNotNull); string strImageFormat = "png"; bool returnUrl = false; if (imageOutputOption != null) { strImageFormat = imageOutputOption.ImageOutputFormat.ToString().ToLower(); if (imageOutputOption.ImageReturnType == ImageReturnType.URL) { returnUrl = true; strImageFormat = "json"; } } string url = string.Format("{0}/maps/{1}/overview.{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(GetMapRequestByMapParameter(mapName, mapParameter, true, false, false, false)); } //进行重定向 //requestParamBuilder.Append(string.Format("redirect={0}&", "true")); url = url + requestParamBuilder.ToString(); Overview overview = new Overview(); if (returnUrl) { string requetResponse = SynchHttpRequest.GetRequestString(url); Dictionary<string, object> jsonItems = JsonConvert.DeserializeObject<Dictionary<string, object>>(requetResponse); overview.ImageUrl = jsonItems["imageUrl"].ToString(); overview.MapName = JsonConvert.DeserializeObject<string>(JsonConvert.SerializeObject(jsonItems["mapName"])); overview.LastModified = JsonConvert.DeserializeObject<long>(JsonConvert.SerializeObject(jsonItems["lastModified"])); overview.ViewBounds = JsonConvert.DeserializeObject<Rectangle2D>(JsonConvert.SerializeObject(jsonItems["viewBounds"])); overview.Viewer = JsonConvert.DeserializeObject<Rectangle>(JsonConvert.SerializeObject(jsonItems["viewer"])); } else { overview.ImageData = SynchHttpRequest.GetRequestBytes(url); } return overview; }
/// <summary> /// 根据指定的图层范围获取地图的全幅显示图片。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="layerName">指定图层,以该图层内容的最小外接矩形作为全幅显示的地理范围。</param> /// <param name="mapParameter">地图参数。</param> /// <param name="imageOutputOption">图片输出设置。</param> /// <returns>全幅显示图片对象。</returns> public MapImage GetEntireImage(string mapName, string layerName, MapParameter mapParameter, ImageOutputOption imageOutputOption) { return _mapProvider.GetEntireImage(mapName, layerName, mapParameter, imageOutputOption); }
//public MapImage GetHighlightImage(string mapName, string highlightTargetSetID, MapParameter mapParameter, ImageOutputOption imageOutputOption) //{ // return _mapProvider.GetHighlightImage(mapName, highlightTargetSetID, mapParameter, imageOutputOption); //} /// <summary> /// 获取地图的鹰眼图片。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="mapParameter">地图参数。</param> /// <param name="imageOutputOption">图片输出设置。</param> /// <returns>鹰眼对象。</returns> /// <example> /// <code> /// Map map1 = new Map("http://localhost:8090/iserver/services/map-world/rest"); /// ImageOutputOption imageOutputOption = new ImageOutputOption(); /// imageOutputOption.ImageOutputFormat = ImageOutputFormat.PNG; /// imageOutputOption.ImageReturnType = ImageReturnType.URL; /// imageOutputOption.Transparent = false; /// MapParameter mapParameter = map1.GetDefaultMapParameter("世界地图"); /// Overview actualResult = map1.GetOverview("世界地图", mapParameter, imageOutputOption); /// </code> /// </example> public Overview GetOverview(string mapName, MapParameter mapParameter, ImageOutputOption imageOutputOption) { return _mapProvider.GetOverview(mapName, mapParameter, imageOutputOption); }
/// <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> /// <example> /// <code> /// ImageOutputOption imageOutputOption = new ImageOutputOption(); /// imageOutputOption.ImageOutputFormat = ImageOutputFormat.PNG; /// imageOutputOption.ImageReturnType = ImageReturnType.URL; /// MapParameter mapParameter = map1.GetDefaultMapParameter("世界地图"); /// mapParameter.ViewBounds = new Rectangle2D(-180, -90, 180, 90); /// mapParameter.RectifyType = RectifyType.BYVIEWBOUNDS; /// Style style = new Style(); /// style.FillForeColor = new SuperMap.Connector.Utility.Color(0, 255, 0); /// Map map1 = new Map("http://localhost:8090/iserver/services/map-world/rest"); /// //需要获取某次查询结果的queryResultID值 /// MapImage actualResult = map1.GetHighlightImage("世界地图", queryResultID, style, mapParameter, imageOutputOption); /// </code> /// </example> public MapImage GetHighlightImage(string mapName, string queryResultID, Style style, MapParameter mapParameter, ImageOutputOption imageOutputOption) { return _mapProvider.GetHighlightImage(mapName, queryResultID, style, mapParameter, imageOutputOption); }
/// <summary> /// 根据地图参数、图片输出设置获取地图图片,可设置是否返回当前图片参数信息。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="mapParameter">地图参数。</param> /// <param name="imageOutputOption">图片输出设置。</param> /// <param name="returnMapParameter">是否返回图片参数信息。</param> /// <returns>所获取的地图图片对象。</returns> public MapImage GetMapImage(string mapName, MapParameter mapParameter, ImageOutputOption imageOutputOption, bool returnMapParameter) { return _mapProvider.GetMapImage(mapName, mapParameter, imageOutputOption, returnMapParameter); }
/// <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) { return _mapProvider.GetTile(mapName, tileInfo, imageOutputOption, mapParameter); }
/// <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; }
/// <summary> /// 获取MapParameter对象的请求字符串(用来出图时用。)。 /// </summary> /// <param name="mapName">地图名</param> /// <param name="mapParameter">地图参数。</param> /// <returns>地图请求参数字符串。</returns> private string GetMapRequestByMapParameter(string mapName, MapParameter mapParameter) { StringBuilder mapParameterBuilder = new StringBuilder(); string layersID = GetTempLayersSetID(mapName, mapParameter); if (layersID != "0") mapParameterBuilder.Append(string.Format("&{0}={1}&", "layersID", layersID)); if (mapParameter.DynamicProjection && mapParameter.PrjCoordSys != null) { mapParameterBuilder.Append(string.Format("{0}={1}&", "dynamicProjection", mapParameter.DynamicProjection.ToString())); mapParameterBuilder.Append(string.Format("{0}={1}", "prjCoordSys", JsonConvert.SerializeObject(mapParameter.PrjCoordSys))); mapParameterBuilder.Append("&"); } mapParameterBuilder.Append(string.Format("{0}={1}&", "cacheEnabled", mapParameter.CacheEnabled)); if (mapParameter.CustomParams != null) { mapParameterBuilder.Append(string.Format("customParams={0}&", mapParameter.CustomParams)); } mapParameterBuilder.Append(string.Format("rectifyType={0}&", mapParameter.RectifyType)); if (mapParameter.ClipRegionEnabled && mapParameter.ClipRegion != null) { mapParameterBuilder.Append(string.Format("clipRegionEnabled={0}&", mapParameter.ClipRegionEnabled)); mapParameterBuilder.Append(string.Format("clipRegion={0}&", JsonConvert.SerializeObject(mapParameter.ClipRegion))); } if (mapParameter.CustomEntireBoundsEnabled && mapParameter.CustomEntireBounds != null) { mapParameterBuilder.Append(string.Format("customEntireBoundsEnabled={0}&", mapParameter.CustomEntireBoundsEnabled)); mapParameterBuilder.Append(string.Format("customEntireBounds={0}&", JsonConvert.SerializeObject(mapParameter.CustomEntireBounds))); } mapParameterBuilder.Append(string.Format("angle={0}&", mapParameter.Angle)); mapParameterBuilder.Append(string.Format("antialias={0}&", mapParameter.Antialias)); mapParameterBuilder.Append(string.Format("backgroundStyle={0}&", JsonConvert.SerializeObject(mapParameter.BackgroundStyle))); mapParameterBuilder.Append(string.Format("colorMode={0}&", mapParameter.ColorMode)); mapParameterBuilder.Append(string.Format("markerAngleFixed={0}&", mapParameter.MarkerAngleFixed)); mapParameterBuilder.Append(string.Format("maxVisibleTextSize={0}&", mapParameter.MaxVisibleTextSize)); mapParameterBuilder.Append(string.Format("maxVisibleVertex={0}&", mapParameter.MaxVisibleVertex)); mapParameterBuilder.Append(string.Format("minVisibleTextSize={0}&", mapParameter.MinVisibleTextSize)); mapParameterBuilder.Append(string.Format("overlapDisplayed={0}&", mapParameter.OverlapDisplayed)); mapParameterBuilder.Append(string.Format("paintBackground={0}&", mapParameter.PaintBackground)); mapParameterBuilder.Append(string.Format("textAngleFixed={0}&", mapParameter.TextAngleFixed)); mapParameterBuilder.Append(string.Format("textOrientationFixed={0}&", mapParameter.TextOrientationFixed)); return mapParameterBuilder.ToString(); }
/// <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; }
public void DynicProject() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); MapParameter mapParameter = new MapParameter(); mapParameter.PrjCoordSys = new PrjCoordSys(); mapParameter.PrjCoordSys.EpsgCode = 3857; mapParameter.Center = new Point2D(0, 0); mapParameter.Scale = 0.0000000013138464; mapParameter.Viewer = new Utility.Rectangle(0, 0, 256, 256); mapParameter.RectifyType = RectifyType.BYCENTERANDMAPSCALE; mapParameter.CacheEnabled = false; ImageOutputOption option = new ImageOutputOption(); option.ImageOutputFormat = ImageOutputFormat.PNG; option.ImageReturnType = ImageReturnType.BINARY; MapImage image = map.GetMapImage("世界地图", mapParameter, option); Assert.IsTrue(image != null); using (MemoryStream stream = new MemoryStream(image.ImageData)) { Bitmap bmp = (Bitmap)Image.FromStream(stream); System.Drawing.Color t = bmp.GetPixel(200, 230); Assert.IsTrue(t.A == 255); Assert.IsTrue(t.R == 196); Assert.IsTrue(t.G == 193); Assert.IsTrue(t.B == 225); } }
/// <summary> /// 获取地图的全幅显示图片。 /// </summary> /// <param name="mapName">地图名称。</param> /// <param name="mapParameter">地图参数。</param> /// <param name="imageOutputOption">图片输出设置。</param> /// <returns>全幅显示图片对象。</returns> public MapImage GetEntireImage(string mapName, MapParameter mapParameter, ImageOutputOption imageOutputOption) { return GetEntireImage(mapName, null, mapParameter, imageOutputOption); }
/// <summary> /// 构造函数。 /// </summary> /// <param name="mapParameter">地图参数对象。</param> public MapParameterEventArgs(MapParameter mapParameter) { _mapParameter = mapParameter; }
//public MapImage GetHighlightImage(string mapName, string highlightTargetSetID, MapParameter mapParameter, ImageOutputOption imageOutputOption) //{ // throw new NotImplementedException(); //} /// <summary> /// 根据地图参数中的图层列表获取临时图层ID /// </summary> /// <param name="mapName">地图名。</param> /// <param name="mapParameter">地图参数。</param> /// <returns>临时图层ID。</returns> private string GetTempLayersSetID(string mapName, MapParameter mapParameter) { if (mapParameter.Layers == null) return "0"; string tempLayersKey = HashKeyHelper.GetHashKey<List<Layer>>(mapParameter.Layers); object layersID = CacheManager.Instance.GetCache(tempLayersKey); if (layersID == null) { lock (MapProvider._lockTarget) { layersID = CacheManager.Instance.GetCache(tempLayersKey); if (layersID == null) { //和GetMapParameter中相似,反向处理时,解析为UGCMapLayer对象中。 List<Layer> layers = new List<Layer>(); UGCMapLayer ugcMapLayer = new UGCMapLayer(); ugcMapLayer.SubLayers = new LayerCollection(); if (mapParameter.Layers != null && mapParameter.Layers.Count > 0) { for (int i = 0; i < mapParameter.Layers.Count; i++) { ugcMapLayer.SubLayers.Add(mapParameter.Layers[i]); } } ugcMapLayer.Name = mapParameter.Name; ugcMapLayer.Caption = mapParameter.Name; ugcMapLayer.Visible = true; ugcMapLayer.Type = LayerType.UGC; ugcMapLayer.Description = mapParameter.Description; ugcMapLayer.Bounds = mapParameter.Bounds; layers.Add(ugcMapLayer); string tempLayersSetUrl = string.Format("{0}/maps/{1}/tempLayersSet.json?", this._serviceUrl, HttpUtility.UrlEncode(mapName)); string tempLayersSetJson = JsonConvert.SerializeObject(layers); string tempLayersSetResourceResult = SynchHttpRequest.GetRequestString(tempLayersSetUrl, tempLayersSetJson); TempLayersSetResourceResult tempLayersSet = JsonConvert.DeserializeObject<TempLayersSetResourceResult>(tempLayersSetResourceResult); if (tempLayersSet != null) { layersID = tempLayersSet.NewResourceID; CacheManager.Instance.AddCache(tempLayersKey, layersID); } } } } return layersID as string; }
public void GetMapImage_CreateThemeGraph() { ThemeGraph themeGraph = new ThemeGraph(); themeGraph.Type = ThemeType.GRAPH; themeGraph.GraphType = ThemeGraphType.BAR3D; themeGraph.GraduatedMode = GraduatedMode.SQUAREROOT; themeGraph.AxesDisplayed = true; themeGraph.MaxGraphSize = 1; themeGraph.MinGraphSize = 0.35; themeGraph.GraphTextDisplayed = true; themeGraph.GraphTextFormat = GraphTextFormat.VALUE; themeGraph.BarWidth = 0.03; var item1 = new ThemeGraphItem(); item1.Caption = "1"; item1.GraphExpression = "Pop_Rate95"; var style1 = new SuperMap.Connector.Utility.Style(); style1.FillForeColor = new SuperMap.Connector.Utility.Color(211, 111, 240); item1.UniformStyle = style1; var item2 = new ThemeGraphItem(); item2.Caption = "人口"; item2.GraphExpression = "Pop_Rate99"; var style2 = new SuperMap.Connector.Utility.Style(); style2.FillForeColor = new SuperMap.Connector.Utility.Color(92, 73, 234); item2.UniformStyle = style2; themeGraph.Items = new ThemeGraphItem[] { item1, item2 }; UGCThemeLayer themeLayer = new UGCThemeLayer(); themeLayer.DatasetInfo = new DatasetInfo(); themeLayer.DatasetInfo.DataSourceName = "Jingjin"; themeLayer.DatasetInfo.Name = "BaseMap_R"; themeLayer.DatasetInfo.Type = DatasetType.REGION; themeLayer.Description = "动态统计专题图"; themeLayer.UgcLayerType = UGCLayerType.THEME; themeLayer.Type = LayerType.UGC; themeLayer.Visible = true; themeLayer.Theme = themeGraph; MapParameter mapParameter = new MapParameter(); mapParameter.CacheEnabled = false; mapParameter.Center = new Point2D(116.755063, 39.803942); mapParameter.Scale = 1.0 / 1589406.44119042; mapParameter.RectifyType = RectifyType.BYCENTERANDMAPSCALE; mapParameter.Name = "动态统计专题图"; mapParameter.ColorMode = MapColorMode.DEFAULT; mapParameter.Layers = new List<Layer>(); mapParameter.Layers.Add(themeLayer); mapParameter.Viewer = new SuperMap.Connector.Utility.Rectangle(0, 0, 500, 400); Map map = new Map("http://" + ip + ":8090/iserver/services/map-jingjin/rest"); ImageOutputOption imgageOutputOption = new ImageOutputOption(); MapImage imageResult = map.GetMapImage("京津地区人口分布图_专题图", mapParameter, imgageOutputOption); using (MemoryStream memoryStream = new MemoryStream(imageResult.ImageData)) { Bitmap bmp = new Bitmap(memoryStream); Assert.IsTrue(bmp.Width == 500); Assert.IsTrue(bmp.Height == 400); Assert.IsTrue(bmp.GetPixel(309, 293).R == 211); Assert.IsTrue(bmp.GetPixel(309, 293).G == 111); Assert.IsTrue(bmp.GetPixel(309, 293).B == 240); } }
//public ActionResult Map() //{ // return View(); //} public ActionResult Map(string actionName) { ImageOutputOption imageOutputOption = new ImageOutputOption(); imageOutputOption.ImageOutputFormat = ImageOutputFormat.PNG; imageOutputOption.ImageReturnType = ImageReturnType.URL; MapParameter currentMapParameter = Session["MapParameter"] as MapParameter; string url = string.Empty; if (currentMapParameter == null) { MapParameter defaultMapParameter = map.GetDefaultMapParameter(mapName); currentMapParameter = new MapParameter(); currentMapParameter.Scale = defaultMapParameter.Scale; currentMapParameter.Center = new Point2D(defaultMapParameter.Center); currentMapParameter.ViewBounds = new Rectangle2D(defaultMapParameter.ViewBounds); currentMapParameter.RectifyType = RectifyType.BYCENTERANDMAPSCALE; currentMapParameter.Name = defaultMapParameter.Name; currentMapParameter.Viewer = new Rectangle(0, 0, 800, 600); } if (string.IsNullOrWhiteSpace(actionName)) { } else if ("ZoomIn" == actionName) { currentMapParameter.Scale = currentMapParameter.Scale * 2; } else if ("ZoomOut" == actionName) { currentMapParameter.Scale = currentMapParameter.Scale / 2; } else if ("LeftPan" == actionName) { currentMapParameter.Center.X = currentMapParameter.Center.X - ((currentMapParameter.ViewBounds.RightTop.X - currentMapParameter.ViewBounds.LeftBottom.X) / 4); } else if ("RightPan" == actionName) { currentMapParameter.Center.X = currentMapParameter.Center.X + ((currentMapParameter.ViewBounds.RightTop.X - currentMapParameter.ViewBounds.LeftBottom.X) / 4); } else if ("DownPan" == actionName) { currentMapParameter.Center.Y = currentMapParameter.Center.Y - ((currentMapParameter.ViewBounds.RightTop.Y - currentMapParameter.ViewBounds.LeftBottom.Y) / 4); } else if ("UpPan" == actionName) { currentMapParameter.Center.Y = currentMapParameter.Center.Y + ((currentMapParameter.ViewBounds.RightTop.Y - currentMapParameter.ViewBounds.LeftBottom.Y) / 4); } else if ("" == actionName) { } MapImage image = map.GetMapImage(mapName, currentMapParameter, imageOutputOption); if (image != null && image.MapParameter != null && image.MapParameter.ViewBounds != null) { currentMapParameter.ViewBounds = new Rectangle2D(image.MapParameter.ViewBounds); } url = image.ImageUrl; Session["MapParameter"] = currentMapParameter; ViewBag.url = url; return View(); }
public void GetOverviewTest_View() { Map map = new Map("http://" + ip + ":8090/iserver/services/map-world/rest"); string mapName = "世界地图"; MapParameter param = new MapParameter(); param.Viewer = new SuperMap.Connector.Utility.Rectangle(); param.Viewer.LeftTop = new SuperMap.Connector.Utility.Point(0, 0); param.Viewer.RightBottom = new SuperMap.Connector.Utility.Point(512, 512); ImageOutputOption option = new ImageOutputOption(); option.ImageOutputFormat = ImageOutputFormat.PNG; option.ImageReturnType = ImageReturnType.URL; Overview image = map.GetOverview(mapName, param, option); Assert.IsNotNull(image.ImageUrl); Assert.IsNull(image.ImageData); Assert.AreEqual(image.Viewer.Height, 512); Assert.AreEqual(image.Viewer.Width, 512); Assert.IsNotNull(image.LastModified); Assert.IsNotNull(image.ViewBounds); }