Ejemplo n.º 1
0
        public override void MouseClick(object sender, MouseEventArgs e)
        {
            if (map.InsertionLayer == null) return;

            CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys;

            CoordConverter oCC = new CoordConverter();
            oCC.Init(layerCoordsys, map.DisplayCoordSys);

            // this atPan converts DisplayCoordSys into Screen CoordSys[px]
            // DisplayCoordSys has Y axis up (unless its AT does not change it)
            // Screen Y axis is down
            AffineTransform atPan = new AffineTransform();
            atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY);
            atPan.MultiplyInPlace(map.MapScale, -map.MapScale);

            // add screen scale and offset transformation
            oCC.atMaster = oCC.atMaster.Compose(atPan);

            oCC.ConvertInverse(e.X, e.Y);

            DPoint pt = new DPoint(oCC.X, oCC.Y);
            // szukaj w tym miejscu feature
            List<Feature> ftrs = map.InsertionLayer.Search(pt);

            if (ftrs.Count == 0)
            {
                Feature oF = FeatureFactory.CreateSymbol(oCC.X, oCC.Y);
                map.InsertionLayer.FeaturesAdd(oF);
            }

            MapControl.Globals.Instance.MapControl.InvalidateMap();
        }
Ejemplo n.º 2
0
 public AffineTransform Compose(AffineTransform at)
 {
     if (at == null) throw new ArgumentNullException("at must not be null.");
     AffineTransform res = new AffineTransform();
     res.a = at.a * a + at.b * d;
     res.b = at.a * b + at.b * e;
     res.c = at.a * c + at.b * f + at.c;
     res.d = at.d * a + at.e * d;
     res.e = at.d * b + at.e * e;
     res.f = at.d * c + at.e * f + at.f;
     return res;
 }
Ejemplo n.º 3
0
 public static CoordSys CreateCoordSys(
     CoordSysType type,
     Datum datum,
     /*double originLongitude,
     double originLatitude,
     double standardParallelOne,
     double standardParallelTwo,
     double azimuth,
     double scaleFactor,
     double falseEasting,
     double falseNorthing,
     double range,*/
     AffineTransform affineTransform)
 {
     CoordSys oCS = new CoordSys(type, datum, affineTransform);
     return oCS;
 }
Ejemplo n.º 4
0
        public static CoordSys CreateCoordSys(string name)
        {
            if (name == "Mercator Datum(WGS84)")
            {
                AffineTransform at = new AffineTransform();

                // uklad wsp:
                // at zamiania wgs84 na px (256x256) i dalej na [m]
            //                at.MultiplyInPlace(256.0 / 360.0, -256.0 / 180.0);
            //                at.OffsetInPlace(-128, 128);
            //                at.MultiplyInPlace(Math.PI * r / 180, Math.PI * r / 180.0);

                CoordSys oCS = new CoordSys(CoordSysType.Mercator, new Datum(DatumID.WGS84), at);
                return oCS;
            }
            else
                throw new Exception("Unsupported coordsys");
        }
Ejemplo n.º 5
0
        public override void MouseMove(object sender, MouseEventArgs e)
        {
            base.MouseMove(sender, e);

            // highlight polilines and points

            if (map.InsertionLayer == null) return;

            CoordSys layerCoordsys = map.InsertionLayer.LayerCoordSys;

            CoordConverter oCC = new CoordConverter();
            oCC.Init(layerCoordsys, map.DisplayCoordSys);

            // this atPan converts DisplayCoordSys into Screen CoordSys[px]
            // DisplayCoordSys has Y axis up (unless its AT does not change it)
            // Screen Y axis is down
            AffineTransform atPan = new AffineTransform();
            atPan.OffsetInPlace((double)map.MapOffsetX, (double)map.MapOffsetY);
            atPan.MultiplyInPlace(map.MapScale, -map.MapScale);

            // add screen scale and offset transformation
            oCC.atMaster = oCC.atMaster.Compose(atPan);

            int margin = 5;

            oCC.ConvertInverse(e.X, e.Y);
            DPoint pt_center = new DPoint(oCC.X, oCC.Y);
            oCC.ConvertInverse(e.X - margin, e.Y - margin);
            DPoint pt1 = new DPoint(oCC.X, oCC.Y);
            oCC.ConvertInverse(e.X + margin, e.Y + margin);
            DPoint pt2 = new DPoint(oCC.X, oCC.Y);
            // szukaj w tym miejscu feature
            //List<Feature> ftrs = map.InsertionLayer.Search(pt);

            // construct search rectangle (10px wide)
            DRect rect = new DRect(pt1.X, pt2.Y, pt2.X, pt1.Y);

            //map.InsertionLayer.SelectWithinRectangle(rect);
        }
Ejemplo n.º 6
0
        private double zoomElevateUpscale = 1024 * 8; //1024;

        #endregion Fields

        #region Constructors

        public LayerTiles()
        {
            Datum datumWGS84Sphere = CoordSysFactory.CreateDatum(Ellipsoid.Sphere, 0, 0, 0, 0, 0, 0, 0, 0);

            double r = datumWGS84Sphere.SemiMajorAxis;

            // scale =256/360, offset=128, this is calculated for zoom=0 (one tile)
            // converts merc deg (-180;180 , -90;90) into pixels (0;256 , 0;256)
            AffineTransform affineTransform = new AffineTransform();
            //zoomElevate = 1024; // zwieksz gestosc wspolrzednych o 10 pozomow zoom
            //            affineTransform.MultiplyInPlace(256.0 / 360.0 * zoomElevateUpscale, -256.0 / 360.0 * zoomElevateUpscale);
            //            affineTransform.OffsetInPlace(-128, 128);

            affineTransform.MultiplyInPlace(256.0 / (2.0 * Math.PI * r) * zoomElevateUpscale, -256.0 / (2.0 * Math.PI * r) * zoomElevateUpscale);
            affineTransform.OffsetInPlace(128 * zoomElevateUpscale, 128 * zoomElevateUpscale);

            layerCoordSys = new CoordSys(CoordSysType.Mercator, datumWGS84Sphere, affineTransform);

            // depending o tile zoom lever (1,2,3,...,17) there is different AT

            // tiles loader
            WindowsFormsImageProxy wimg = new WindowsFormsImageProxy();
            GMaps.Instance.ImageProxy = wimg;
        }
Ejemplo n.º 7
0
 internal AffineTransform Clone()
 {
     AffineTransform at = new AffineTransform();
     at.Set(a, b, c, d, e, f);
     return at;
 }
Ejemplo n.º 8
0
 public AffineTransform Inverse()
 {
     double det = Determinant();
     if (det == 0) return null;
     double invDeterminant = 1 / det;
     AffineTransform res = new AffineTransform();
     res.a = invDeterminant * e;
     res.b = -invDeterminant * b;
     res.c = -invDeterminant * (e * c - b * f);
     res.d = -invDeterminant * d;
     res.e = invDeterminant * a;
     res.f = invDeterminant * (d * c - a * f);
     return res;
 }
Ejemplo n.º 9
0
Archivo: Map.cs Proyecto: ravcio/MapNet
        void DrawLayer(LayerAbstract oL, Graphics g, Rectangle Rect)
        {
            CoordSys layerCoordsys = oL.LayerCoordSys;

            CoordConverter oCC = new CoordConverter();
            oCC.Init(layerCoordsys, DisplayCoordSys);

            // this atPan converts DisplayCoordSys into Screen CoordSys[px]
            // DisplayCoordSys has Y axis up (unless its AT does not change it)
            // Screen Y axis is down
            AffineTransform atPan = new AffineTransform();
            atPan.OffsetInPlace((double)mapOffsetX, (double)mapOffsetY);
            atPan.MultiplyInPlace(mapScale, -mapScale);

            // add screen scale and offset transformation
            oCC.atMaster = oCC.atMaster.Compose(atPan);

            oL.Draw(g, Rect, oCC);
        }
Ejemplo n.º 10
0
 internal CoordSys(CoordSysType type, Datum datum, AffineTransform affineTransform)
 {
     this.type = type;
     this.datum = datum;
     this.affineTransform = affineTransform;
 }
Ejemplo n.º 11
0
 internal DisplayTransform(AffineTransform affineTransform)
 {
     at = affineTransform;
 }
Ejemplo n.º 12
0
        private void tileDownloaderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // auto download tiles

            // calculate x,y, range
            // calculate zoom range

            CoordSys layerCoordsys = tileLayer.LayerCoordSys;

            CoordConverter oCC = new CoordConverter();
            oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys);

            // this atPan converts DisplayCoordSys into Screen CoordSys[px]
            // DisplayCoordSys has Y axis up (unless its AT does not change it)
            // Screen Y axis is down
            AffineTransform atPan = new AffineTransform();
            atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY);
            atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale);

            // add screen scale and offset transformation
            oCC.atMaster = oCC.atMaster.Compose(atPan);

            double zoomElevateUpscale = 1024 * 8; //1024;
            double scale = oCC.atMaster.A;

            int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2);

            TileDownloader downloader = new TileDownloader();
            downloader.Download(zoom, ((LayerTilesAsynch)tileLayer).MapType, oCC, new System.Drawing.Rectangle(0, 0, mapControl1.Width, mapControl1.Height));
        }
Ejemplo n.º 13
0
        private void mapControl1_MouseMove(object sender, MouseEventArgs e)
        {
            DPoint pt;
            mapControl1.Map.DisplayTransform.FromDisplay(new System.Drawing.Point(e.X, e.Y), out pt);

            // convert mercator to wgs84
            CoordConverter occ = new CoordConverter();
            CoordSys oCSMercator = CoordSysFactory.CreateCoordSys(CoordSysType.Mercator, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform());
            CoordSys oCSWGS84 = CoordSysFactory.CreateCoordSys(CoordSysType.LatLong, CoordSysFactory.CreateDatum(DatumID.WGS84), new AffineTransform());
            occ.Init(oCSMercator, oCSWGS84);
            occ.Convert(pt.X, pt.Y);

            // calculate zoom
            CoordSys layerCoordsys = tileLayer.LayerCoordSys;

            CoordConverter oCC = new CoordConverter();
            oCC.Init(layerCoordsys, mapControl1.Map.DisplayCoordSys);

            // this atPan converts DisplayCoordSys into Screen CoordSys[px]
            // DisplayCoordSys has Y axis up (unless its AT does not change it)
            // Screen Y axis is down
            AffineTransform atPan = new AffineTransform();
            atPan.OffsetInPlace((double)mapControl1.Map.MapOffsetX, (double)mapControl1.Map.MapOffsetY);
            atPan.MultiplyInPlace(mapControl1.Map.MapScale, -mapControl1.Map.MapScale);

            // add screen scale and offset transformation
            oCC.atMaster = oCC.atMaster.Compose(atPan);

            double zoomElevateUpscale = 1024 * 8; //1024;
            double scale = oCC.atMaster.A;

            int zoom = (int)Math.Log(scale * zoomElevateUpscale, 2);

            lblInfo.Text = string.Format("x={0:0.00000}, y={1:0.00000} Mercator: x={2:0}, y={3:0}, zoom={4}", occ.X, occ.Y, pt.X, pt.Y, zoom);
        }