Exemplo n.º 1
0
        private void CalculateVisibleExtents( Extent e, bool LogPrev,bool OnResize)
        {
            if(_Map == null) return;

            if( LogPrev == true )
            {
                LogPrevExtent();
            }

            //�жϵ�ǰ����ķ�Χ�Ƿ���ڵ�ͼ�Ŀɼ���Χ
            //������ڿɼ���Χ���������ɼ���Χ��С

            e.Left = e.Left < m_MapMinx ? m_MapMinx : e.Left;
            e.Right = e.Right > m_MapMaxx ? m_MapMaxx : e.Right;
            e.Bottom = e.Bottom < m_MapMiny ? m_MapMiny : e.Bottom;
            e.Top = e.Top > m_MapMaxy ? m_MapMaxy : e.Top;

            //�жϴ���ķ�Χ�뵱ǰ����ʾ����Χ�����Ƿ�һ��
            //�����һ�£��޸ķ�Χ

            double viewWidth = m_viewWidth;
            double viewHeight = m_viewHeight;

            double geoxMin = e.Left>=e.Right?e.Right:e.Left;
            double geoxMax = e.Left >= e.Right ? e.Left : e.Right;
            double geoyMin = e.Bottom >= e.Top ? e.Top : e.Bottom;
            double geoyMax = e.Bottom >= e.Top ? e.Bottom : e.Top;

            double geoWidth = Math.Abs(geoxMax -  geoxMin);
            double geoHeight = Math.Abs(geoyMax - geoyMin);

            if((viewWidth <=0)||(viewHeight <= 0)||(geoWidth <=0)||(geoHeight<=0))
            {
                m_Curextents = new Extent();
                return;
            }

            double xAdjust = 0;
            double yAdjust = 0;

            if((viewWidth/viewHeight)>(geoWidth/geoHeight))
            {
                xAdjust = ((viewWidth/viewHeight)*geoHeight - geoWidth)/2;
            }
            else
            {
                yAdjust = (geoWidth*viewHeight/viewWidth - geoHeight)/2;
            }

            //drawmap��ʱ���ı�extent�ķ�Χ��
            //��Ҫ�����ﻹԭ
            _Map.extent.maxx = geoxMax + xAdjust;
            _Map.extent.minx = geoxMin - xAdjust;
            _Map.extent.miny = geoyMin - yAdjust;
            _Map.extent.maxy = geoyMax + yAdjust;

            if (OnExtentChanged != null)
                OnExtentChanged(null, null);

            //m_Curextents.left = geoxMin - xAdjust;
            //m_Curextents.right = geoxMax + xAdjust;
            //m_Curextents.top = geoyMin - yAdjust;
            //m_Curextents.bottom = geoyMax +  yAdjust;
        }
Exemplo n.º 2
0
 public void zoomToExtents(double xMin, double xMax, double yMin, double yMax)
 {
     Extent inExtent = new Extent(xMin,xMax,yMin,yMax);
     CalculateVisibleExtents(inExtent,true,true);
     refreshMap(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// refresh the map,can reread the origin mapfile
        /// </summary>
        /// <param name="reload"></param>
        public void refreshMap(bool reload)
        {
            if (_Map == null)
            {
                if (this.BackgroundImage != null)
                    this.BackgroundImage = null;
                return;
            }

            if (reload)
            {
                if (_Map != null)
                    _Map.Dispose();

                try
                {

                    //_TempMapfilePath = CreateTempMapfile(_MapfilePath);

                    _Map = new mapObj(_TempMapfilePath);
                    _Map.setSize(m_viewWidth, m_viewHeight);
                    _Map.extent.minx = m_Curextents.Left;
                    _Map.extent.maxx = m_Curextents.Right;
                    _Map.extent.miny = m_Curextents.Bottom;
                    _Map.extent.maxy = m_Curextents.Top;

                    drawImg2Mapcontrol();

                    //fire the mapreplaced event
                    if (this.OnMapReplaced != null)
                        OnMapReplaced(null, new EventArgs());
                }
                catch (Exception ex)
                {
                    if (ErrorOccured != null)
                        ErrorOccured(null, new MSErrorEventArgs(ex.Message));
                    closeMapfile();
                }
            }
            else
            {
                try
                {
                    _Map.setSize(m_viewWidth, m_viewHeight);

                    drawImg2Mapcontrol();

                    calculateNewScale();

                    m_Curextents = new Extent(_Map.extent.minx, _Map.extent.maxx, _Map.extent.miny, _Map.extent.maxy);

                    {
                        double geoWidth = Math.Abs(m_Curextents.Right - m_Curextents.Left);
                        double geoHeight = Math.Abs(m_Curextents.Top - m_Curextents.Bottom);

                        if (geoWidth == 0)
                        {
                            m_pixelPerProjectionX = 0;
                            m_inversePixelPerProjectionX = 0;
                        }
                        else
                        {
                            m_pixelPerProjectionX = m_viewWidth / geoWidth;
                            m_inversePixelPerProjectionX = 1.0 / m_pixelPerProjectionX;
                        }

                        if (geoHeight == 0)
                        {
                            m_pixelPerProjectionY = 0;
                            m_inversePixelPerProjectionY = 0;
                        }
                        else
                        {
                            m_pixelPerProjectionY = m_viewHeight / geoHeight;
                            m_inversePixelPerProjectionY = 1.0 / m_pixelPerProjectionY;
                        }
                    }

                    ChecktLayerState();
                }
                catch(Exception ex)
                {
                    MessageBox.Show("Error:" + ex.Message,"��ʾ");
                }

            }
        }
Exemplo n.º 4
0
        public void zoomOut()
        {
            double halfW = Math.Abs(m_Curextents.Right - m_Curextents.Left) / 4;
            double halfH = Math.Abs(m_Curextents.Top - m_Curextents.Bottom) / 4;

            Extent zoomGeoExt = new Extent(m_Curextents.Left - halfW, m_Curextents.Right + halfW,
                m_Curextents.Bottom - halfH, m_Curextents.Top + halfH);
            CalculateVisibleExtents(zoomGeoExt, true, true);
            refreshMap(false);
        }
Exemplo n.º 5
0
        private Extent pixcelToGeo(Rectangle pixExtent)
        {
            //���¼���ɼ���Χ
            //���ݴ����extent�����������extent�Ĵ�С��ʹ�����ʵ����Χ��Сһ��
            //��������ĵ�
            double pCenterX = (pixExtent.Right + pixExtent.Left)/2;
            double pCenterY = (pixExtent.Top + pixExtent.Bottom)/2;

            //����������곤��
            double geoWidth = Math.Abs(m_Curextents.Right - m_Curextents.Left);
            double geoHeight = Math.Abs(m_Curextents.Top - m_Curextents.Bottom);

            double viewWidth = m_viewWidth;
            double viewHeight = m_viewHeight;

            Extent newExt = new Extent();

            if((viewWidth <=0)||(viewHeight <= 0)||(geoWidth <=0)||(geoHeight<=0))
                return newExt;

            newExt.Left = m_Curextents.Left + (pixExtent.Left / viewWidth) * geoWidth;
            newExt.Right = m_Curextents.Left + (pixExtent.Right / viewWidth) * geoWidth;
            newExt.Bottom = m_Curextents.Bottom + (1 - pixExtent.Bottom / viewHeight) * geoHeight;
            newExt.Top = m_Curextents.Bottom + (1 - pixExtent.Top / viewHeight) * geoHeight;

            return newExt;
        }