예제 #1
0
        public static IEnvelope SetBoundsWithXYRatio(IEnvelope bounds, SizeF ratio)
        {
            if (NumericHelper.Equal(ratio.Width, 0.0) || NumericHelper.Equal(ratio.Height, 0.0))
            {
                return(bounds.Clone());
            }

            double height = bounds.Height;
            double width  = bounds.Width;

            if (ratio.Height / ratio.Width > height / width)
            {
                height = ratio.Height * width / ratio.Width;
            }
            else
            {
                width = ratio.Width * height / ratio.Height;
            }

            var result = new Envelope();

            result.SetBounds(bounds.Center, width, height);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Zooms to the extents of all layers
        /// Adds an extra 10 % marge to each border
        /// </summary>
        public virtual void ZoomToExtents()
        {
            IEnvelope boundingBox = GetExtents();

            if (null == boundingBox)
            {
                return;
            }
            boundingBox = (IEnvelope)boundingBox.Clone();
            // beware of true 1d networks
            if ((boundingBox.Width < 1.0e-6) && (boundingBox.Height < 1.0e-6))
            {
                return;
            }
            double minX = 0.0;
            double minY = 0.0;

            if (boundingBox.Width < 1.0e-6)
            {
                minX = 1.0;
            }
            if (boundingBox.Height < 1.0e-6)
            {
                minY = 1.0;
            }
            boundingBox.ExpandBy(minX + boundingBox.Width / 10, minY + boundingBox.Height / 10);
            ZoomToBox(boundingBox);
        }
예제 #3
0
        public static IEnvelope CloneProject(this IEnvelope envelope, ISpatialReference spatialReference)
        {
            IEnvelope clone = envelope.Clone();

            clone.Project(spatialReference);
            return(clone);
        }
예제 #4
0
 public void ZooomToOriginalExtents()
 {
     if (_extentsOriginal != null)
     {
         Envelope = _extentsOriginal.Clone();
     }
 }
예제 #5
0
        /// <summary>
        /// Adds map element to the new layout.
        /// </summary>
        /// <param name="mapScale">The map scale.</param>
        /// <param name="extents">The extents.</param>
        private void AddMapElement(int mapScale, IEnvelope extents)
        {
            var map = _context.Map;

            var mapElement = new LayoutMap();

            mapElement.Initialize(map, View.LayoutControl);
            mapElement.IsMain       = true;
            mapElement.TileProvider = _context.Map.TileProvider;

            mapElement.LocationF = new PointF(PrintingConstants.DefaultMapOffset, PrintingConstants.DefaultMapOffset);
            mapElement.DrawTiles = map.Tiles.Visible;

            // calc the necessary size in paper coordinates
            GeoSize size;

            if (map.GetGeodesicSize(extents, out size))
            {
                mapElement.SizeF = LayoutScaleHelper.CalcMapSize(mapScale, size, extents.Width / extents.Height);

                mapElement.Envelope    = extents.Clone();
                mapElement.Initialized = true;

                View.LayoutControl.AddToLayout(mapElement);

                View.LayoutControl.UpdateLayout();

                View.LayoutControl.ZoomFitToScreen();
            }
        }
예제 #6
0
        private void SetNewExtents(IEnvelope box)
        {
            _extents = box;

            if (_extentsOriginal == null && box != null)
            {
                _extentsOriginal = box.Clone();
            }
        }
예제 #7
0
        private void CoordinateItem_TextChanged(object sender, EventArgs e)
        {
            if (BoundsOverride.Tag as TreeNode == null || m_isUpdating)
            {
                return;
            }

            TreeNode root = BoundsOverride.Tag as TreeNode;

            if (!m_coordinateOverrides.ContainsKey(root.Text))
            {
                //IEnvelope newbox = new OSGeo.MapGuide.IEnvelope();
                IMapDefinition     mdf     = root.Tag as IMapDefinition;
                ITileSetDefinition tdf     = root.Tag as ITileSetDefinition;
                IEnvelope          origbox = null;
                if (mdf != null)
                {
                    origbox = mdf.Extents;
                }
                else if (tdf != null)
                {
                    origbox = tdf.Extents;
                }
                IEnvelope newbox = origbox.Clone();
                m_coordinateOverrides.Add(root.Text, newbox);
            }

            double d;

            if (double.TryParse(txtLowerX.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentUICulture, out d))
            {
                m_coordinateOverrides[root.Text].MinX = d;
            }
            if (double.TryParse(txtLowerY.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentUICulture, out d))
            {
                m_coordinateOverrides[root.Text].MinY = d;
            }
            if (double.TryParse(txtUpperX.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentUICulture, out d))
            {
                m_coordinateOverrides[root.Text].MaxX = d;
            }
            if (double.TryParse(txtUpperY.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.CurrentUICulture, out d))
            {
                m_coordinateOverrides[root.Text].MaxY = d;
            }
        }
예제 #8
0
파일: Map.cs 프로젝트: Sony-NS/SharpMap
        /// <summary>
        /// Zooms to the extents of all layers
        /// Adds an extra 10 % marge to each border
        /// </summary>
        public virtual void ZoomToExtents()
        {
            IEnvelope boundingBox = GetExtents();

            if (null == boundingBox)
            {
                return;
            }
            boundingBox = (IEnvelope)boundingBox.Clone();
            // beware of true 1d networks
            if ((boundingBox.Width < 1.0e-6) && (boundingBox.Height < 1.0e-6))
            {
                return;
            }

            AddMargin(boundingBox, defaultExtendsMarginPercentage);
            ZoomToFit(boundingBox);
        }
예제 #9
0
        /// <summary>
        /// Actual rendering of map
        /// </summary>
        private bool RenderMap(IEnvelope extent, Size bitmapSize, Graphics g)
        {
            if (bitmapSize.Width < 1 | bitmapSize.Height < 1)
            {
                return(false);
            }

            _map.Lock();

            // save settings
            bool state = _map.ScalebarVisible;

            _map.ScalebarVisible = false;

            float dx   = g.Transform.OffsetX;
            float dy   = g.Transform.OffsetY;
            var   clip = g.ClipBounds;

            // rendering
            g.Clear(Color.White);
            var dcPtr = g.GetHdc();

            bool result;

            // several map elements may set different tile providers,
            // mutually exclusive excess is needed to avoid interference
            lock (_layoutControl.TileLoader.Lock)
            {
                PrepareTiles();

                result = _map.SnapShotToDC2(dcPtr, extent.Clone(), bitmapSize.Width, dx, dy, clip.X, clip.Y, clip.Width, clip.Height);

                RestoreTiles();
            }

            g.ReleaseHdc(dcPtr);

            // restore settings
            _map.ScalebarVisible = state;

            _map.Unlock();

            return(result);
        }
예제 #10
0
        /// <summary>
        /// Zooms the map to fit a bounding box.
        /// </summary>
        /// <remarks>
        /// NOTE: If the aspect ratio of the box and the aspect ratio of the mapsize
        /// isn't the same, the resulting map-envelope will be adjusted so that it contains
        /// the bounding box, thus making the resulting envelope larger!
        /// </remarks>
        /// <param name="bbox"></param>
        /// <param name="addMargin">Add a default margin?</param>
        public virtual void ZoomToFit(IEnvelope bbox, bool addMargin)
        {
            if (bbox == null || bbox.Width == 0 || bbox.Height == 0)
            {
                return;
            }
            //create a copy so we don't mess up any given envelope...
            bbox = (IEnvelope)bbox.Clone();

            if (addMargin)
            {
                AddMargin(bbox, defaultExtendsMarginPercentage);
            }

            desiredEnvelope = bbox;

            zoom = bbox.Width; //Set the private center value so we only fire one MapOnViewChange event
            //if the map height is smaller than the given bbox height scale to the height
            if (Envelope.Height < bbox.Height)
            {
                zoom *= bbox.Height / MapHeight;
                //zoom *= bbox.Height / Envelope.Height; --> Significance decrease for large center coordinates (TOOLS-7678)
            }

            center = bbox.Centre;

            UpdateDimensions();

            if (GetExtents() == null || GetExtents().IsNull)
            {
                desiredEnvelope = Envelope;
            }


            if (MapViewOnChange != null)
            {
                MapViewOnChange();
            }
            SetRenderRequiredForAllLayers();
        }