private void _2DLink3D() { if (b3To2 || b2To3) { b3To2 = false; b2To3 = false; return; } b2To3 = true; DF2DApplication app2D = DF2DApplication.Application; DF3DApplication app3D = DF3DApplication.Application; if (app2D == null || app3D == null || app2D.Current2DMapControl == null || app3D.Current3DMapControl == null) { return; } ESRI.ArcGIS.Geometry.IEnvelope env = app2D.Current2DMapControl.Extent; ICamera camera3D = app3D.Current3DMapControl.Camera; Gvitech.CityMaker.Math.IEulerAngle angle = new Gvitech.CityMaker.Math.EulerAngle(); Gvitech.CityMaker.Math.IVector3 pos = new Gvitech.CityMaker.Math.Vector3(); camera3D.GetCamera(out pos, out angle); double ox, oy, oz; Link2DAnd3D._2DLink3D(env.XMin, env.XMax, env.YMin, env.YMax, Math.Abs(angle.Tilt * Math.PI / 180), camera3D.VerticalFieldOfView * Math.PI / 180, out ox, out oy, out oz); pos.Set(ox, oy, oz); camera3D.SetCamera(pos, angle, gviSetCameraFlags.gviSetCameraNoFlags); }
private void _3DLink2D(double x, double y, double z) { if (b3To2 || b2To3) { b3To2 = false; b2To3 = false; return; } b3To2 = true; DF2DApplication app2D = DF2DApplication.Application; DF3DApplication app3D = DF3DApplication.Application; if (app2D == null || app3D == null || app2D.Current2DMapControl == null || app3D.Current3DMapControl == null) { return; } ICamera camera3D = app3D.Current3DMapControl.Camera; Gvitech.CityMaker.Math.IEulerAngle angle = new Gvitech.CityMaker.Math.EulerAngle(); Gvitech.CityMaker.Math.IVector3 pos = new Gvitech.CityMaker.Math.Vector3(); camera3D.GetCamera(out pos, out angle); ESRI.ArcGIS.Geometry.IEnvelope env = app2D.Current2DMapControl.Extent; double width = env.XMax - env.XMin; double height = env.YMax - env.YMin; double rate = width / height; double xmin, ymin, xmax, ymax; Link2DAnd3D._3DLink2D(x, y, z, Math.Abs(angle.Tilt * Math.PI / 180), camera3D.VerticalFieldOfView * Math.PI / 180, rate, out xmin, out ymin, out xmax, out ymax); ESRI.ArcGIS.Geometry.IEnvelope env1 = new ESRI.ArcGIS.Geometry.EnvelopeClass(); env1.PutCoords(xmin, ymin, xmax, ymax); app2D.Current2DMapControl.Extent = env1; }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { if (m_hookHelper.Hook == null) { return; } IMapControl2 pMapCtl = m_hookHelper.Hook as IMapControl2; ESRI.ArcGIS.Geometry.IEnvelope pGeometry = pMapCtl.TrackRectangle(); if (pGeometry == null) { return; } ESRI.ArcGIS.Carto.IMap pMap = m_hookHelper.FocusMap; //更改获取面积的方法,20111123 double area = GetArea(pGeometry, pMap); double dArea = SysCommon.ModSysSetting.GetExportAreaOfUser(Plugin.ModuleCommon.TmpWorkSpace, m_pAppForm.ConnUser); if (dArea >= 0 && area > dArea) { MessageBox.Show("超过提取最大面积", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } drawgeometryXOR(pGeometry as IGeometry); frm = new frmExport(pMap, pGeometry); frm.WriteLog = WriteLog; //ygc 2012-9-12 是否写日志 frm.m_area = area; //ZQ 2011 1126 modify SysCommon.ScreenDraw.list.Add(ToolEvnelopeExportAfterDraw); frm.FormClosed += new FormClosedEventHandler(frm_FormClosed); frm.ShowDialog(); }
private void buttonX2_Click(object sender, EventArgs e) { ESRI.ArcGIS.Analyst3D.IScene scene = (ESRI.ArcGIS.Analyst3D.IScene)GlobeControl.Globe; // Explicit cast. ESRI.ArcGIS.Geometry.IEnvelope envelope = GlobalValues.element3D.Geometry.Envelope; ESRI.ArcGIS.Analyst3D.ICamera camera = GlobeControl.Globe.GlobeDisplay.ActiveViewer.Camera; ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera = (ESRI.ArcGIS.GlobeCore.IGlobeCamera) camera; // Explicit cast. ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer = GlobeControl.Globe.GlobeDisplay.ActiveViewer; globeCamera.SetToZoomToExtents(envelope, GlobeControl.Globe, sceneViewer); }
/// <summary> /// Gets the number of map units for a given number of pixels /// </summary> /// <param name="pixelUnits">number of pixels to convert</param> /// <returns>double</returns> /// <remarks>Converted from http://resources.esri.com/help/9.3/ArcGISDesktop/com/samples/Cartography/Display/dc78c617-adbb-4145-bc9a-530230905f80.htm</remarks> public double ConvertPixelsToMapUnits(double pixelUnits) { double realWorldDisplayExtent = 0; long pixelExtent = 0; double sizeOfOnePixel = 0; ESRI.ArcGIS.Display.IDisplayTransformation pDT = null; tagRECT deviceRECT; ESRI.ArcGIS.Geometry.IEnvelope pEnv = null; ESRI.ArcGIS.Carto.IActiveView pActiveView = null; // Get the width of the display extents in Pixels // and get the extent of the displayed data // work out the size of one pixel and then return // the pixels units passed in mulitplied by that value pActiveView = this.ActiveView; // Get IDisplayTransformation pDT = pActiveView.ScreenDisplay.DisplayTransformation; // Get the device frame which will give us the number of pixels in the X direction deviceRECT = pDT.get_DeviceFrame(); pixelExtent = deviceRECT.right - deviceRECT.left; // Now get the map extent of the currently visible area pEnv = pDT.VisibleBounds; // Calculate the size of one pixel realWorldDisplayExtent = pEnv.Width; sizeOfOnePixel = realWorldDisplayExtent / pixelExtent; //Multiply this by the input argument to get the result return(pixelUnits * sizeOfOnePixel); }
public void ZoomToSelectedGlobeFeatures(ESRI.ArcGIS.GlobeCore.IGlobe globe, IEnvelope pEv, string name) { ESRI.ArcGIS.GlobeCore.IGlobeDisplay globeDisplay = globe.GlobeDisplay; ESRI.ArcGIS.Analyst3D.ISceneViewer sceneViewer = globeDisplay.ActiveViewer; ESRI.ArcGIS.Analyst3D.ICamera camera = sceneViewer.Camera; ESRI.ArcGIS.GlobeCore.IGlobeCamera globeCamera = (ESRI.ArcGIS.GlobeCore.IGlobeCamera)camera; ESRI.ArcGIS.Analyst3D.IScene scene = globeDisplay.Scene; ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); envelope.SetEmpty(); ESRI.ArcGIS.Geometry.IEnvelope layersExtentEnvelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); layersExtentEnvelope.SetEmpty(); ESRI.ArcGIS.Geometry.IZAware ZAware = (ESRI.ArcGIS.Geometry.IZAware)envelope; ZAware.ZAware = (true); envelope.Union(pEv); IFeatureLayer pFlyr = null; for (int i = 0; i < scene.LayerCount; ++i) { if (scene.get_Layer(i).Name == name) { pFlyr = scene.get_Layer(i) as IFeatureLayer; break; } } ESRI.ArcGIS.Geodatabase.IGeoDataset geoDataset = (ESRI.ArcGIS.Geodatabase.IGeoDataset)pFlyr; if (geoDataset != null) { ESRI.ArcGIS.Geometry.IEnvelope layerExtent = geoDataset.Extent; layersExtentEnvelope.Union(layerExtent); } System.Double width = envelope.Width; System.Double height = envelope.Height; if (width == 0.0 && height == 0.0) { System.Double dim = 1.0; System.Boolean bEmpty = layersExtentEnvelope.IsEmpty; if (!bEmpty) { System.Double layerWidth = layersExtentEnvelope.Width; System.Double layerHeight = layersExtentEnvelope.Height; System.Double layerDim = System.Math.Max(layerWidth, layerHeight) * 0.05; if (layerDim > 0.0) { dim = System.Math.Min(1.0, layerDim); } } System.Double xMin = envelope.XMin; System.Double yMin = envelope.YMin; ESRI.ArcGIS.Geometry.IPoint point = new ESRI.ArcGIS.Geometry.PointClass(); point.X = xMin; point.Y = yMin; envelope.Width = dim * 0.8; envelope.Height = dim * 0.8; envelope.CenterAt(point); } else if (width == 0.0 || height == 0.0) { System.Double maxDim = System.Math.Max(width, height); envelope.Width = maxDim; envelope.Height = maxDim; } globeCamera.SetToZoomToExtents(envelope, globe, sceneViewer); sceneViewer.Redraw(true); }
protected override void OnClick() { // Get the min/max zoom from user input int minzoom = 0; int maxzoom = 6; Ecotrust.Form1 form1 = new Ecotrust.Form1(); if (form1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { minzoom = (int)form1.numericUpDown1.Value; maxzoom = (int)form1.numericUpDown2.Value; } else { return; //TODO } // Use the FolderBrowserDialog Class to choose export folder System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog(); folderDialog.Description = "Select output folder for map tiles..."; string exportDir = ""; if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // The returned string will be the full path, filename and file-extension for the chosen shapefile. Example: "C:\test\cities.shp" exportDir = folderDialog.SelectedPath; if (exportDir == "") { return; // TODO raise error } } else { return; //TODO } ESRI.ArcGIS.ArcMapUI.IMxDocument mxDocument = ArcMap.Application.Document as ESRI.ArcGIS.ArcMapUI.IMxDocument; // Dynamic Cast ESRI.ArcGIS.Carto.IActiveView activeView = mxDocument.ActiveView; ESRI.ArcGIS.Carto.IMap map = activeView.FocusMap; ESRI.ArcGIS.Geometry.IEnvelope mapaoi = activeView.Extent; // Set up export object and tile pixel coordinates int tileSizeX = 256; int tileSizeY = 256; // set up exporter with transparent background ESRI.ArcGIS.Output.IExportPNG pngexport = new ESRI.ArcGIS.Output.ExportPNGClass(); ESRI.ArcGIS.Display.IColor tcolor = new ESRI.ArcGIS.Display.RgbColorClass(); // Warning: 254,254,254 will be set to transparent; don't use in any of map styling ((IRgbColor)tcolor).Red = 254; ((IRgbColor)tcolor).Green = 254; ((IRgbColor)tcolor).Blue = 254; ((ExportPNG)pngexport).BackgroundColor = tcolor; pngexport.TransparentColor = tcolor; ESRI.ArcGIS.Output.IExport export = (ESRI.ArcGIS.Output.IExport)pngexport; ESRI.ArcGIS.esriSystem.tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = tileSizeX; exportRECT.bottom = tileSizeY; ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; map.DelayDrawing(true); // Turn off all layers for (int i = 0; i < map.LayerCount; i++) { map.get_Layer(i).Visible = false; } // Calculate total number of tiles needed GlobalMercator mercator = new GlobalMercator(); GlobalMercator.Coords tempmins; GlobalMercator.Coords tempmaxs; Double numTiles = 0; for (int tz = minzoom; tz <= maxzoom; tz++) { tempmins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz); tempmaxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz); numTiles += ((tempmaxs.y - tempmins.y) + 1) * ((tempmaxs.x - tempmins.x) + 1); } numTiles *= map.LayerCount; ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar; statusBar.set_Message(0, "Rendering " + numTiles.ToString() + " tiles"); // Create a CancelTracker ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass(); ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass(); // Set the properties of the Step Progressor System.Int32 int32_hWnd = ArcMap.Application.hWnd; ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd); stepProgressor.MinRange = 0; stepProgressor.MaxRange = (int)numTiles; stepProgressor.StepValue = 1; stepProgressor.Message = "Calculating " + numTiles.ToString() + " tiles"; // Create the ProgressDialog. This automatically displays the dialog ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast // Set the properties of the ProgressDialog progressDialog2.CancelEnabled = true; progressDialog2.Description = "Rendering " + numTiles.ToString() + " map tiles"; progressDialog2.Title = "Creating map tiles..."; progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriDownloadFile; System.Boolean boolean_Continue = true; int tileCount = 0; for (int lyrnum = 0; lyrnum < map.LayerCount; lyrnum++) { // Turn on the layer of interest ESRI.ArcGIS.Carto.ILayer layer = map.get_Layer(lyrnum); layer.Visible = true; // Set extents //ESRI.ArcGIS.Geometry.IEnvelope layeraoi = layer.AreaOfInterest; ESRI.ArcGIS.Geometry.IEnvelope aoi = new ESRI.ArcGIS.Geometry.EnvelopeClass(); // Create layer directory if it doesn't exist DirectoryInfo dir = new DirectoryInfo(exportDir + "\\" + layer.Name); if (!dir.Exists) { dir.Create(); } DateTime startTime = DateTime.Now; // Loop through zoom levels, rows, cols for (int tz = minzoom; tz <= maxzoom; tz++) { GlobalMercator.Coords mins = mercator.MetersToTile(mapaoi.XMin, mapaoi.YMin, tz); GlobalMercator.Coords maxs = mercator.MetersToTile(mapaoi.XMax, mapaoi.YMax, tz); // Create zoom directory if it doesn't exist DirectoryInfo dir2 = new DirectoryInfo(dir.FullName + "\\" + tz); if (!dir2.Exists) { dir2.Create(); } for (int tx = (int)mins.x; tx <= (int)maxs.x; tx++) { // Create X directory if it doesn't exist DirectoryInfo dir3 = new DirectoryInfo(dir2.FullName + "\\" + tx); if (!dir3.Exists) { dir3.Create(); } for (int ty = (int)mins.y; ty <= (int)maxs.y; ty++) { // Flip y-axis for output tile name int invertTy = (int)((Math.Pow(2, tz) - 1) - ty); tileCount += 1; // TODO Calculate time and set new message // TimeSpan timeElapsed = TimeSpan.FromTicks(DateTime.Now.Subtract(startTime).Ticks); // * ((double)tileCount - (numTiles + 1)) / (numTiles + 1)); // double timeRemaining = (timeElapsed.TotalSeconds / (tileCount / numTiles)) - timeElapsed.TotalSeconds; //(" + ((int)timeRemaining).ToString() +" remaining)"; stepProgressor.Message = layer.Name + "\\" + tz + "\\" + tx + "\\" + invertTy + ".png (" + tileCount + " of " + numTiles + ")"; export.ExportFileName = dir3.FullName + "\\" + invertTy + ".png"; GlobalMercator.Bounds bnd = mercator.TileBounds(tx, ty, tz); aoi.PutCoords(bnd.minx, bnd.miny, bnd.maxx, bnd.maxy); aoi.SpatialReference = map.SpatialReference; // TODO aoi spatial reference == mercator? // Use FullExtent instead of Extent to make the extent independent of the activeView ratio activeView.FullExtent = aoi; // Export System.Int32 hDC = export.StartExporting(); activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed export.FinishExporting(); export.Cleanup(); stepProgressor.Position = tileCount; //Check if the cancel button was pressed. If so, break out of row boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } } //Check if the cancel button was pressed. If so, break out of col boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } } //Check if the cancel button was pressed. If so, break out of layers boolean_Continue = trackCancel.Continue(); if (!boolean_Continue) { break; } // Write log using (System.IO.StreamWriter file = new System.IO.StreamWriter(exportDir + "\\log.txt", true)) { file.WriteLine(layer.Name + ", zoom " + tz + ", numtiles " + tileCount + ":" + mins.x + " " + mins.y + " " + maxs.x + " " + maxs.y); } } // Turn it off layer.Visible = false; } map.DelayDrawing(false); // Turn ON all layers for (int i = 0; i < map.LayerCount; i++) { map.get_Layer(i).Visible = true; } // restore extent activeView.FullExtent = mapaoi; activeView.Refresh(); // Done trackCancel = null; stepProgressor = null; progressDialog2.HideDialog(); progressDialog2 = null; }
private void OnActiveViewEventsViewRefreshed(ESRI.ArcGIS.Carto.IActiveView view, ESRI.ArcGIS.Carto.esriViewDrawPhase phase, System.Object data, ESRI.ArcGIS.Geometry.IEnvelope envelope) { if (!_iscloned) { return; } if (!_isthisadmin) { return; } try { //first check if the map extent has changed if (ExtentHasChanged()) { //this flag is to avoid an infinite loop; any change to the map will cause this 'view refresh' //event to be fired again if (_firstRefresh) { _firstRefresh = false; using (StreamWriter sw = new StreamWriter(_extentfile)) { sw.WriteLine(_currentExtent.XMin.ToString()); sw.WriteLine(_currentExtent.XMax.ToString()); sw.WriteLine(_currentExtent.YMin.ToString()); sw.WriteLine(_currentExtent.YMax.ToString()); sw.WriteLine(Math.Round(_map.MapScale).ToString()); } } } } catch (Exception ex) { string message = ex.Message; } }
private void OnActiveViewEventsViewRefreshed(ESRI.ArcGIS.Carto.IActiveView view, ESRI.ArcGIS.Carto.esriViewDrawPhase phase, System.Object data, ESRI.ArcGIS.Geometry.IEnvelope envelope) { IPoint point = new Point(); IPoint lowerLeftPoint = new Point(); IPoint upperRightPoint = new Point(); double latXmin, latXmax, longYmin, longYmax, diagonal; lowerLeftPoint.X = view.Extent.XMin; lowerLeftPoint.Y = view.Extent.YMin; upperRightPoint.X = view.Extent.XMax; upperRightPoint.Y = view.Extent.YMax; PointToLatLong(lowerLeftPoint, out latXmin, out longYmin); PointToLatLong(upperRightPoint, out latXmax, out longYmax); diagonal = Distance(latXmin, longYmin, latXmax, longYmax, 'K') * 1000; // "1KM * 1000 diagonal = Math.Round(diagonal, 2); _altitude = Convert.ToString(0.5 * Math.Sqrt(3) * diagonal, CultureInfo.InvariantCulture); point.X = (view.Extent.XMax + view.Extent.XMin) / 2; point.Y = (view.Extent.YMax + view.Extent.YMin) / 2; Double lat; Double lon; PointToLatLong(point, out lat, out lon); lat = Math.Round(lat, 5); lon = Math.Round(lon, 5); _latitude = Convert.ToString(lat, CultureInfo.InvariantCulture); _longitude = Convert.ToString(lon, CultureInfo.InvariantCulture); CreateTrackingKML(); }