Exemplo n.º 1
1
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (this.DesignMode)
                return;

            if (area.LocationMiddle.Lat == 0 && area.LocationMiddle.Lng == 0)
                return;
            
            try
            {
                base.OnPaint(e);

            }
            catch { return;  }

            double heightscale = (step / 90.0) * 3;

            float yawradians = (float)(Math.PI * (rpy.Z * 1) / 180.0f);

             //radians = 0;

            float mouseY = (float)(0.0025);

            cameraX = area.LocationMiddle.Lng;// -Math.Sin(yawradians) * mouseY;     // multiplying by mouseY makes the
            cameraY = area.LocationMiddle.Lat;// -Math.Cos(yawradians) * mouseY;    // camera get closer/farther away with mouseY
            cameraZ = (LocationCenter.Alt < srtm.getAltitude(center.Lat, center.Lng).alt) ? (srtm.getAltitude(center.Lat, center.Lng).alt + 1) * heightscale : LocationCenter.Alt * heightscale;// (srtm.getAltitude(lookZ, lookX, 20) + 100) * heighscale;

      lookX = area.LocationMiddle.Lng + Math.Sin(yawradians) * mouseY;
      lookY = area.LocationMiddle.Lat + Math.Cos(yawradians) * mouseY;
      lookZ = cameraZ;

     // cameraZ += 0.04;
            
            GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj = type.Projection;

          
            PointLatLngAlt leftf = center.newpos(rpy.Z ,500);
            PointLatLngAlt rightf = center.newpos(rpy.Z, 10);
            PointLatLngAlt left = center.newpos(rpy.Z - 90, 500);
            PointLatLngAlt right = center.newpos(rpy.Z + 90, 500);

            double maxlat = Math.Max(left.Lat,Math.Max(right.Lat,Math.Max(leftf.Lat,rightf.Lat)));
            double minlat = Math.Min(left.Lat, Math.Min(right.Lat, Math.Min(leftf.Lat, rightf.Lat)));

            double maxlng = Math.Max(left.Lng, Math.Max(right.Lng, Math.Max(leftf.Lng, rightf.Lng)));
            double minlng = Math.Min(left.Lng, Math.Min(right.Lng, Math.Min(leftf.Lng, rightf.Lng)));

            area = RectLatLng.FromLTRB(minlng, maxlat, maxlng, minlat);

            GPoint topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
            GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
            GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            zoom = 17;

            // zoom based on pixel density
            while (pxDelta.X > 2000)
            {
                zoom--;

                // current area
                topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            }

            // update once per seconds - we only read from disk, so need to let cahce settle
            if (lastrefresh.AddSeconds(.6) < DateTime.Now)
            {
                // get tiles - bg
                core.Provider = type;
                core.Position = LocationCenter;
                core.Zoom = zoom;
                core.OnMapSizeChanged(this.Width, this.Height);

                lastrefresh = DateTime.Now;
            }
            else
            {
                //return;
            }

            MakeCurrent();


            GL.MatrixMode(MatrixMode.Projection);

            OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(130 * deg2rad, 1f, 0.00001f, (float)step * 100);
            GL.LoadMatrix(ref projection);

            Matrix4 modelview = Matrix4.LookAt((float)cameraX, (float)cameraY, (float)cameraZ, (float)lookX, (float)lookY, (float)lookZ, 0, 0, 1);
            GL.MatrixMode(MatrixMode.Modelview);

            // roll
            modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationZ(rpy.X * deg2rad));
            // pitch
            modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationX((rpy.Y - 10) * -deg2rad));

            GL.LoadMatrix(ref modelview);

            GL.ClearColor(Color.LightBlue);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 1f, 1f, 1f, 1f });

            GL.Enable(EnableCap.Fog);
            // GL.Enable(EnableCap.Lighting);
            // GL.Enable(EnableCap.Light0);

            GL.Fog(FogParameter.FogColor, new float[] { 0.5f, 0.5f, 0.5f, 1f });
            //GL.Fog(FogParameter.FogDensity,0.1f);
            GL.Fog(FogParameter.FogMode, (int)FogMode.Linear);
            GL.Fog(FogParameter.FogStart, (float)step * 1);
            GL.Fog(FogParameter.FogEnd, (float)(step * 7));

            /*
            GL.Begin(BeginMode.LineStrip);

            GL.Color3(Color.White);
            GL.Vertex3(0, 0, 0);

            GL.Vertex3(area.Bottom, 0, area.Left);

            GL.Vertex3(lookX, lookY, lookZ);

            //GL.Vertex3(cameraX, cameraY, cameraZ);

            GL.End();
            */

            GL.Begin(PrimitiveType.LineStrip);
            GL.PointSize(200);
            GL.Color3(Color.Red);
            //GL.Vertex3(new Vector3((float)center.Lng,(float)center.Lat,(float)(center.Alt * heightscale)));
            //GL.Vertex3(new Vector3(0, 0, 0));
            //GL.Vertex3(new Vector3((float)cameraX, (float)cameraY, (float)cameraZ));
            //GL.Color3(Color.Green);
            //GL.Vertex3(new Vector3((float)lookX, (float)lookY, (float)lookZ));

            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, 0);
            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationRightBottom.Lat, 0);
            GL.Vertex3(area.LocationRightBottom.Lng, area.LocationRightBottom.Lat, 0);
            GL.Vertex3(area.LocationRightBottom.Lng, area.LocationTopLeft.Lat, 0);
            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, 0);

            GL.End();

            GL.Begin(PrimitiveType.LineStrip);
            GL.PointSize(200);
            GL.Color3(Color.Red);
            GL.Vertex3(new Vector3((float)center.Lng, (float)center.Lat, 0));
            GL.Vertex3(new Vector3((float)leftf.Lng, (float)leftf.Lat, 0));

            GL.End();

            GL.Begin(PrimitiveType.Points);
            GL.PointSize(100);
            GL.Color3(Color.Blue);
            GL.Vertex3(new Vector3((float)center.Lng, (float)center.Lat, 0));
            GL.End();

            //textureid.Clear();

            // get type list at new zoom level
            List<GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

             // get tiles & combine into one
            foreach (var p in tileArea)
            {
                core.tileDrawingListLock.AcquireReaderLock();
                core.Matrix.EnterReadLock();
                try
                {
                    GMap.NET.Internals.Tile t = core.Matrix.GetTileWithNoLock(core.Zoom, p);

                    if (t.NotEmpty)
                    {
                        foreach (GMapImage img in t.Overlays)
                        {
                            if (!textureid.ContainsKey(p))
                            {
                                generateTexture(p, (Bitmap)img.Img);
                            }
                        }
                    }
                    else
                    {

                    }
                }
                finally
                {
                    core.Matrix.LeaveReadLock();
                    core.tileDrawingListLock.ReleaseReaderLock();
                }

                //GMapImage tile = ((PureImageCache)Maps.MyImageCache.Instance).GetImageFromCache(type.DbId, p, zoom) as GMapImage;

                //if (tile != null && !textureid.ContainsKey(p))
                {
                  //  generateTexture(p, (Bitmap)tile.Img);
                }

                if (textureid.ContainsKey(p))
                {
                    int texture = textureid[p];

                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, texture);

                }
                else
                {
                    GL.Disable(EnableCap.Texture2D);
                }

                long x = p.X * prj.TileSize.Width - topLeftPx.X;
                long y = p.Y * prj.TileSize.Width - topLeftPx.Y;

                long xr = p.X * prj.TileSize.Width;
                long yr = p.Y * prj.TileSize.Width;

                long x2 = (p.X+1) * prj.TileSize.Width;
                long y2 = (p.Y+1) * prj.TileSize.Width;

                // generate terrain
                GL.Begin(PrimitiveType.TriangleStrip);

                var latlng = prj.FromPixelToLatLng(xr,yr,zoom);

                double heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.Color3(Color.White);
                //xr - topLeftPx.X, yr - topLeftPx.Y
                GL.TexCoord2(0,0);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next down
                latlng = prj.FromPixelToLatLng(xr, y2, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(0,.99);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next right
                latlng = prj.FromPixelToLatLng(x2, yr, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(.99,0);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next right down
                latlng = prj.FromPixelToLatLng(x2, y2, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(.99,.99);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);

                GL.End();

            }


            GL.Enable(EnableCap.Blend);
            GL.DepthMask(false);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
            GL.DepthMask(true);
            GL.Disable(EnableCap.Blend);

            GL.Flush();

            try
            {

                this.SwapBuffers();


                Context.MakeCurrent(null);
            }
            catch { }

            return;
        }
Exemplo n.º 2
1
            public bool LoadFile(string filename)
            {
                FileName = filename;

                log.InfoFormat("GeoTiff {0}", filename);

                using (Tiff tiff = Tiff.Open(filename, "r"))
                {
                    width = tiff.GetField(TiffTag.IMAGEWIDTH)[0].ToInt();
                    height = tiff.GetField(TiffTag.IMAGELENGTH)[0].ToInt();
                    bits = tiff.GetField(TiffTag.BITSPERSAMPLE)[0].ToInt();

                    if (bits != 16)
                        return false;

                    var modelscale = tiff.GetField(TiffTag.GEOTIFF_MODELPIXELSCALETAG);
                    var tiepoint = tiff.GetField(TiffTag.GEOTIFF_MODELTIEPOINTTAG);

                    i = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0);
                    j = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 8);
                    k = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 16);
                    x = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 24);
                    y = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 32);
                    z = BitConverter.ToDouble(tiepoint[1].ToByteArray(), 0 + 40);

                    log.InfoFormat("Tie Point ({0},{1},{2}) --> ({3},{4},{5})", i, j, k, x, y, z);

                    xscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0);
                    yscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0 + 8);
                    zscale = BitConverter.ToDouble(modelscale[1].ToByteArray(), 0 + 16);

                    log.InfoFormat("Scale ({0},{1},{2})", xscale, yscale, zscale);

                    Area = new RectLatLng(y, x, width*xscale, height*yscale);

                    log.InfoFormat("Coverage {0}", Area.ToString());

                    GeoTiff.index.Add(this);

                    /*

                short numberOfDirectories = tiff.NumberOfDirectories();
                for (short d = 0; d < numberOfDirectories; ++d)
                {
                    tiff.SetDirectory((short)d);

                    for (ushort t = ushort.MinValue; t < ushort.MaxValue; ++t)
                    {
                        TiffTag tag = (TiffTag)t;
                        FieldValue[] value = tiff.GetField(tag);
                        if (value != null)
                        {
                            for (int j2 = 0; j2 < value.Length; j2++)
                            {
                                Console.WriteLine("{0} : {1} : {2}", tag.ToString(), value[j2].Value.GetType().ToString(), value[j2].ToString());
                            }
                        }
                    }
                }
                     */
                }

                return true;
            }
Exemplo n.º 3
0
 public MapInfo(RectLatLng Area, int Zoom, GMapProvider Type, bool makeWorldFile)
 {
     this.Area = Area;
      this.Zoom = Zoom;
      this.Type = Type;
      this.MakeWorldFile = makeWorldFile;
 }
Exemplo n.º 4
0
 public MapInfo(PureProjection Projection, RectLatLng Area, int Zoom, MapType Type)
 {
     this.Projection = Projection;
      this.Area = Area;
      this.Zoom = Zoom;
      this.Type = Type;
 }
Exemplo n.º 5
0
Arquivo: GDAL.cs Projeto: Aravent/MP
 public GeoBitmap(string file, double resolution, int rasterXSize, int rasterYSize, double Left, double Top, double Right, double Bottom)
 {
     this.File        = file;
     this.Resolution  = resolution;
     this.RasterXSize = rasterXSize;
     this.RasterYSize = rasterYSize;
     Rect             = new GMap.NET.RectLatLng(Top, Left, Right - Left, Top - Bottom);
 }
Exemplo n.º 6
0
 public static bool RectLatLngCollide(RectLatLng a, RectLatLng b)
 {
     if ((a.Left > b.Left && a.Left < b.Right) || (b.Left > a.Left && b.Left > a.Right))
     {
         if ((a.Top < b.Top && a.Top < b.Top) || (b.Top > a.Top && b.Top > a.Top))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 7
0
 public GridDataPoints activeData(GridDataPoints allPoints, RectLatLng bounds, String id)
 {
     GridDataPoints activePoints = new GridDataPoints(id);
     foreach (GridDataPoint p in allPoints.points)
     {
         if (OverlayProcessor.RectLatLngCollide(p.loc,bounds))
         {
             activePoints.addPoint(p);
         }
     }
     return activePoints;
 }
 /// <summary>
 ///     Get the map data from the AA api service.
 ///     Required scopes: query_mapdata query_mapairdata
 /// </summary>
 /// <param name="latLongBounds">The bounds of the request.</param>
 /// <returns>A collection of GeoJSON features.</returns>
 public Task<AAFeatureCollection> GetMapData(RectLatLng latLongBounds)
 {
     return _apiUrl
         .AppendPathSegments("v2", "mapdata", "geojson")
         .SetQueryParams(new
         {
             n = latLongBounds.Top,
             e = latLongBounds.Right,
             s = latLongBounds.Bottom,
             w = latLongBounds.Left
         })
         .WithClient(_client)
         .GetJsonAsync<AAFeatureCollection>();
 }
        public GMapMarkerOverlapCount(PointLatLng p)
            : base(p)
        {
            area = new RectLatLng(p, SizeLatLng.Empty);

            if (colorbrushs == null)
            {
                colorbrushs = new SolidBrush[color.Length];
                int a = 0;
                foreach (var color1 in color)
                {
                    colorbrushs[a] = new SolidBrush(Color.FromArgb(140, color1.R, color1.G, color1.B));
                    a++;
                }
            }
        }
Exemplo n.º 10
0
        public void Start(RectLatLng area, PureProjection prj, int zoom, MapType type, int sleep)
        {
            if(!worker.IsBusy)
             {
            this.label1.Text = "...";
            this.progressBar1.Value = 0;

            this.prj = prj;
            this.area = area;
            this.zoom = zoom;
            this.type = type;
            this.sleep = sleep;

            GMaps.Instance.UseMemoryCache = false;

            worker.RunWorkerAsync();

            this.ShowDialog();
             }
        }
Exemplo n.º 11
0
        public void Start(RectLatLng area, int zoom, GMapProvider provider, int sleep)
        {
            if (!worker.IsBusy)
            {
                this.label1.Text = "...";
                this.progressBarDownload.Value = 0;

                this.area     = area;
                this.zoom     = zoom;
                this.provider = provider;
                this.sleep    = sleep;

                GMaps.Instance.UseMemoryCache   = false;
                GMaps.Instance.CacheOnIdleRead  = false;
                GMaps.Instance.BoostCacheEngine = true;

                worker.RunWorkerAsync();

                this.ShowDialog();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// gets all tiles in rect at specific zoom
        /// </summary>
        public List <GPoint> GetAreaTileList(RectLatLng rect, int zoom, int padding)
        {
            List <GPoint> ret = new List <GPoint>();

            GPoint topLeft     = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft, zoom));
            GPoint rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.LocationRightBottom, zoom));

            for (long x = (topLeft.X - padding); x <= (rightBottom.X + padding); x++)
            {
                for (long y = (topLeft.Y - padding); y <= (rightBottom.Y + padding); y++)
                {
                    GPoint p = new GPoint(x, y);
                    if (!ret.Contains(p) && p.X >= 0 && p.Y >= 0)
                    {
                        ret.Add(p);
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 13
0
        public void Start(RectLatLng area, int zoom, GMapProvider provider, int sleep)
        {
            if(!worker.IsBusy)
             {
            this.label1.Text = "...";
            this.progressBarDownload.Value = 0;

            this.area = area;
            this.zoom = zoom;
            this.provider = provider;
            this.sleep = sleep;

            GMaps.Instance.UseMemoryCache = false;
            GMaps.Instance.CacheOnIdleRead = false;
            GMaps.Instance.BoostCacheEngine = true;

            worker.RunWorkerAsync();

            this.ShowDialog();
             }
        }
        public SuperMapProjection(double[] mapScales, MapParameter defaultMapParameter)
        {
            if (mapScales == null)
                throw new ArgumentNullException();
            if (defaultMapParameter == null)
            {
                throw new ArgumentNullException();
            }

            _mapScales = mapScales;
            _bounds = RectLatLng.FromLTRB(defaultMapParameter.Bounds.LeftBottom.X, 
                defaultMapParameter.Bounds.RightTop.Y, 
                defaultMapParameter.Bounds.RightTop.X, 
                defaultMapParameter.Bounds.LeftBottom.Y);

            if (defaultMapParameter.Bounds == null)
                throw new ArgumentNullException();
            _minX = defaultMapParameter.Bounds.LeftBottom.X;
            _minY = defaultMapParameter.Bounds.LeftBottom.Y;
            _maxX = defaultMapParameter.Bounds.RightTop.X;
            _maxY = defaultMapParameter.Bounds.RightTop.Y;

            if (defaultMapParameter.PrjCoordSys != null &&
                defaultMapParameter.PrjCoordSys.CoordSystem != null &&
                defaultMapParameter.PrjCoordSys.CoordSystem.Datum != null &&
                defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid != null)
            {
                _axis = defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid.Axis;
                _flattening = defaultMapParameter.PrjCoordSys.CoordSystem.Datum.Spheroid.Flatten;
            }

            double refMapScale = defaultMapParameter.Scale;
            double refResolution = (defaultMapParameter.ViewBounds.RightTop.X - defaultMapParameter.ViewBounds.LeftBottom.X) /
                (defaultMapParameter.Viewer.Width);
            _resolutions = new double[_mapScales.Length];
            for (int i = 0; i < _mapScales.Length; i++)
            {
                _resolutions[i] = refResolution * refMapScale / mapScales[i];
            }
        }
Exemplo n.º 15
0
        /// <summary>
        ///     gets all tiles in rect at specific zoom
        /// </summary>
        public List <GPoint> GetAreaTileList(RectLatLng rect, int zoom, int padding)
        {
            var topLeft     = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft, zoom));
            var rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.LocationRightBottom, zoom));

            long x   = Max(0, topLeft.X - padding);
            long toX = rightBottom.X + padding;
            long y0  = Max(0, topLeft.Y - padding);
            long toY = rightBottom.Y + padding;

            var list = new List <GPoint>((int)((toX - x + 1) * (toY - y0 + 1)));

            for (; x <= toX; x++)
            {
                for (long y = y0; y <= toY; y++)
                {
                    list.Add(new GPoint(x, y));
                }
            }

            return(list);
        }
Exemplo n.º 16
0
 static RectLatLng()
 {
     Empty = new RectLatLng();
 }
Exemplo n.º 17
0
 public static RectLatLng Inflate(RectLatLng rect, double lat, double lng)
 {
     RectLatLng ef = rect;
      ef.Inflate(lat, lng);
      return ef;
 }
Exemplo n.º 18
0
        // ok ???
        public static RectLatLng Intersect(RectLatLng a, RectLatLng b)
        {
            double lng = Math.Max(a.Lng, b.Lng);
             double num2 = Math.Min((double)(a.Lng + a.WidthLng), (double)(b.Lng + b.WidthLng));

             double lat = Math.Max(a.Lat, b.Lat);
             double num4 = Math.Min((double)(a.Lat + a.HeightLat), (double)(b.Lat + b.HeightLat));

             if((num2 >= lng) && (num4 >= lat))
             {
            return new RectLatLng(lat, lng, num2 - lng, num4 - lat);
             }
             return Empty;
        }
Exemplo n.º 19
0
      /// <summary>
      /// sets zoom to max to fit rect
      /// </summary>
      /// <param name="rect">area</param>
      /// <returns></returns>
      public bool SetZoomToFitRect(RectLatLng rect)
      {
         if(lazyEvents)
         {
            lazySetZoomToFitRect = rect;
         }
         else
         {
            int maxZoom = Core.GetMaxZoomToFitRect(rect);
            if(maxZoom > 0)
            {
               PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2));
               Position = center;

               if(maxZoom > MaxZoom)
               {
                  maxZoom = MaxZoom;
               }

               if(Core.Zoom != maxZoom)
               {
                  Zoom = maxZoom;
               }

               return true;
            }
         }
         return false;
      }
Exemplo n.º 20
0
      protected override void OnMouseMove(MouseEventArgs e)
      {
         base.OnMouseMove(e);
          
         // wpf generates to many events if mouse is over some visual
         // and OnMouseUp is fired, wtf, anyway...
         // http://greatmaps.codeplex.com/workitem/16013
         if((e.Timestamp & Int32.MaxValue) - onMouseUpTimestamp < 55)
         {
            Debug.WriteLine("OnMouseMove skipped: " + ((e.Timestamp & Int32.MaxValue) - onMouseUpTimestamp) + "ms");
            return;
         }

         if(!Core.IsDragging && !Core.mouseDown.IsEmpty)
         {
            Point p = e.GetPosition(this);

            if(MapScaleTransform != null)
            {
               p = MapScaleTransform.Inverse.Transform(p);
            }

            p = ApplyRotationInversion(p.X, p.Y);

            // cursor has moved beyond drag tolerance
            if(Math.Abs(p.X - Core.mouseDown.X) * 2 >= SystemParameters.MinimumHorizontalDragDistance || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= SystemParameters.MinimumVerticalDragDistance)
            {
               Core.BeginDrag(Core.mouseDown);
            }
         }

         if(Core.IsDragging)
         {
            if(!isDragging)
            {
               isDragging = true;
               Debug.WriteLine("IsDragging = " + isDragging);
               cursorBefore = Cursor;
               Cursor = Cursors.SizeAll;
               Mouse.Capture(this);
            }

            if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position))
            {
               // ...
            }
            else
            {
               Point p = e.GetPosition(this);

               if(MapScaleTransform != null)
               {
                  p = MapScaleTransform.Inverse.Transform(p);
               }

               p = ApplyRotationInversion(p.X, p.Y);

               Core.mouseCurrent.X = (int)p.X;
               Core.mouseCurrent.Y = (int)p.Y;
               {
                  Core.Drag(Core.mouseCurrent);
               }

               if(IsRotated || scaleMode != ScaleModes.Integer)
               {
                  ForceUpdateOverlays();
               }
               else
               {
                  UpdateMarkersOffset();
               }
            }
            InvalidateVisual(true);
         }
         else
         {
            if(isSelected && !selectionStart.IsEmpty && (Keyboard.Modifiers == ModifierKeys.Shift || Keyboard.Modifiers == ModifierKeys.Alt || DisableAltForSelection))
            {
               System.Windows.Point p = e.GetPosition(this);
               selectionEnd = FromLocalToLatLng((int)p.X, (int)p.Y);
               {
                  GMap.NET.PointLatLng p1 = selectionStart;
                  GMap.NET.PointLatLng p2 = selectionEnd;

                  double x1 = Math.Min(p1.Lng, p2.Lng);
                  double y1 = Math.Max(p1.Lat, p2.Lat);
                  double x2 = Math.Max(p1.Lng, p2.Lng);
                  double y2 = Math.Min(p1.Lat, p2.Lat);

                  SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2);
               }
            }

            if(renderHelperLine)
            {
               InvalidateVisual(true);
            }
         }         
      }
Exemplo n.º 21
0
 void GmapWidget_OnSelectionChange(RectLatLng Selection, bool ZoomToFit)
 {
     if (poligonSelection)
         return;
     var selected = addressesOverlay.Markers.Where(m => Selection.Contains(m.Position)).ToList();
     UpdateSelectedInfo(selected);
 }
Exemplo n.º 22
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (Core.IsDragging)
            {
                if (!isDragging)
                {
                    isDragging = true;
                    Debug.WriteLine("IsDragging = " + isDragging);
                }

                if (BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position))
                {
                    // ...
                }
                else
                {
                    Core.mouseCurrent = ApplyRotationInversion(e.X, e.Y);
                    Core.Drag(Core.mouseCurrent);
                    Refresh();
                }
            }
            else
            {
                if (isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift))
                {
                    selectionEnd = FromLocalToLatLng(e.X, e.Y);
                    {
                        GMap.NET.PointLatLng p1 = selectionStart;
                        GMap.NET.PointLatLng p2 = selectionEnd;

                        double x1 = Math.Min(p1.Lng, p2.Lng);
                        double y1 = Math.Max(p1.Lat, p2.Lat);
                        double x2 = Math.Max(p1.Lng, p2.Lng);
                        double y2 = Math.Min(p1.Lat, p2.Lat);

                        SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2);
                    }
                }
            }

            base.OnMouseMove(e);
        }
Exemplo n.º 23
0
 public void Intersect(RectLatLng rect)
 {
     RectLatLng ef = Intersect(rect, this);
      this.Lng = ef.Lng;
      this.Lat = ef.Lat;
      this.WidthLng = ef.WidthLng;
      this.HeightLat = ef.HeightLat;
 }
Exemplo n.º 24
0
        /// <summary>
        /// gets all tiles in rect at specific zoom
        /// </summary>
        public List<Point> GetAreaTileList(RectLatLng rect, int zoom, int padding)
        {
            List<Point> ret = new List<Point>();

            Point topLeft = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft, zoom));
            Point rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.LocationRightBottom, zoom));

            for (int x = (topLeft.X - padding); x <= (rightBottom.X + padding); x++)
            {
                for (int y = (topLeft.Y - padding); y <= (rightBottom.Y + padding); y++)
                {
                    Point p = new Point(x, y);
                    if (!ret.Contains(p) && p.X >= 0 && p.Y >= 0)
                    {
                        ret.Add(p);
                    }
                }
            }
            ret.TrimExcess();

            return ret;
        }
Exemplo n.º 25
0
 // ok ???
 // http://greatmaps.codeplex.com/workitem/15981
 public static RectLatLng Union(RectLatLng a, RectLatLng b)
 {
     return RectLatLng.FromLTRB(
     Math.Min(a.Left, b.Left),
     Math.Max(a.Top, b.Top),
     Math.Max(a.Right, b.Right),
     Math.Min(a.Bottom, b.Bottom));
 }
Exemplo n.º 26
0
        static PointF GetPixel(RectLatLng area, PointLatLngAlt loc, Size size) 
        {
            double lon =  loc.Lng;
            double lat = loc.Lat;

            double lonscale = (lon - area.Left) * (size.Width - 0) / (area.Right - area.Left) + 0;

            double latscale = (lat - area.Top) * (size.Height - 0) / (area.Bottom - area.Top) + 0;

            return new PointF((float)lonscale, (float)latscale);
        }
Exemplo n.º 27
0
 static RectLatLng()
 {
     Empty = new RectLatLng();
 }
Exemplo n.º 28
0
 // ok ???
 // http://greatmaps.codeplex.com/workitem/15981
 public bool IntersectsWith(RectLatLng a)
 {
     return(this.Left < a.Right && this.Top > a.Bottom && this.Right > a.Left && this.Bottom < a.Top);
 }
Exemplo n.º 29
0
 public bool Contains(RectLatLng rect)
 {
     return((((this.Lng <= rect.Lng) && ((rect.Lng + rect.WidthLng) <= (this.Lng + this.WidthLng))) && (this.Lat >= rect.Lat)) && ((rect.Lat - rect.HeightLat) >= (this.Lat - this.HeightLat)));
 }
Exemplo n.º 30
0
 public bool Contains(RectLatLng rect)
 {
     return ((((this.Lng <= rect.Lng) && ((rect.Lng + rect.WidthLng) <= (this.Lng + this.WidthLng))) && (this.Lat >= rect.Lat)) && ((rect.Lat - rect.HeightLat) >= (this.Lat - this.HeightLat)));
 }
Exemplo n.º 31
0
 // ok ???
 public static RectLatLng Union(RectLatLng a, RectLatLng b)
 {
     double lng = Math.Min(a.Lng, b.Lng);
      double num2 = Math.Max((double) (a.Lng + a.WidthLng), (double) (b.Lng + b.WidthLng));
      double lat = Math.Min(a.Lat, b.Lat);
      double num4 = Math.Max((double) (a.Lat + a.HeightLat), (double) (b.Lat + b.HeightLat));
      return new RectLatLng(lng, lat, num2 - lng, num4 - lat);
 }
Exemplo n.º 32
0
 // ok ???
 // http://greatmaps.codeplex.com/workitem/15981
 public bool IntersectsWith(RectLatLng a)
 {
     return this.Left < a.Right && this.Top > a.Bottom && this.Right > a.Left && this.Bottom < a.Top;
 }
Exemplo n.º 33
0
 // ok ???
 public bool IntersectsWith(RectLatLng rect)
 {
     return ((((rect.Lng < (this.Lng + this.WidthLng)) && (this.Lng < (rect.Lng + rect.WidthLng))) && (rect.Lat < (this.Lat + this.HeightLat))) && (this.Lat < (rect.Lat + rect.HeightLat)));
 }
Exemplo n.º 34
0
        private RectLatLng union(RectLatLng r1, RectLatLng r2) {

            double l = Math.Min(r1.Left, r2.Left);
            double t = Math.Max(r1.Top, r2.Top);
            double r = Math.Max(r2.Right, r1.Right);
            double b = Math.Min(r1.Bottom, r2.Bottom);
            return new RectLatLng(t, l, r - l, t - b);
        }
Exemplo n.º 35
0
        /// <summary>
        /// sets zoom to max to fit rect
        /// </summary>
        /// <param name="rect">area</param>
        /// <returns></returns>
        public bool SetZoomToFitRect(RectLatLng rect)
        {
            int maxZoom = Core.GetMaxZoomToFitRect(rect);
             if(maxZoom > 0)
             {
            PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2));
            CurrentPosition = center;

            if(maxZoom > MaxZoom)
            {
               maxZoom = MaxZoom;
            }

            if(ZoomStep != maxZoom)
            {
               Zoom = maxZoom;
            }

            return true;
             }
             return false;
        }
Exemplo n.º 36
0
 // ok ???
 public bool IntersectsWith(RectLatLng rect)
 {
     return((((rect.Lng < (this.Lng + this.WidthLng)) && (this.Lng < (rect.Lng + rect.WidthLng))) && (rect.Lat < (this.Lat + this.HeightLat))) && (this.Lat < (rect.Lat + rect.HeightLat)));
 }
 public bool Contains(RectLatLng rect)
 {
     return(Lng <= rect.Lng && rect.Lng + rect.WidthLng <= Lng + WidthLng &&
            Lat >= rect.Lat && rect.Lat - rect.HeightLat >= Lat - HeightLat);
 }
Exemplo n.º 38
0
        static Bitmap GetMap(RectLatLng area)
        {
            GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj = type.Projection;

            int zoom = 16;

            GPoint topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
            GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
            GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            // zoom based on pixel density
            while (pxDelta.X > 2000)
            {
                zoom--;

                // current area
                topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            }

            // get type list at new zoom level
            List<GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

            int padding = 10;

            Bitmap bmpDestination = new Bitmap((int)pxDelta.X + padding * 2, (int)pxDelta.Y + padding * 2);

            {
                using (Graphics gfx = Graphics.FromImage(bmpDestination))
                {
                    gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                    // get tiles & combine into one
                    foreach (var p in tileArea)
                    {
                        Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count);

                        foreach (var tp in type.Overlays)
                        {
                            Exception ex;
                            GMapImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage;

                            if (tile != null)
                            {
                                using (tile)
                                {
                                    long x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                    long y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                    {
                                        gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                    }
                                }
                            }
                        }
                    }
                }

                return bmpDestination;
            }
        }
Exemplo n.º 39
0
            public void LoadFile(string filename)
            {
                log.InfoFormat("DTED {0}", filename);

                using (var stream = File.OpenRead(filename))
                {
                    byte[] buffer = new byte[80];
                    stream.Read(buffer, 0, buffer.Length);

                    var UHL = user_header_label.Match(ASCIIEncoding.ASCII.GetString(buffer));

                    buffer = new byte[648];
                    stream.Read(buffer, 0, buffer.Length);

                    var DSI = data_set_identification.Match(ASCIIEncoding.ASCII.GetString(buffer));

                    buffer = new byte[2700];
                    stream.Read(buffer, 0, buffer.Length);

                    var ACC = accuracy_description.Match(ASCIIEncoding.ASCII.GetString(buffer));

                    width = int.Parse(UHL.Groups[10].Value);
                    height = int.Parse(UHL.Groups[11].Value);

                    log.InfoFormat("Size ({0},{1})", width, height);

                    // lower left corner
                    x = DDDMMSSH2DD(UHL.Groups[3].Value);
                    y = DDDMMSSH2DD(UHL.Groups[4].Value);

                    log.InfoFormat("Start Point ({0},{1})", x, y);

                    // scales
                    xscale = SSSS2DD(UHL.Groups[5].Value);
                    yscale = SSSS2DD(UHL.Groups[6].Value);

                    log.InfoFormat("Scale ({0},{1})", xscale, yscale);

                    // switch top for bottom
                    y += height * yscale;

                    Area = new RectLatLng(y, x, width * xscale, height * yscale);

                    log.InfoFormat("Coverage {0}", Area.ToString());

                    FileName = filename;
                    index.Add(this);
                }
            }