private void GotoByPrj(PointF pt) { double cx = (_viewport.MinX + _viewport.MaxX) / 2; double cy = (_viewport.MinY + _viewport.MaxY) / 2; double offsetX = pt.x - cx; double offsetY = pt.y - cy; _viewport.Offset(offsetX, offsetY); RefreshMap(); }
private void ComputePrjTransfrom() { PrjRectangleF newViewport = _viewport; //如果_offsetX与_offsetY不为0,则表示地图正在漫游 newViewport.Offset(-_offsetX, _offsetY); if (_onMapControlViewportChanged != null) { _onMapControlViewportChanged(this, _viewport, newViewport); } TranslateTransform translateMatrix = null; ScaleTransform scaleMatrix = null; if (_prj2PixelTransform == null) { TransformGroup tran = new TransformGroup(); translateMatrix = new TranslateTransform(); scaleMatrix = new ScaleTransform(); ScaleTransform negMatrix = new ScaleTransform(); negMatrix.ScaleX = 1; negMatrix.ScaleY = -1; tran.Children.Add(negMatrix); tran.Children.Add(translateMatrix); tran.Children.Add(scaleMatrix); // translateMatrix.X = -newViewport.MinX; //left translateMatrix.Y = newViewport.MaxY; //top scaleMatrix.ScaleX = 1d / _resolutionX; scaleMatrix.ScaleY = 1d / _resolutionY; // _prj2PixelTransform = tran; } else { translateMatrix = (_prj2PixelTransform as TransformGroup).Children[1] as TranslateTransform; scaleMatrix = (_prj2PixelTransform as TransformGroup).Children[2] as ScaleTransform; // translateMatrix.X = -newViewport.MinX; translateMatrix.Y = newViewport.MaxY; scaleMatrix.ScaleX = 1d / _resolutionX; scaleMatrix.ScaleY = 1d / _resolutionY; } _pixel2PrjTransform = _prj2PixelTransform.Inverse as Transform; }