public static gView.Interoperability.AGS.Proxy.Geometry FromWebGIS(gView.Framework.Geometry.IGeometry geometry) { if (geometry == null) { return(null); } if (geometry is gView.Framework.Geometry.IEnvelope) { EnvelopeN env = new EnvelopeN(); env.XMin = ((gView.Framework.Geometry.IEnvelope)geometry).minx; env.YMin = ((gView.Framework.Geometry.IEnvelope)geometry).miny; env.XMax = ((gView.Framework.Geometry.IEnvelope)geometry).maxx; env.YMax = ((gView.Framework.Geometry.IEnvelope)geometry).maxy; return(env); } if (geometry is gView.Framework.Geometry.IPoint) { return(ToPoint((gView.Framework.Geometry.IPoint)geometry)); } if (geometry is gView.Framework.Geometry.IMultiPoint) { return(ToMultipoint((gView.Framework.Geometry.IMultiPoint)geometry)); } if (geometry is gView.Framework.Geometry.IPolyline) { return(ToPolyline((gView.Framework.Geometry.IPolyline)geometry)); } if (geometry is gView.Framework.Geometry.IPolygon) { return(ToPolygon((gView.Framework.Geometry.IPolygon)geometry)); } return(null); }
public static void TheTest(LayerDescription activelayerdesc, SpatialFilter spatialfilter, SpatialReference sp1, SpatialReference sp2) { string oIDFieldName = MapServiceFidTests.GetOIDFieldName(MapServiceFidTests._mapinfo, activelayerdesc.LayerID); spatialfilter.OutputSpatialReference = sp1; EnvelopeN envelopeN = spatialfilter.FilterGeometry as EnvelopeN; envelopeN.SpatialReference = sp2; spatialfilter.FilterGeometry = envelopeN; FIDSet fIDSet = MapServiceFidTests.BuildFIDSet(MapServiceFidTests.name, activelayerdesc, spatialfilter); QueryFilter queryFilter = MapServiceFidTests.BuildQueryFromFIDSet(fIDSet, sp1); queryFilter.OutputSpatialReference = sp1; RecordSet recordSet = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, false); RecordSet rs = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, true); int num = MapServiceFidTests.FindGeometryFieldIndex(recordSet); SpatialReference spatialReference = recordSet.Fields.FieldArray[num].GeometryDef.SpatialReference; recordSet = MapServiceFidTests.ProjectRecordSet(MapServiceFidTests._mapinfo.FullExtent, recordSet, num, spatialReference, sp2); rs = MapServiceFidTests.ProjectRecordSet(MapServiceFidTests._mapinfo.FullExtent, rs, num, spatialReference, sp2); FIDSet fIDSet2 = MapServiceFidTests.BuildDeltaFIDSet(fIDSet, recordSet, oIDFieldName); while (fIDSet2.FIDArray.Length > 0) { queryFilter = MapServiceFidTests.BuildQueryFromFIDSet(fIDSet2, sp1); queryFilter.OutputSpatialReference = sp1; recordSet = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, false); rs = MapServiceFidTests.QueryFeatures(activelayerdesc, queryFilter, true); fIDSet2 = MapServiceFidTests.BuildDeltaFIDSet(fIDSet2, recordSet, oIDFieldName); } }
/// <summary> /// Gets map extent for stop with selected radius around. /// </summary> /// <param name="stop">Stop to getting position.</param> /// <param name="extentRadiusInUnits">Extent radius [units].</param> /// <returns>Map extent for stop.</returns> private EnvelopeN _GetExtent(Stop stop, double extentRadiusInUnits) { Debug.Assert(null != stop); Debug.Assert(0 < extentRadiusInUnits); AppGeometry.Point point = stop.MapLocation.Value; double stopX = point.X; double stopY = point.Y; double extentRadius = DistCalc.GetExtentRadius(stopX, stopY, extentRadiusInUnits); // project extent to map spatial reference AppGeometry.Point leftTop = new AppGeometry.Point(stopX - extentRadius, stopY + extentRadius); AppGeometry.Point rightBottom = new AppGeometry.Point(stopX + extentRadius, stopY - extentRadius); int spatialRefId = _mapInfo.SpatialReference.WKID; leftTop = WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialRefId); rightBottom = WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialRefId); // create extent in correct projection EnvelopeN extent = new EnvelopeN(); extent.XMin = leftTop.X; extent.XMax = rightBottom.X; extent.YMin = rightBottom.Y; extent.YMax = leftTop.Y; return(extent); }
public static SpatialFilter BuildSpatialFilter(EnvelopeN env, string geomField, SpatialReference spRef) { SpatialFilter result; try { SpatialFilter spatialFilter = new SpatialFilter(); env.SpatialReference = spRef; spatialFilter.FilterGeometry = env; if (!string.IsNullOrEmpty(geomField)) { spatialFilter.GeometryFieldName = geomField; } spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; if (!string.IsNullOrEmpty(env.SpatialReference.WKT)) { string wKT = env.SpatialReference.WKT; spatialFilter.OutputSpatialReference = MapServiceFidTests.SpRefFromWKT(ref wKT); } else if (env.SpatialReference.WKIDSpecified) { int wKID = env.SpatialReference.WKID; spatialFilter.OutputSpatialReference = MapServiceFidTests.SpRefFromWKID(ref wKID); } result = spatialFilter; } catch { result = null; } return(result); }
/// <summary> /// Gets route's stop image. /// </summary> /// <param name="route">Route for draw.</param> /// <param name="stop">Stop for draw.</param> /// <param name="extentRadius">Radius of extent indent of stop.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Created route image, or null if not inited.</returns> private Image _GetStopImage(Route route, Stop stop, double extentRadius, int height, int width, int dpi) { Debug.Assert(null != route); Debug.Assert(null != stop); Debug.Assert(0 < extentRadius); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); Image image = null; IList <Stop> routeStops = CommonHelpers.GetSortedStops(route); if (((stop.AssociatedObject != routeStops[0].AssociatedObject) || _showLeadingStemTime) && ((stop.AssociatedObject != routeStops[routeStops.Count - 1].AssociatedObject) || _showTrailingStemTime)) { EnvelopeN extent = _GetExtent(stop, extentRadius); image = _CreateImage(route, routeStops, extent, width, height, dpi); } return(image); }
public static EnvelopeN InitializeEnvelope(EnvelopeN baseEnv, Extent bbox) { EnvelopeN result; try { EnvelopeN envelopeN; if (baseEnv == null) { envelopeN = baseEnv; } else { envelopeN = new EnvelopeN(); } envelopeN.XMin = bbox.XMin.Value; envelopeN.XMax = bbox.XMax.Value; envelopeN.YMin = bbox.YMin.Value; envelopeN.YMax = bbox.YMax.Value; envelopeN.SpatialReference = AGSSpatialReference.SpRefFromString(bbox.SpatialReference); result = envelopeN; } catch { result = baseEnv; } return(result); }
/// <summary> /// Gets image by service. /// </summary> /// <param name="extent">Map area extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Getted image.</returns> private MapImage _GetImage(EnvelopeN extent, int width, int height, int dpi) { Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); MapImage mapImage = null; try { var imgdDisplay = new ImageDisplay(); imgdDisplay.ImageHeight = height; imgdDisplay.ImageWidth = width; imgdDisplay.ImageDPI = dpi; _imgDescription.ImageDisplay = imgdDisplay; _mapDescription.MapArea.Extent = extent; mapImage = _mapService.ExportMapImage(_mapDescription, _imgDescription); } catch (Exception ex) { if (ex is AuthenticationException || ex is CommunicationException) { _serviceInWorkedState = false; } throw; // exception } _imgDescription.ImageDisplay = null; return(mapImage); }
private void GetCenterPointAndDistance(EnvelopeN extent, out PointN center, out double distance) { center = new PointN(); center.SpatialReference = extent.SpatialReference; center.X = extent.XMin + (Math.Abs(extent.XMax - extent.XMin)/2); center.Y = extent.YMin + (Math.Abs(extent.YMax - extent.YMin)/2); distance = Math.Abs(extent.XMax - extent.XMin)/10; }
private void GetCenterPointAndDistance(EnvelopeN extent, out PointN center, out double distance) { center = new PointN(); center.SpatialReference = extent.SpatialReference; center.X = extent.XMin + (Math.Abs(extent.XMax - extent.XMin) / 2); center.Y = extent.YMin + (Math.Abs(extent.YMax - extent.YMin) / 2); distance = Math.Abs(extent.XMax - extent.XMin) / 10; }
private static void DumpSpatialFilter(SpatialFilter sf) { EnvelopeN env = (EnvelopeN)sf.FilterGeometry; MapServiceFidTests.DumpEnvelope(env); MapServiceFidTests.DumpSpatialReference(sf.OutputSpatialReference); if (!string.IsNullOrEmpty(sf.WhereClause)) { return; } string arg_31_0 = sf.WhereClause; }
public static EnvelopeN EnvelopeN(gView.Framework.Geometry.IEnvelope env) { if (env == null) { return(null); } EnvelopeN e = new EnvelopeN(); e.XMin = env.minx; e.YMin = env.miny; e.XMax = env.maxx; e.YMax = env.maxy; return(e); }
private void button1_Click(object sender, EventArgs e) { try { //create instance of proxy var nearFeatsService = new localhost.USA_NetFindNearFeaturesSoapSOE(); nearFeatsService.Url = "http://localhost:6080/arcgis/services/USA/MapServer/NetFindNearFeaturesSoapSOE"; //getLayerInfos CustomLayerInfo[] layerInfos = nearFeatsService.GetLayerInfos(); foreach (CustomLayerInfo layerInfo in layerInfos) { EnvelopeN extent = (EnvelopeN)layerInfo.Extent; debug( string.Format("Layer {0} has ID: {1} and extent: {2},{3},{4},{5}", layerInfo.Name, layerInfo.ID, extent.XMin, extent.YMin, extent.XMax, extent.YMax)); } //findNearFeatures CustomLayerInfo aLayerInfo = layerInfos[0]; PointN location; double distance; GetCenterPointAndDistance((EnvelopeN)aLayerInfo.Extent, out location, out distance); RecordSet feats = nearFeatsService.FindNearFeatures(aLayerInfo.ID, location, distance); foreach (Record record in feats.Records) { foreach (object o in record.Values) { if (o != null) { debug(o.ToString() + ", "); } } debug("\n"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Gets route image with drawn stops. /// </summary> /// <param name="route">Route for draw.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Created route image, or null if not inited.</returns> private Image _GetRouteImage(Route route, int width, int height, int dpi) { Debug.Assert(null != route); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); IList <Stop> sortedRouteStops = CommonHelpers.GetSortedStops(route); EnvelopeN extent = _GetExtent(route, sortedRouteStops); Image image = _CreateImage(route, sortedRouteStops, extent, width, height, dpi); return(image); }
/// <summary> /// Converts from map coordinates to screen. /// </summary> /// <param name="mapPoint">Point to conversion (in map coordinates).</param> /// <param name="extent">Map extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <returns>Converted point in screen coordinates.</returns> private SysWindows.Point _ConvertPoint(AppGeometry.Point mapPoint, EnvelopeN extent, double width, double height) { Debug.Assert(null != mapPoint); Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); AppGeometry.Point projectedPointFrom = WebMercatorUtil.ProjectPointToWebMercator(mapPoint, _mapInfo.SpatialReference.WKID); double x = width * (projectedPointFrom.X - extent.XMin) / (extent.XMax - extent.XMin); double y = height - height * (projectedPointFrom.Y - extent.YMin) / (extent.YMax - extent.YMin); SysWindows.Point pointTo = new SysWindows.Point(x, y); return(pointTo); }
public static SpatialFilter BuildSpatialFilter(EnvelopeN env, string geomField) { SpatialFilter result; try { SpatialFilter spatialFilter = new SpatialFilter(); spatialFilter.FilterGeometry = env; if (!string.IsNullOrEmpty(geomField)) { spatialFilter.GeometryFieldName = geomField; } spatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelEnvelopeIntersects; result = spatialFilter; } catch { result = null; } return(result); }
/// <summary> /// Creates image. /// </summary> /// <param name="route">Route for draw.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <param name="extent">Image extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Created image.</returns> private Image _CreateImage(Route route, IList <Stop> sortedRouteStops, EnvelopeN extent, int width, int height, int dpi) { Debug.Assert(null != route); Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); _LoadSymbolTemplates(); MapImage mapImage = _GetImage(extent, width, height, dpi); SysControls.Canvas canvas = _CreateRouteCanvas(route, sortedRouteStops, mapImage); Image image = _CreateImage(mapImage, canvas); return(image); }
public EnvelopeN ProjectEnvelope(EnvelopeN env, SpatialReference inSR, SpatialReference outSR) { Geometry[] inGeometryArray = new Geometry[] { env }; EnvelopeN result; try { Geometry[] array = this._GeomServer.Project(inSR, outSR, true, null, env, inGeometryArray); EnvelopeN envelopeN = array[0] as EnvelopeN; envelopeN.SpatialReference = outSR; result = envelopeN; } catch { if (base.Parent.Challenge()) { this._GeomServer.Credentials = base.Parent.Credentials; if (this._GeomServer.Credentials == null) { this._GeomServer.UseDefaultCredentials = true; } this._GeomServer.Proxy = WebRequest.DefaultWebProxy; Geometry[] array2 = this._GeomServer.Project(inSR, outSR, true, null, env, inGeometryArray); EnvelopeN envelopeN2 = array2[0] as EnvelopeN; envelopeN2.SpatialReference = outSR; result = envelopeN2; } else { result = null; } } return(result); }
private void DoTask() { try { if (this.Mapservice == null || this.Mapdesc == null || this.Imagedescription == null) { this._errMsg.Append("Insufficient map information to generate request"); } else if (this.UpdateForm == null) { this._errMsg.Append("Update form not initialized"); } else { this.UpdateForm.SetReady(false); MapImage mapImage = this.Mapservice.ExportMapImage(this.Mapdesc, this.Imagedescription); string imageURL = mapImage.ImageURL; if (string.IsNullOrEmpty(imageURL)) { this._errMsg.Append("ErrorGeneratingImage"); } else { this._errMsg.Append("Map successfully retrieved"); this._returnData.AddRange(new string[] { mapImage.ImageURL }); EnvelopeN envelopeN = mapImage.Extent as EnvelopeN; PointN[] array = new PointN[] { new PointN { SpatialReference = envelopeN.SpatialReference, X = envelopeN.XMin, Y = envelopeN.YMin, Z = 0.0 }, new PointN { SpatialReference = envelopeN.SpatialReference, X = envelopeN.XMax, Y = envelopeN.YMin, Z = 0.0 }, new PointN { SpatialReference = envelopeN.SpatialReference, X = envelopeN.XMin, Y = envelopeN.YMax, Z = 0.0 } }; try { if (!string.IsNullOrEmpty(this.OutputFile)) { if (File.Exists(this.OutputFile)) { File.Delete(this.OutputFile); if (App.TempFiles.Contains(this.OutputFile)) { App.TempFiles.Remove(this.OutputFile); } } WebClient webClient = new WebClient(); webClient.Proxy = this.Mapservice.Proxy; webClient.Credentials = this.Mapservice.Credentials; if (webClient.Credentials == null) { webClient.UseDefaultCredentials = true; } webClient.DownloadFile(imageURL, this.OutputFile); App.TempFiles.Add(this.OutputFile); } } catch { this.UpdateForm.SetReady(false); return; } this.UpdateForm.SetReady(false); Point3d point3d = new Point3d(array[0].X, array[0].Y, 0.0); Point3d point3d2 = new Point3d(array[1].X, array[1].Y, 0.0); Point3d point3d3 = new Point3d(array[2].X, array[2].Y, 0.0); this.UpdateForm.V1 = point3d2 - point3d; this.UpdateForm.V2 = point3d3 - point3d; this.UpdateForm.BasePoint = point3d; this.UpdateForm.ImageURL = this.OutputFile; this.UpdateForm.SetReady(true); } } } catch (SystemException ex) { this.UpdateForm.SetReady(false); this._errMsg.Append(ex.Message); } }
/// <summary> /// Gets map extent for route. /// </summary> /// <param name="route">Route to getting points.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <returns>Map extent for route (all points on map).</returns> private EnvelopeN _GetExtent(Route route, IList <Stop> sortedRouteStops) { Debug.Assert(null != route); Debug.Assert(null != sortedRouteStops); int spatialRefId = _mapInfo.SpatialReference.WKID; int startIndex = _GetStartIndex(route, sortedRouteStops); int processCount = _GetProcessStopCount(route, sortedRouteStops); var points = new List <AppGeometry.Point>(); bool isStartFound = false; for (int stopIndex = startIndex; stopIndex < processCount; ++stopIndex) { Stop stop = sortedRouteStops[stopIndex]; // NOTE: path to first stop not showing if (isStartFound && (null != stop.Path) && !stop.Path.IsEmpty) { for (int index = 0; index < stop.Path.Groups.Length; ++index) { AppGeometry.Point[] pointsArray = stop.Path.GetGroupPoints(index); foreach (AppGeometry.Point point in pointsArray) { AppGeometry.Point pt = WebMercatorUtil.ProjectPointToWebMercator(point, spatialRefId); points.Add(pt); } } } if (stop.MapLocation.HasValue) { AppGeometry.Point location = stop.MapLocation.Value; AppGeometry.Point loc = WebMercatorUtil.ProjectPointToWebMercator(location, spatialRefId); points.Add(loc); if (!isStartFound) { isStartFound = true; } } } var rect = new AppGeometry.Envelope(); rect.SetEmpty(); foreach (AppGeometry.Point point in points) { rect.Union(point); } // increase extent double heightInc = ROUTE_EXTENT_INDENT * rect.Height; if (heightInc == 0) { heightInc = ROUTE_EXTENT_INDENT; } double widthInc = ROUTE_EXTENT_INDENT * rect.Width; if (widthInc == 0) { widthInc = ROUTE_EXTENT_INDENT; } rect.left -= widthInc; rect.right += widthInc; rect.top += heightInc; rect.bottom -= heightInc; var extent = new EnvelopeN(); extent.XMax = rect.right; extent.XMin = rect.left; extent.YMax = rect.top; extent.YMin = rect.bottom; return(extent); }
public bool Open(gView.MapServer.IServiceRequestContext context) { if (_class == null) { _class = new AGSClass(this); } #region Parameters string server = ConfigTextStream.ExtractValue(ConnectionString, "server"); string service = ConfigTextStream.ExtractValue(ConnectionString, "service"); string user = ConfigTextStream.ExtractValue(ConnectionString, "user"); string pwd = ConfigTextStream.ExtractValue(ConnectionString, "pwd"); if ((user == "#" || user == "$") && context != null && context.ServiceRequest != null && context.ServiceRequest.Identity != null) { string roles = String.Empty; if (user == "#" && context.ServiceRequest.Identity.UserRoles != null) { foreach (string role in context.ServiceRequest.Identity.UserRoles) { if (String.IsNullOrEmpty(role)) { continue; } roles += "|" + role; } } user = context.ServiceRequest.Identity.UserName + roles; pwd = context.ServiceRequest.Identity.HashedPassword; } #endregion try { _proxy = ProxySettings.Proxy(server); _themes.Clear(); _parentIds.Clear(); _mapServer = new gView.Interoperability.AGS.Proxy.MapServer(service); _mapServer.Proxy = gView.Framework.Web.ProxySettings.Proxy(service); MapServerInfo msi = _mapServer.GetServerInfo(_mapServer.GetDefaultMapName()); _mapDescription = msi.DefaultMapDescription; MapLayerInfo[] mapLayerInfos = msi.MapLayerInfos; foreach (MapLayerInfo layerInfo in mapLayerInfos) { if (layerInfo.Extent is EnvelopeN) { EnvelopeN env = (EnvelopeN)layerInfo.Extent; if (_envelope == null) { _envelope = new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax); } else { _envelope.Union(new gView.Framework.Geometry.Envelope(env.XMin, env.YMin, env.XMax, env.YMax)); } } CalcParentLayerIds(mapLayerInfos, layerInfo.LayerID); IClass themeClass = null; IWebServiceTheme theme = null; LayerDescription ld = LayerDescriptionById(layerInfo.LayerID); if (ld == null) { continue; } if (layerInfo.LayerType == "Feature Layer") { #region Geometry Type (Point, Line, Polygon) geometryType geomType = geometryType.Unknown; if (layerInfo.Fields != null) { foreach (Proxy.Field fieldInfo in layerInfo.Fields.FieldArray) { if (fieldInfo.Type == esriFieldType.esriFieldTypeGeometry && fieldInfo.GeometryDef != null) { switch (fieldInfo.GeometryDef.GeometryType) { case esriGeometryType.esriGeometryMultipoint: case esriGeometryType.esriGeometryPoint: geomType = geometryType.Point; break; case esriGeometryType.esriGeometryPolyline: geomType = geometryType.Polyline; break; case esriGeometryType.esriGeometryPolygon: geomType = geometryType.Polygon; break; case esriGeometryType.esriGeometryMultiPatch: break; } } } } #endregion themeClass = new AGSThemeFeatureClass(this, layerInfo, geomType); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } else if (layerInfo.LayerType == "Raster Layer" || layerInfo.LayerType == "Raster Catalog Layer") { themeClass = new AGSThemeRasterClass(this, layerInfo); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } else { MapLayerInfo parentLayer = MapLayerInfoById(mapLayerInfos, layerInfo.ParentLayerID); if (parentLayer != null && parentLayer.LayerType == "Annotation Layer") { themeClass = new AGSThemeFeatureClass(this, layerInfo, geometryType.Polygon); theme = LayerFactory.Create(themeClass, _class as IWebServiceClass) as IWebServiceTheme; if (theme == null) { continue; } } } if (theme != null) { theme.MinimumScale = layerInfo.MaxScale; theme.MaximumScale = layerInfo.MinScale; theme.Visible = ld.Visible; _themes.Add(theme); } } _state = DatasetState.opened; return(true); } catch (Exception ex) { _state = DatasetState.unknown; _errMsg = ex.Message; return(false); } }
public RasterInfo(string imageURL, TiledRaster.ViewInfo v, EnvelopeN env) { this.View = v; this.url = imageURL; this.ActualPosition = (EnvelopeN)Utility.CloneObject(env); }
private void SampleGetTileInfo() { string defaultMapName = this._mapservice.GetDefaultMapName(); this._mapservice.GetServerInfo(defaultMapName); MapDescription defaultMapDescription = this._mapinfo.DefaultMapDescription; string virtualCacheDirectory = this._mapservice.GetVirtualCacheDirectory(defaultMapName, -1); int num = 400; int height = 400; EnvelopeN envelopeN = (EnvelopeN)defaultMapDescription.MapArea.Extent; double num2 = Math.Abs(envelopeN.XMax - envelopeN.XMin) / (double)num; Bitmap bitmap = new Bitmap(num, height); Graphics graphics = Graphics.FromImage(bitmap); graphics.FillRectangle(new SolidBrush(System.Drawing.Color.LightGray), 0, 0, num, height); if (this._mapservice.HasSingleFusedMapCache(defaultMapName)) { TileCacheInfo tileCacheInfo = this._mapservice.GetTileCacheInfo(defaultMapName); LODInfo[] lODInfos = tileCacheInfo.LODInfos; double num3 = 0.0; int level = 0; LODInfo[] array = lODInfos; for (int i = 0; i < array.Length; i++) { LODInfo lODInfo = array[i]; double resolution = lODInfo.Resolution; num3 = resolution; level = lODInfo.LevelID; if (num2 >= resolution) { break; } } double xMin = envelopeN.XMin; double yMin = envelopeN.YMin; double xMax = envelopeN.XMax; double yMax = envelopeN.YMax; double x = ((PointN)tileCacheInfo.TileOrigin).X; double y = ((PointN)tileCacheInfo.TileOrigin).Y; double d = (xMin - x) / ((double)tileCacheInfo.TileCols * num3); double d2 = (y - yMax) / ((double)tileCacheInfo.TileRows * num3); double d3 = (xMax - x) / ((double)tileCacheInfo.TileCols * num3); double d4 = (y - yMin) / ((double)tileCacheInfo.TileRows * num3); int num4 = (int)Math.Floor(d); int num5 = (int)Math.Floor(d2); int num6 = (int)Math.Floor(d3); int num7 = (int)Math.Floor(d4); double num8 = x + (double)num4 * ((double)tileCacheInfo.TileCols * num3); double num9 = y - (double)num5 * ((double)tileCacheInfo.TileRows * num3); double num10 = Math.Abs(xMin - num8); double num11 = Math.Abs(yMax - num9); int num12 = (int)(num10 / num3); int num13 = (int)(num11 / num3); TileImageInfo tileImageInfo = this._mapservice.GetTileImageInfo(this._mapservice.GetDefaultMapName()); int num14 = 0; for (int j = num5; j <= num7; j++) { int num15 = 0; for (int k = num4; k <= num6; k++) { byte[] array2 = null; try { array2 = this._mapservice.GetMapTile(defaultMapName, level, j, k, tileImageInfo.CacheTileFormat); string text = "png"; string requestUriString = string.Concat(new string[] { virtualCacheDirectory, "/L", level.ToString().PadLeft(2, '0'), "/R", j.ToString("x").PadLeft(8, '0'), "/C", k.ToString("x").PadLeft(8, '0'), text }); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(requestUriString); HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream responseStream = httpWebResponse.GetResponseStream(); MemoryStream memoryStream = new MemoryStream(); int num16; while ((num16 = responseStream.ReadByte()) != -1) { memoryStream.WriteByte((byte)num16); } array2 = memoryStream.ToArray(); } catch { } if (array2 != null) { using (MemoryStream memoryStream2 = new MemoryStream(array2, 0, array2.Length)) { memoryStream2.Write(array2, 0, array2.Length); Image image = Image.FromStream(memoryStream2, true); graphics.DrawImage(image, tileCacheInfo.TileCols * num15 - num12, tileCacheInfo.TileRows * num14 - num13, tileCacheInfo.TileCols, tileCacheInfo.TileRows); } } num15++; } num14++; } } string filename = Utility.TemporaryFilePath() + ".bmp"; bitmap.Save(filename, ImageFormat.Bmp); Bitmap bitmap2 = new Bitmap(num, height); Graphics graphics2 = Graphics.FromImage(bitmap2); graphics2.FillRectangle(new SolidBrush(System.Drawing.Color.LightGray), 0, 0, num, height); graphics2.DrawImage(bitmap, 0, 0, num, height); string filename2 = Utility.TemporaryFilePath() + ".bmp"; bitmap2.Save(filename2, ImageFormat.Bmp); }
/// <summary> /// Gets image by service. /// </summary> /// <param name="extent">Map area extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Getted image.</returns> private MapImage _GetImage(EnvelopeN extent, int width, int height, int dpi) { Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); MapImage mapImage = null; try { var imgdDisplay = new ImageDisplay(); imgdDisplay.ImageHeight = height; imgdDisplay.ImageWidth = width; imgdDisplay.ImageDPI = dpi; _imgDescription.ImageDisplay = imgdDisplay; _mapDescription.MapArea.Extent = extent; mapImage = _mapService.ExportMapImage(_mapDescription, _imgDescription); } catch (Exception ex) { if (ex is AuthenticationException || ex is CommunicationException) _serviceInWorkedState = false; throw; // exception } _imgDescription.ImageDisplay = null; return mapImage; }
/// <summary> /// Gets map extent for route. /// </summary> /// <param name="route">Route to getting points.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <returns>Map extent for route (all points on map).</returns> private EnvelopeN _GetExtent(Route route, IList<Stop> sortedRouteStops) { Debug.Assert(null != route); Debug.Assert(null != sortedRouteStops); int spatialRefId = _mapInfo.SpatialReference.WKID; int startIndex = _GetStartIndex(route, sortedRouteStops); int processCount = _GetProcessStopCount(route, sortedRouteStops); var points = new List<AppGeometry.Point>(); bool isStartFound = false; for (int stopIndex = startIndex; stopIndex < processCount; ++stopIndex) { Stop stop = sortedRouteStops[stopIndex]; // NOTE: path to first stop not showing if (isStartFound && (null != stop.Path) && !stop.Path.IsEmpty) { for (int index = 0; index < stop.Path.Groups.Length; ++index) { AppGeometry.Point[] pointsArray = stop.Path.GetGroupPoints(index); foreach (AppGeometry.Point point in pointsArray) { AppGeometry.Point pt = WebMercatorUtil.ProjectPointToWebMercator(point, spatialRefId); points.Add(pt); } } } if (stop.MapLocation.HasValue) { AppGeometry.Point location = stop.MapLocation.Value; AppGeometry.Point loc = WebMercatorUtil.ProjectPointToWebMercator(location, spatialRefId); points.Add(loc); if (!isStartFound) { isStartFound = true; } } } var rect = new AppGeometry.Envelope(); rect.SetEmpty(); foreach (AppGeometry.Point point in points) rect.Union(point); // increase extent double heightInc = ROUTE_EXTENT_INDENT * rect.Height; if (heightInc == 0) heightInc = ROUTE_EXTENT_INDENT; double widthInc = ROUTE_EXTENT_INDENT * rect.Width; if (widthInc == 0) widthInc = ROUTE_EXTENT_INDENT; rect.left -= widthInc; rect.right += widthInc; rect.top += heightInc; rect.bottom -= heightInc; var extent = new EnvelopeN(); extent.XMax = rect.right; extent.XMin = rect.left; extent.YMax = rect.top; extent.YMin = rect.bottom; return extent; }
/// <summary> /// Gets map extent for stop with selected radius around. /// </summary> /// <param name="stop">Stop to getting position.</param> /// <param name="extentRadiusInUnits">Extent radius [units].</param> /// <returns>Map extent for stop.</returns> private EnvelopeN _GetExtent(Stop stop, double extentRadiusInUnits) { Debug.Assert(null != stop); Debug.Assert(0 < extentRadiusInUnits); AppGeometry.Point point = stop.MapLocation.Value; double stopX = point.X; double stopY = point.Y; double extentRadius = DistCalc.GetExtentRadius(stopX, stopY, extentRadiusInUnits); // project extent to map spatial reference AppGeometry.Point leftTop = new AppGeometry.Point(stopX - extentRadius, stopY + extentRadius); AppGeometry.Point rightBottom = new AppGeometry.Point(stopX + extentRadius, stopY - extentRadius); int spatialRefId = _mapInfo.SpatialReference.WKID; leftTop = WebMercatorUtil.ProjectPointToWebMercator(leftTop, spatialRefId); rightBottom = WebMercatorUtil.ProjectPointToWebMercator(rightBottom, spatialRefId); // create extent in correct projection EnvelopeN extent = new EnvelopeN(); extent.XMin = leftTop.X; extent.XMax = rightBottom.X; extent.YMin = rightBottom.Y; extent.YMax = leftTop.Y; return extent; }
/// <summary> /// Converts from map coordinates to screen. /// </summary> /// <param name="mapPoint">Point to conversion (in map coordinates).</param> /// <param name="extent">Map extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <returns>Converted point in screen coordinates.</returns> private SysWindows.Point _ConvertPoint(AppGeometry.Point mapPoint, EnvelopeN extent, double width, double height) { Debug.Assert(null != mapPoint); Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); AppGeometry.Point projectedPointFrom = WebMercatorUtil.ProjectPointToWebMercator(mapPoint, _mapInfo.SpatialReference.WKID); double x = width * (projectedPointFrom.X - extent.XMin) / (extent.XMax - extent.XMin); double y = height - height * (projectedPointFrom.Y - extent.YMin) / (extent.YMax - extent.YMin); SysWindows.Point pointTo = new SysWindows.Point(x, y); return pointTo; }
/// <summary> /// Creates image. /// </summary> /// <param name="route">Route for draw.</param> /// <param name="sortedRouteStops">Sorted stops from route.</param> /// <param name="extent">Image extent.</param> /// <param name="width">Image width.</param> /// <param name="height">Image height.</param> /// <param name="dpi">Image DPI.</param> /// <returns>Created image.</returns> private Image _CreateImage(Route route, IList<Stop> sortedRouteStops, EnvelopeN extent, int width, int height, int dpi) { Debug.Assert(null != route); Debug.Assert(null != extent); Debug.Assert(0 < width); Debug.Assert(0 < height); Debug.Assert(0 < dpi); _LoadSymbolTemplates(); MapImage mapImage = _GetImage(extent, width, height, dpi); SysControls.Canvas canvas = _CreateRouteCanvas(route, sortedRouteStops, mapImage); Image image = _CreateImage(mapImage, canvas); return image; }
private static void DumpEnvelope(EnvelopeN env) { MapServiceFidTests.DumpSpatialReference(env.SpatialReference); }