Beispiel #1
0
 public LatviaMapProviderBase()
 {
    RefererUrl = "http://www.ikarte.lv/default.aspx?lang=en";
    Copyright = string.Format("©{0} Hnit-Baltic - Map data ©{0} LR Valsts zemes dieniests, SIA Envirotech", DateTime.Today.Year);
    MaxZoom = 11;
    Area = new RectLatLng(58.0794870805093, 20.3286067123543, 7.90883164336887, 2.506129113082);
 }
 public LithuaniaMapProviderBase()
 {
    RefererUrl = "http://www.maps.lt/map/";
    Copyright = string.Format("©{0} Hnit-Baltic - Map data ©{0} ESRI", DateTime.Today.Year);
    MaxZoom = 12;
    Area = new RectLatLng(56.431489960361, 20.8962105239809, 5.8924169643369, 2.58940626652217);
 }
        public void Start(RectLatLng area, int zoom, GMapProvider provider, int sleep)
        {
            if (!_worker.IsBusy)
            {
                Label1.Text        = "...";
                ProgressBar1.Value = 0;

                _area     = area;
                _zoom     = zoom;
                _provider = provider;
                _sleep    = sleep;

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

                _worker.RunWorkerAsync();

                ShowDialog();
            }
        }
Beispiel #4
0
        public void Start(RectLatLng area, int zoom, GMapProvider provider, int sleep)
        {
            if(!worker.IsBusy)
             {
            this.label1.Text = "...";
            this.progressBar1.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();
             }
        }
Beispiel #5
0
        /// <summary>
        /// 根据层级获取矩形区域内的所有瓦片索引
        /// </summary>
        public static List <PointInt64> GetAreaTileList(RectLatLng rect, int zoom, int padding = 0)
        {
            List <PointInt64> ret = new List <PointInt64>();

            PointInt64 topLeft     = PixelToTileXY(LatLngToPixel(rect.LeftTop, zoom));
            PointInt64 rightBottom = PixelToTileXY(LatLngToPixel(rect.RightBottom, zoom));

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

            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// gets max zoom level to fit rectangle
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public int GetMaxZoomToFitRect(RectLatLng rect)
        {
            int zoom = minZoom;

            for (int i = zoom; i <= maxZoom; i++)
            {
                Point p1 = Projection.FromLatLngToPixel(rect.LocationTopLeft, i);
                Point p2 = Projection.FromLatLngToPixel(rect.LocationRightBottom, i);

                if (((p2.X - p1.X) <= Width + 10) && (p2.Y - p1.Y) <= Height + 10)
                {
                    zoom = i;
                }
                else
                {
                    break;
                }
            }

            return(zoom);
        }
        private async void buttonFind_ClickAsync(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                //Debug.WriteLine( "InvokeRequired" );
                var d = new SafeCallDelegate(buttonFind_ClickAsync);
                this.Invoke(d, new object[] { this, null });
                return;
            }


            //logger.Info( viewArea.LocationTopLeft + " " + viewArea.LocationRightBottom );

            labelMsg.Text = null;

            //AqiPackage aqiPackage = await controller.getDataAsync( viewArea );

            int minutes = ((ComboTypeItem)comboBoxTime.SelectedItem).Value();


            Object results = await controller.getDataAsync(minutes, viewArea);

            if (results is String)
            {
                gmap.Overlays.Clear();
                gmap.Refresh();
                labelMsg.Text = "No stations found: " + results;
                return;
            }

            if (viewArea == null)
            {
                viewArea = gmap.ViewArea;
            }

            lastViewArea = gmap.ViewArea;

            PlotData();
            //
        }
Beispiel #8
0
        public void CalcPicCountAndSave()
        {
            DataTable dt = new DataTable();

            dt = GisSqliteOperate.GetAllData();

            for (int j = 0; j < dt.Rows.Count; j++)
            {
                string jgid        = dt.Rows[j]["gid"].ToString();
                string jname       = dt.Rows[j]["name"].ToString();
                string jparent_gid = dt.Rows[j]["parent_gid"].ToString();
                string jdl         = dt.Rows[j]["dl"].ToString();
                string jdr         = dt.Rows[j]["dr"].ToString();
                string jtl         = dt.Rows[j]["tl"].ToString();
                string jtr         = dt.Rows[j]["tr"].ToString();

                double tllat2 = dt.Rows[j]["tl"].ToString().Equals(string.Empty) ? 0.0 : double.Parse(dt.Rows[j]["tl"].ToString().Split(' ')[1].ToString());
                double tllng2 = dt.Rows[j]["tl"].ToString().Equals(string.Empty) ? 0.0 : double.Parse(dt.Rows[j]["tl"].ToString().Split(' ')[0].ToString());
                double trlng2 = dt.Rows[j]["tr"].ToString().Equals(string.Empty) ? 0.0 : double.Parse(dt.Rows[j]["tr"].ToString().Split(' ')[0].ToString());
                double dllat2 = dt.Rows[j]["dl"].ToString().Equals(string.Empty) ? 0.0 : double.Parse(dt.Rows[j]["dl"].ToString().Split(' ')[1].ToString());

                RectLatLng rect       = new RectLatLng(tllat2, tllng2, trlng2 - tllng2, tllat2 - dllat2);
                string     totalCount = string.Empty;
                for (int i = 1; i <= 18; i++)
                {
                    int count = GetPicCount(rect, i, 0);
                    Console.WriteLine("Name:{0}, gid:{1}, zoom:{2}, count:{3}", jname, jgid, i.ToString(), count.ToString());
                    if (i == 1)
                    {
                        totalCount += count.ToString();
                    }
                    else
                    {
                        totalCount += "," + count.ToString();
                    }
                }
                Console.WriteLine(totalCount.ToString());
                GisSqliteOperate.UpdatePicCount(totalCount, jgid);
            }
        }
Beispiel #9
0
        private void button3_Click(object sender, EventArgs e)
        {
            RectLatLng area = gmap.SelectedArea;

            if (area.IsEmpty)
            {
                DialogResult res = MessageBox.Show("No ripp area defined, ripp displayed on screen?", "Rip", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    area = gmap.ViewArea;
                }
            }

            if (!area.IsEmpty)
            {
                DialogResult res = MessageBox.Show("Ready ripp at Zoom = " + (int)gmap.Zoom + " ?", "GMap.NET", MessageBoxButtons.YesNo);

                for (int i = 1; i <= gmap.MaxZoom; i++)
                {
                    if (res == DialogResult.Yes)
                    {
                        TilePrefetcher obj = new TilePrefetcher();
                        obj.ShowCompleteMessage = false;
                        obj.Start(area, i, gmap.MapProvider, 100, 0);
                    }
                    else if (res == DialogResult.No)
                    {
                        continue;
                    }
                    else if (res == DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
            else
            {
                //MessageBox.Show("Select map area holding ALT", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        public RectLatLng GetViewArea()
        {
            RectLatLng rectLatLng = default(RectLatLng);

            try
            {
                _context.Send(_ => rectLatLng = _mapControl.ViewArea, null);
            }
            catch (Exception ex)
            {
            }
            if (rectLatLng.WidthLng < 0.03)
            {
                rectLatLng.Inflate(0, (0.03 - rectLatLng.WidthLng) / 2);
            }
            if (rectLatLng.HeightLat < 0.03)
            {
                rectLatLng.Inflate((0.03 - rectLatLng.HeightLat) / 2, 0);
            }

            return(rectLatLng);
        }
Beispiel #11
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);
                    }
                }
            }
            ret.TrimExcess();

            return(ret);
        }
Beispiel #12
0
        private void DownLoadMap()
        {//C:\Users\NNNNN\AppData\Local\GMap.NET\TileDBv5\zh-CN
            RectLatLng area = RectLatLng.FromLTRB(104.28077393000, 26.58757324030, 112.25690002000, 20.70236091970);

            if (!area.IsEmpty)
            {
                try
                {
                    for (int i = 10; i <= 11; i++)
                    {
                        GMap.NET.WindowsPresentation.TilePrefetcher obj = new GMap.NET.WindowsPresentation.TilePrefetcher();
                        obj.Owner = MainWindow.obj;
                        obj.ShowCompleteMessage = true;
                        obj.Start(area, i, m_mapCtl.MapProvider, 100);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
Beispiel #13
0
        private void MoveToRegion(MapSpan span)
        {
            try
            {
                if (span == null)
                {
                    return;
                }

                var p1 = new PointLatLng
                {
                    Lat = span.Center.Latitude + span.LatitudeDegrees / 2,
                    Lng = span.Center.Longitude - span.LongitudeDegrees / 2
                };

                var p2 = new PointLatLng
                {
                    Lat = span.Center.Latitude - span.LatitudeDegrees / 2,
                    Lng = span.Center.Longitude + span.LongitudeDegrees / 2
                };

                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);

                var region = new RectLatLng(y1, x1, x2 - x1, y1 - y2);

                Control.SelectionPen = new Pen(Brushes.Transparent, 2);
                Control.SelectedArea = region;
                Control.SetZoomToFitRect(region);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("MoveToRegion exception: " + ex);
                Log.Warning("System.Maui MapRenderer", $"MoveToRegion exception: {ex}");
            }
        }
Beispiel #14
0
            public void LoadFile(string 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);

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

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

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

                    Area     = new RectLatLng(y, x, width * xscale, height * yscale);
                    FileName = filename;
                    index.Add(this);
                }
            }
Beispiel #15
0
        public void Add(GMapPolygon footprint)
        {
            DateTime start = DateTime.Now;

            // if the same name footprint exists exit
            if (footprintpolys.Any(p => p.Name == footprint.Name))
            {
                return;
            }

            // if this is the first entry reset area
            if (footprintpolys.Count == 0)
            {
                Position = footprint.Points[0];
                area     = new RectLatLng(footprint.Points[0], new SizeLatLng(0, 0));
            }

            // add the new footprint
            footprintpolys.Add(footprint);

            // recalc the area
            foreach (var point in footprint.Points)
            {
                if (!area.Contains(point))
                {
                    double tllat = Math.Max(area.Lat, point.Lat);
                    double tllng = Math.Min(area.Lng, point.Lng);
                    double brlat = Math.Min(area.Bottom, point.Lat);
                    double brlng = Math.Max(area.Right, point.Lng);
                    // enlarge the area
                    area = RectLatLng.FromLTRB(tllng, tllat, brlng, brlat);
                }
            }

            generateCoverageFP(footprint);

            Console.WriteLine("Add " + (DateTime.Now - start));
        }
        private RectLatLng polygonToRect(List <PointLatLng> points)
        {
            double lat = (points[0].Lat + points[2].Lat) / 2;
            double lon = (points[0].Lng + points[2].Lng) / 2;

            if (points[0].Lat > points[3].Lat)
            {
                if (points[0].Lng < points[1].Lng) //top left -> bottom right
                {
                    lat = lat - (lat - points[0].Lat);
                    lon = lon - (lon - points[3].Lng);
                }
                else //top right -> bottom left
                {
                    lat = lat + (lat - points[3].Lat);
                    lon = lon + (lon - points[0].Lng);
                }
            }
            else
            {
                if (points[0].Lng > points[1].Lng) //bottom right -> top left
                {
                    lat = lat + (lat - points[0].Lat);
                    lon = lon + (lon - points[3].Lng);
                }
                else
                {
                    lat = lat - (lat - points[3].Lat); //bottom left -> top right
                    lon = lon - (lon - points[0].Lng);
                }
            }

            double     width  = Math.Abs(Math.Abs(points[1].Lng) - Math.Abs(points[0].Lng));
            double     height = Math.Abs(Math.Abs(points[3].Lat) - Math.Abs(points[0].Lat));
            RectLatLng rect   = new RectLatLng(lat, lon, width, height);

            return(rect);
        }
Beispiel #17
0
        private void btnDownSelMap_Click(object sender, EventArgs e)
        {
            RectLatLng area = MainMap.SelectedArea;

            if (!area.IsEmpty)
            {
                for (int i = (int)MainMap.Zoom; i <= MainMap.MaxZoom; i++)
                {
                    DialogResult res = MessageBox.Show("Ready ripp at Zoom = " + i + " ?", "GMap.NET", MessageBoxButtons.YesNoCancel);

                    if (res == DialogResult.Yes)
                    {
                        using (TilePrefetcher obj = new TilePrefetcher())
                        {
                            obj.Overlay = objectsLay; // set overlay if you want to see cache progress on the map

                            obj.Shuffle = MainMap.Manager.Mode != AccessMode.CacheOnly;

                            obj.Owner = this;
                            obj.ShowCompleteMessage = true;
                            obj.Start(area, i, MainMap.MapProvider, MainMap.Manager.Mode == AccessMode.CacheOnly ? 0 : 100, MainMap.Manager.Mode == AccessMode.CacheOnly ? 0 : 1);
                        }
                    }
                    else if (res == DialogResult.No)
                    {
                        continue;
                    }
                    else if (res == DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show(" Alt + 右键选择地图", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Beispiel #18
0
        private static void MapProviderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            MiniGMapControl map = (MiniGMapControl)d;

            if (map != null && e.NewValue != null)
            {
                RectLatLng viewarea = map.SelectedArea;
                if (viewarea != RectLatLng.Empty)
                {
                    map.Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2);
                }
                else
                {
                    viewarea = map.ViewArea;
                }

                map.Core.Provider = e.NewValue as GMapProvider;

                map.Copyright = null;
                if (!string.IsNullOrEmpty(map.Core.Provider.Copyright))
                {
                    map.Copyright = new FormattedText(map.Core.Provider.Copyright, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, new Typeface("GenericSansSerif"), 9, Brushes.Navy);
                }

                if (map.Core.IsStarted && map.Core.zoomToArea)
                {
                    // restore zoomrect as close as possible
                    if (viewarea != RectLatLng.Empty && viewarea != map.ViewArea)
                    {
                        int bestZoom = map.Core.GetMaxZoomToFitRect(viewarea);
                        if (bestZoom > 0 && map.Zoom != bestZoom)
                        {
                            map.Zoom = bestZoom;
                        }
                    }
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// sets zoom to max to fit rect
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public bool SetZoomToFitRect(RectLatLng rect)
        {
            int mmaxZoom = GetMaxZoomToFitRect(rect);

            if (mmaxZoom > 0)
            {
                PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2));
                Position = center;

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

                if (Zoom != mmaxZoom)
                {
                    Zoom = (int)mmaxZoom;
                }

                return(true);
            }
            return(false);
        }
        /// <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);
        }
Beispiel #21
0
        public void Start(RectLatLng area, int minZoom, int maxZoom, GMapProvider provider, int retryNum)
        {
            this.Retry = retryNum;

            if (!worker.IsBusy)
            {
                WorkerArgs args = new WorkerArgs();
                args.MinZoom  = minZoom;
                args.MaxZoom  = maxZoom;
                args.Area     = area;
                args.Provider = provider;

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

                if (PrefetchTileStart != null)
                {
                    PrefetchTileStart(this, new TileDownloadEventArgs(0));
                }

                worker.RunWorkerAsync(args);
            }
        }
Beispiel #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            RectLatLng area = gMapControl1.SelectedArea;

            if (!area.IsEmpty)
            {
                for (int i = (int)gMapControl1.Zoom; i <= gMapControl1.MaxZoom; i++)
                {
                    DialogResult res = MessageBox.Show("Ready ripp at Zoom = " + i + " ?", "GMap.NET", MessageBoxButtons.YesNoCancel);

                    if (res == DialogResult.Yes)
                    {
                        bool mode = gMapControl1.Manager.Mode != AccessMode.CacheOnly;
                        using (TilePrefetcher obj = new TilePrefetcher())
                        {
                            obj.Shuffle = gMapControl1.Manager.Mode != AccessMode.CacheOnly;

                            obj.Owner = this;
                            obj.ShowCompleteMessage = true;
                            obj.Start(area, i, gMapControl1.MapProvider, gMapControl1.Manager.Mode == AccessMode.CacheOnly ? 0 : 100, gMapControl1.Manager.Mode == AccessMode.CacheOnly ? 0 : 1);
                        }
                    }
                    else if (res == DialogResult.No)
                    {
                        continue;
                    }
                    else if (res == DialogResult.Cancel)
                    {
                        break;
                    }
                }
            }
            else
            {
                MessageBox.Show("Select map area holding ALT", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private RectLatLng GetShapeRect(double[] adfMinBound, double[] adfMaxBound)
        {
            double minX, minY, maxX, maxY;

            minX = adfMinBound[0];
            minY = adfMinBound[1];

            var minZone = (int)minX / 1000000;

            minX = minX - minZone * 1000000;

            maxX = adfMaxBound[0];
            maxY = adfMaxBound[1];

            var maxZone = (int)maxX / 1000000;

            maxX = maxX - maxZone * 1000000;

            var projection = new GaussKrugerProjection();

            projection.Ellipsoid = ReferenceEllipsoid.International1975;

            double lat, lng;

            projection.LongitudeOfOrigin = minZone * 3;
            projection.Reverse(minX, minY, out lat, out lng);
            var minLB = new GeocentricCoordinate(lat, lng);

            projection.LongitudeOfOrigin = maxZone * 3;
            projection.Reverse(maxX, maxY, out lat, out lng);
            var maxLB = new GeocentricCoordinate(lat, lng);

            // 取得图形范围用于显示
            var rect = new RectLatLng(maxLB.Latitude.Digital, minLB.Longitude.Digital, maxLB.Longitude.Digital - minLB.Longitude.Digital, maxLB.Latitude.Digital - minLB.Latitude.Digital);

            return(rect);
        }
Beispiel #24
0
        private void CacheBtn_Click(object sender, RoutedEventArgs e)
        {
            RectLatLng area = mapView.SelectedArea;

            if (!area.IsEmpty)
            {
                for (int i = (int)mapView.Zoom; i <= mapView.MaxZoom; i++)
                {
                    TilePrefetcher obj = new TilePrefetcher();
                    obj.Title = "Prefetching Tiles";
                    obj.Icon  = this.Icon;
                    obj.Owner = this;
                    obj.ShowCompleteMessage = false;
                    obj.Start(area, i, mapView.MapProvider, 100);
                }


                Close();
            }
            else
            {
                MessageBox.Show("No Area Chosen", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #25
0
        /// <summary>
        ///     Updates a map with the latest ground / air data
        /// </summary>
        /// <param name="map">The map to update</param>
        /// <returns></returns>
        private async Task UpdateMapData(IMap map)
        {
            if (!IsSignedIn)
            {
                return;
            }

            try
            {
                RectLatLng area = map.GetViewArea();
                await _messagesService.AddMessageAsync($"Map area {area.Top}, {area.Bottom}, {area.Left}, {area.Right}");

                AAFeatureCollection mapData = await _client.GetMapData(area);

                // build the filter list
                mapData.GetFilters();

                // this ensures the user sees the results before its saved
                _settings.MapFilters = FilteredOut;

                await _messagesService.AddMessageAsync($"Map area Loaded {area.Top}, {area.Bottom}, {area.Left}, {area.Right}");

                // add all items to cache
                MapFeatureCache.Clear();
                mapData.Features.ForEach(feature => MapFeatureCache[feature.Id] = feature);

                // Only get the features that are enabled by default, and have not been filtered out
                IEnumerable <Feature> features = mapData.Features.Where(feature => feature.IsEnabledByDefault() && feature.IsFilterOutItem(FilteredOut)).ToList();

                ProcessFeatures(map, features);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Beispiel #26
0
 public Placemark(Placemark oth)
 {
     this.Address                   = oth.Address;
     this.Category                  = oth.Category;
     this.ProvinceName              = oth.ProvinceName;
     this.CityName                  = oth.CityName;
     this.CountryCode               = oth.CountryCode;
     this.LatLonBox                 = oth.LatLonBox;
     this.Name                      = oth.Name;
     this.Tel                       = oth.Tel;
     this.Point                     = oth.Point;
     this.Accuracy                  = oth.Accuracy;
     this.HouseNo                   = oth.HouseNo;
     this.ThoroughfareName          = oth.ThoroughfareName;
     this.DistrictName              = oth.DistrictName;
     this.LocalityName              = oth.LocalityName;
     this.PostalCodeNumber          = oth.PostalCodeNumber;
     this.CountryName               = oth.CountryName;
     this.CountryNameCode           = oth.CountryNameCode;
     this.AdministrativeAreaName    = oth.AdministrativeAreaName;
     this.SubAdministrativeAreaName = oth.SubAdministrativeAreaName;
     this.Neighborhood              = oth.Neighborhood;
     this.StreetNumber              = oth.StreetNumber;
 }
        public GMapMarkerFill(byte [,] imageData, RectLatLng rect, PointLatLng currentloc)
            : base(currentloc)
        {
            this.rect = rect;

            IsHitTestVisible = false;

            //create a new Bitmap
            Bitmap bmp = new Bitmap(imageData.GetLength(0), imageData.GetLength(1), PixelFormat.Format32bppArgb);

            //lock it to get the BitmapData Object
            BitmapData bmData =
                bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            //now we have to convert the 2 dimensional array into a one dimensional byte-array for use with 8bpp bitmaps
            // use stride and height to prevent stride mod 4 issues
            int[] pixels = new int[(bmData.Stride / 4) * bmData.Height];
            for (int y = 0; y < imageData.GetLength(1); y++)
            {
                for (int x = 0; x < imageData.GetLength(0); x++)
                {
                    pixels[(y * (bmData.Stride / 4) + x)] = ConvertColor(imageData[x, y]);
                }
            }

            //copy the bytes
            System.Runtime.InteropServices.Marshal.Copy(pixels, 0, bmData.Scan0, (bmData.Stride / 4) * bmData.Height);

            //never forget to unlock the bitmap
            bmp.UnlockBits(bmData);

            bmp.MakeTransparent();

            //display
            elevation = bmp;
        }
Beispiel #28
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 = 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;
                            using (var tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex))
                            {
                                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;
                                        {
                                            try
                                            {
                                                tile.Data.Position = 0;
                                                gfx.DrawImage(Image.FromStream(tile.Data), x, y, prj.TileSize.Width,
                                                              prj.TileSize.Height);
                                            } catch (Exception ex2) {  }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                return(bmpDestination);
            }
        }
        private void LoadStreets()
        {
            RemoveStreets();

            string strFilename = $"{Tool.StartupPath}\\streets_bw.sqlite";

            RectLatLng bb = this.mcMapControl.ViewArea;

            //TODO: Check if the area is not to big ... But what is big ?

            SQLiteConnectionStringBuilder csbDatabase = new SQLiteConnectionStringBuilder
            {
                DataSource = strFilename
            };

            using (SQLiteConnection dbConnection = new SQLiteConnection(csbDatabase.ConnectionString))
            {
                dbConnection.Open();

                try
                {
                    //                                     0     1   2   3
                    //const string strSelectStatement = "select highway,ref,name,way from streets_bw where highway in ('motorway','motorway_link','trunk','trunk_link','primary','secondary','primary_link','secondary_link','residential')";
                    const string strSelectStatement = "select highway,ref,name,way from streets_bw";

                    uint iCounter = 0;

                    DateTime dtStart = DateTime.Now;

                    using (SQLiteCommand dbSelectCommand = new SQLiteCommand(strSelectStatement, dbConnection))
                    {
                        using (SQLiteDataReader dbResult = dbSelectCommand.ExecuteReader())
                        {
                            while (dbResult.Read())
                            {
                                Highway type = Highway.Unknown;

                                try
                                {
                                    type = (Highway)Enum.Parse(typeof(Highway), dbResult.GetString(0), true);
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine(ex.Message);
                                }

                                string strRef  = dbResult.GetStringOrNull(1);
                                string strName = dbResult.GetStringOrNull(2);

                                LineString way = (LineString)dbResult.GetGeometryFromWKB(3);

                                if (bb.Contains(way.Coordinate.ToPointLatLng()))
                                {
                                    List <PointLatLng> list = new List <PointLatLng>(way.Count);

                                    list.AddRange(way.Coordinates.Select(pos => pos.ToPointLatLng()));

                                    this.Dispatcher.Invoke(() =>
                                    {
                                        PathMarker mrWay = new PathMarker(this.mcMapControl, list, type, $"{( strName.IsNotEmpty() ? strName : "Unknown" )}{( strRef.IsNotEmpty() ? $" ({strRef})" : "" )}")
                                        {
                                            Tag = type
                                        };

                                        this.mcMapControl.Markers.Add(mrWay);
                                    });

                                    iCounter++;
                                }
                            }
                        }
                    }

                    DateTime dtStop = DateTime.Now;

                    MB.Information("Load {0} Ways In {1}.", iCounter, (dtStop - dtStart).ToHHMMSSString());
                }
                catch (Exception ex)
                {
                    MB.Error(ex);
                }
                finally
                {
                    if (dbConnection.State == ConnectionState.Open)
                    {
                        dbConnection.Close();
                    }
                }
            }
        }
      /// <summary>
      /// gets max zoom level to fit rectangle
      /// </summary>
      /// <param name="rect"></param>
      /// <returns></returns>
      public int GetMaxZoomToFitRect(RectLatLng rect)
      {
         int zoom = minZoom;

         if(rect.HeightLat == 0 || rect.WidthLng == 0)
         {
            zoom = maxZoom / 2;
         }
         else
         {
            for(int i = (int)zoom; i <= maxZoom; i++)
            {
               GPoint p1 = Provider.Projection.FromLatLngToPixel(rect.LocationTopLeft, i);
               GPoint p2 = Provider.Projection.FromLatLngToPixel(rect.LocationRightBottom, i);

               if(((p2.X - p1.X) <= Width + 10) && (p2.Y - p1.Y) <= Height + 10)
               {
                  zoom = i;
               }
               else
               {
                  break;
               }
            }
         }

         return zoom;
      }
      /// <summary>
      /// sets zoom to max to fit rect
      /// </summary>
      /// <param name="rect"></param>
      /// <returns></returns>
      public bool SetZoomToFitRect(RectLatLng rect)
      {
         int mmaxZoom = GetMaxZoomToFitRect(rect);
         if(mmaxZoom > 0)
         {
            PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2));
            Position = center;

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

            if(Zoom != mmaxZoom)
            {
               Zoom = (int)mmaxZoom;
            }

            return true;
         }
         return false;
      }
Beispiel #32
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;
        }
Beispiel #33
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            DateTime start = DateTime.Now;

            if (this.DesignMode)
            {
                return;
            }

            if (area.LocationMiddle.Lat == 0 && area.LocationMiddle.Lng == 0)
            {
                return;
            }

            try
            {
                base.OnPaint(e);
            }
            catch
            {
                return;
            }

            utmzone = center.GetUTMZone();

            double heightscale = 1;//(step/90.0)*5;

            var campos = convertCoords(center);

            cameraX = campos[0];
            cameraY = campos[1];
            cameraZ = (campos[2] < srtm.getAltitude(center.Lat, center.Lng).alt)
                ? (srtm.getAltitude(center.Lat, center.Lng).alt + 1) * heightscale
                : center.Alt * heightscale; // (srtm.getAltitude(lookZ, lookX, 20) + 100) * heighscale;

            lookX = campos[0] + Math.Sin(MathHelper.Radians(rpy.Z)) * 100;
            lookY = campos[1] + Math.Cos(MathHelper.Radians(rpy.Z)) * 100;
            lookZ = cameraZ;

            var size = 20000;

            // in front
            PointLatLngAlt front = center.newpos(rpy.Z, size);
            // behind
            PointLatLngAlt behind = center.newpos(rpy.Z, -50);
            // left : 90 allows for 180 degree viewing angle
            PointLatLngAlt left = center.newpos(rpy.Z - 45, size);
            // right
            PointLatLngAlt right = center.newpos(rpy.Z + 45, size);

            double maxlat = Math.Max(left.Lat, Math.Max(right.Lat, Math.Max(front.Lat, behind.Lat)));
            double minlat = Math.Min(left.Lat, Math.Min(right.Lat, Math.Min(front.Lat, behind.Lat)));

            double maxlng = Math.Max(left.Lng, Math.Max(right.Lng, Math.Max(front.Lng, behind.Lng)));
            double minlng = Math.Min(left.Lng, Math.Min(right.Lng, Math.Min(front.Lng, behind.Lng)));

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

            zoom = 20;


            float screenscale = 1;//this.Width/(float) this.Height*1f;

            //if(!Context.IsCurrent)
            MakeCurrent();

            GL.MatrixMode(MatrixMode.Projection);

            OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView((float)(90 * MathHelper.deg2rad), screenscale, 0.00000001f,
                                                                                    (float)20000);
            GL.LoadMatrix(ref projection);

            Console.WriteLine("cam: {0} {1} {2} lookat: {3} {4} {5}", (float)cameraX, (float)cameraY, (float)cameraZ,
                              (float)lookX,
                              (float)lookY, (float)lookZ);

            Matrix4 modelview = Matrix4.LookAt((float)cameraX, (float)cameraY, (float)cameraZ + 100f * 0, (float)lookX,
                                               (float)lookY, (float)lookZ, 0, 0, 1);

            GL.MatrixMode(MatrixMode.Modelview);

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

            GL.LoadMatrix(ref modelview);

            GL.ClearColor(Color.CornflowerBlue);

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

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

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

            GL.Fog(FogParameter.FogColor, new float[] { 100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 1f });
            //GL.Fog(FogParameter.FogDensity,0.1f);
            GL.Fog(FogParameter.FogMode, (int)FogMode.Linear);
            GL.Fog(FogParameter.FogStart, (float)4000);
            GL.Fog(FogParameter.FogEnd, (float)size);

            GL.Disable(EnableCap.DepthTest);
            GL.DepthFunc(DepthFunction.Always);

            /*
             * GL.Begin(BeginMode.LineStrip);
             *
             * GL.Color3(Color.White);
             * GL.Vertex3(0, 0, 0);
             *
             * GL.Color3(Color.Red);
             * GL.Vertex3(area.Bottom, 0, area.Left);
             *
             * GL.Color3(Color.Yellow);
             * GL.Vertex3(lookX, lookY, lookZ);
             *
             * GL.Color3(Color.Green);
             * GL.Vertex3(cameraX, cameraY, cameraZ);
             *
             * GL.End();
             */
            /*
             * GL.PointSize(10);
             * GL.Color4(Color.Yellow);
             * GL.LineWidth(5);
             *
             *
             * GL.Begin(PrimitiveType.LineStrip);
             *
             * GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, (float)cameraZ);
             * GL.Vertex3(area.LocationTopLeft.Lng, area.LocationRightBottom.Lat, (float)cameraZ);
             * GL.Vertex3(area.LocationRightBottom.Lng, area.LocationRightBottom.Lat, (float)cameraZ);
             * GL.Vertex3(area.LocationRightBottom.Lng, area.LocationTopLeft.Lat, (float)cameraZ);
             * GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, (float)cameraZ);
             *
             * GL.End();
             *
             * GL.PointSize((float) (step*1));
             * GL.Color3(Color.Blue);
             * GL.Begin(PrimitiveType.Points);
             * GL.Vertex3(new Vector3((float) center.Lng, (float) center.Lat, (float) cameraZ));
             * GL.End();
             */

            //GL.ClampColor(ClampColorTarget.ClampReadColor, ClampColorMode.True);

            /*
             * GL.Enable(EnableCap.Blend);
             * GL.DepthMask(false);
             * GL.BlendFunc(BlendingFactorSrc.Zero, BlendingFactorDest.Src1Color);
             * GL.DepthMask(true);
             * GL.Disable(EnableCap.Blend);
             */
            // textureid.Clear();

            core.fillEmptyTiles = true;

            core.LevelsKeepInMemmory = 20;

            core.Provider = type;
            core.Position = center;

            //core.ReloadMap();

            List <tileZoomArea> tileArea = new List <tileZoomArea>();

            for (int a = 10; a <= zoom; a++)
            {
                core.Zoom = a;

                var area2 = new RectLatLng(center.Lat, center.Lng, 0, 0);

                // 200m at max zoom
                // step at 0 zoom
                var distm = MathHelper.map(a, 0, zoom, size, 50);

                var offset = center.newpos(rpy.Z, distm);

                area2.Inflate(Math.Abs(center.Lat - offset.Lat), Math.Abs(center.Lng - offset.Lng));

                var extratile = 0;

                if (a == zoom)
                {
                    extratile = 1;
                }

                var tiles = new tileZoomArea()
                {
                    zoom = a, points = prj.GetAreaTileList(area2, a, extratile), area = area2
                };

                tileArea.Add(tiles);
            }

            //tileArea.Reverse();

            while (textureid.Count > 250)
            {
                var first = textureid.Keys.First();
                GL.DeleteTexture(textureid[first]);
                textureid.Remove(first);
            }

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

                        if (t.NotEmpty)
                        {
                            foreach (GMapImage img in t.Overlays)
                            {
                                if (img.IsParent)
                                {
                                }

                                if (!textureid.ContainsKey(p))
                                {
                                    try
                                    {
                                        generateTexture(p, (Bitmap)img.Img);
                                    }
                                    catch
                                    {
                                        continue;
                                    }
                                }
                            }
                        }
                        else
                        {
                        }
                    }
                    finally
                    {
                        core.Matrix.LeaveReadLock();
                        core.tileDrawingListLock.ReleaseReaderLock();
                    }

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

                        GL.Enable(EnableCap.Texture2D);
                        GL.BindTexture(TextureTarget.Texture2D, texture);
                    }
                    else
                    {
                        //Console.WriteLine("Missing tile");
                        GL.Disable(EnableCap.Texture2D);
                        continue;
                    }

                    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;

                    GL.LineWidth(4);
                    GL.Color3(Color.White);

                    GL.Clear(ClearBufferMask.DepthBufferBit);

                    GL.Enable(EnableCap.DepthTest);

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

                    GL.PointSize((float)(20));

                    //GL.Begin(PrimitiveType.Points);
                    GL.Color3(Color.Blue);

                    var latlng = prj.FromPixelToLatLng(xr, yr, tilearea.zoom);
                    var utm    = convertCoords(latlng);
                    utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                    GL.TexCoord2(0, 0);
                    GL.Vertex3(utm[0], utm[1], utm[2]);

                    // next down
                    latlng = prj.FromPixelToLatLng(xr, y2, tilearea.zoom);
                    utm    = convertCoords(latlng);
                    utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                    GL.TexCoord2(0, 1);
                    GL.Vertex3(utm[0], utm[1], utm[2]);

                    // next right
                    latlng = prj.FromPixelToLatLng(x2, yr, tilearea.zoom);
                    utm    = convertCoords(latlng);
                    utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                    GL.TexCoord2(1, 0);
                    GL.Vertex3(utm[0], utm[1], utm[2]);

                    // next right down
                    latlng = prj.FromPixelToLatLng(x2, y2, tilearea.zoom);
                    utm    = convertCoords(latlng);
                    utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                    GL.TexCoord2(1, 1);
                    GL.Vertex3(utm[0], utm[1], utm[2]);

                    GL.End();

                    var dist = LocationCenter.GetDistance(latlng);

                    var pxstep = 128;

                    if (dist < 500)
                    {
                        pxstep = 32;
                    }

                    double[] oldutm = null;
                    GL.Begin(PrimitiveType.TriangleStrip);
                    for (long x = xr; x < x2; x += pxstep)
                    {
                        long xnext = x + pxstep;
                        //GL.Begin(PrimitiveType.LineStrip);
                        for (long y = yr; y < y2; y += pxstep)
                        {
                            long ynext = y + pxstep;

                            //GL.Begin(PrimitiveType.Lines);
                            var latlng1 = prj.FromPixelToLatLng(x, y, tilearea.zoom);
                            var utm1    = convertCoords(latlng1);
                            utm1[2] = srtm.getAltitude(latlng1.Lat, latlng1.Lng).alt;

                            var imgx = MathHelper.map(x, xr, x2, 0, 1);
                            var imgy = MathHelper.map(y, yr, y2, 0, 1);

                            GL.TexCoord2(imgx, imgy);
                            GL.Vertex3(utm1[0], utm1[1], utm1[2]);

                            //
                            var latlng2 = prj.FromPixelToLatLng(x, ynext, tilearea.zoom);
                            var utm2    = convertCoords(latlng2);
                            utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt;

                            imgx = MathHelper.map(x, xr, x2, 0, 1);
                            imgy = MathHelper.map(ynext, yr, y2, 0, 1);

                            GL.TexCoord2(imgx, imgy);
                            GL.Vertex3(utm2[0], utm2[1], utm2[2]);

                            //
                            latlng2 = prj.FromPixelToLatLng(xnext, y, tilearea.zoom);
                            utm2    = convertCoords(latlng2);
                            utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt;

                            imgx = MathHelper.map(xnext, xr, x2, 0, 1);
                            imgy = MathHelper.map(y, yr, y2, 0, 1);

                            GL.TexCoord2(imgx, imgy);
                            GL.Vertex3(utm2[0], utm2[1], utm2[2]);

                            //
                            latlng2 = prj.FromPixelToLatLng(xnext, ynext, tilearea.zoom);
                            utm2    = convertCoords(latlng2);
                            utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt;

                            imgx = MathHelper.map(xnext, xr, x2, 0, 1);
                            imgy = MathHelper.map(ynext, yr, y2, 0, 1);

                            GL.TexCoord2(imgx, imgy);
                            GL.Vertex3(utm2[0], utm2[1], utm2[2]);
                        }
                    }

                    GL.End();
                    GL.Disable(EnableCap.Texture2D);
                }
            }

            GL.Flush();

            try
            {
                this.SwapBuffers();


                Context.MakeCurrent(null);
            }
            catch
            {
            }

            //this.Invalidate();

            var delta = DateTime.Now - start;

            Console.WriteLine("OpenGLTest2 {0}", delta.TotalMilliseconds);
        }
Beispiel #34
0
        public static void GetFlightRadarData(List <FlightRadarData> ret, RectLatLng bounds)
        {
            ret.Clear();

            //if(resetSession || string.IsNullOrEmpty(sessionId))
            //{
            //   sessionId = GetFlightRadarContentUsingHttp("http://www.flightradar24.com/", location, zoom, string.Empty);
            //}

            // get track for one object
            //var tm = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds;
            //var r = GetContentUsingHttp("http://www.flightradar24.com/FlightDataService.php?callsign=WZZ1MF&hex=47340F&date=" + tm, p1, 6, id);
            //Debug.WriteLine(r);

            //if(!string.IsNullOrEmpty(sessionId))
            {
                //var response = GetFlightRadarContentUsingHttp("http://arn.data.fr24.com/zones/fcgi/feed.js?bounds=63.056845879294244,55.95299968262111,5.99853515625,28.54248046875&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=900&gliders=1&stats=1&", location, zoom, sessionId);
                var response = GetFlightRadarContentUsingHttp(string.Format(CultureInfo.InvariantCulture, "http://arn.data.fr24.com/zones/fcgi/feed.js?bounds={0},{1},{2},{3}&faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&maxage=900&gliders=1&stats=1&", bounds.Top, bounds.Bottom, bounds.Left, bounds.Right));

                var items = response.Split(new string[] { "\n," }, StringSplitOptions.RemoveEmptyEntries);

                //int i = 0;
                foreach (var it in items)
                {
                    if (it.Length > 11 && !it.Contains("full_count") && !it.Contains("stats"))
                    {
                        var d = it.TrimEnd(']').Replace(":[", ",").Replace("\"", string.Empty);

                        //Debug.WriteLine(++i + " -> " + d);

                        // BAW576":["400803",48.9923,1.8083,"144","36950","462","0512","LFPO","A319","G-EUPC"
                        var par = d.Split(',');
                        if (par.Length >= 9)
                        {
                            var id       = Convert.ToInt32(par[0], 16);
                            var name     = par[8] + "|" + par[9] + "|" + par[10];
                            var lat      = par[2];
                            var lng      = par[3];
                            var bearing  = par[4];
                            var altitude = (int)(int.Parse(par[5]) * 0.3048) + "m";
                            var speed    = (int)(int.Parse(par[6]) * 1.852) + "km/h";

                            FlightRadarData fd = new FlightRadarData();
                            fd.name     = name;
                            fd.bearing  = int.Parse(bearing);
                            fd.altitude = altitude;
                            fd.speed    = speed;
                            fd.point    = new PointLatLng(double.Parse(lat, CultureInfo.InvariantCulture), double.Parse(lng, CultureInfo.InvariantCulture));
                            fd.Id       = id;

                            ret.Add(fd);

                            //Debug.WriteLine("name: " + name);
                            //Debug.WriteLine("hex: " + hex);
                            //Debug.WriteLine("point: " + fd.point);
                            //Debug.WriteLine("bearing: " + bearing);
                            //Debug.WriteLine("altitude: " + altitude);
                            //Debug.WriteLine("speed: " + speed);
                        }
                        else
                        {
#if DEBUG
                            if (Debugger.IsAttached)
                            {
                                Debugger.Break();
                            }
#endif
                        }
                        //Debug.WriteLine("--------------");
                    }
                }
            }
        }
Beispiel #35
0
 SpainMapProvider()
 {
     Copyright = string.Format("©{0} SIGPAC", DateTime.Today.Year);
     MinZoom   = 5;
     Area      = new RectLatLng(43.8741381814747, -9.700927734375, 14.34814453125, 7.8605775962932);
 }
 SpainMapProvider()
 {
    Copyright = string.Format("©{0} SIGPAC", DateTime.Today.Year);
    MinZoom = 1;
    Area = new RectLatLng(43.8741381814747, -9.700927734375, 14.34814453125, 7.8605775962932);
 }
Beispiel #37
0
        protected override void OnMouseMove(MouseEventArgs 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 - onMouseUpTimestamp < 55)
             {
            Debug.WriteLine("OnMouseMove skipped: " + (e.Timestamp - 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)
               {
                  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);
               {
                  PointLatLng p1 = selectionStart;
                  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);
            }
             }

             base.OnMouseMove(e);
        }
 GoogleKoreaMapProvider()
 {
    Area = new RectLatLng(38.6597777307125, 125.738525390625, 4.02099609375, 4.42072406219614);
 }
 TurkeyMapProvider()
 {
    Copyright = string.Format("©{0} Pergo - Map data ©{0} Fideltus Advanced Technology", DateTime.Today.Year);
    Area = new RectLatLng(42.5830078125, 25.48828125, 19.05029296875, 6.83349609375);
    InvertedAxisY = true;
 }
Beispiel #40
0
        /// <summary>
        /// gets max zoom level to fit rectangle
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public int GetMaxZoomToFitRect(RectLatLng rect)
        {
            int zoom = minZoom;

            for (int i = zoom; i <= maxZoom; i++)
            {
                Point p1 = Projection.FromLatLngToPixel(rect.LocationTopLeft, i);
                Point p2 = Projection.FromLatLngToPixel(rect.LocationRightBottom, i);

                if (((p2.X - p1.X) <= Width + 10) && (p2.Y - p1.Y) <= Height + 10)
                {
                    zoom = i;
                }
                else
                {
                    break;
                }
            }

            return zoom;
        }
 public CzechMapProviderBase()
 {
    RefererUrl = "http://www.mapy.cz/";
    Area = new RectLatLng(51.2024819920053, 11.8401353319027, 7.22833716731277, 2.78312271922872);
 }
Beispiel #42
-1
        public static void ProcessFile(string logfile)
        {
            if (File.Exists(logfile + ".jpg"))
            {
                return;
            }

            double minx = 99999;
            double maxx = -99999;
            double miny = 99999;
            double maxy = -99999;

            bool sitl = false;

            Dictionary <int, List <PointLatLngAlt> > loc_list = new Dictionary <int, List <PointLatLngAlt> >();

            try
            {
                if (logfile.ToLower().EndsWith(".tlog"))
                {
                    Comms.CommsFile cf = new CommsFile();
                    cf.Open(logfile);

                    using (CommsStream cs = new CommsStream(cf, cf.BytesToRead))
                    {
                        MAVLink.MavlinkParse parse = new MAVLink.MavlinkParse(true);

                        while (cs.Position < cs.Length)
                        {
                            try
                            {
                                MAVLink.MAVLinkMessage packet = parse.ReadPacket(cs);

                                if (packet == null || packet.Length < 5)
                                {
                                    continue;
                                }

                                if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIM_STATE ||
                                    packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIMSTATE)
                                {
                                    sitl = true;
                                }

                                if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT)
                                {
                                    var loc = packet.ToStructure <MAVLink.mavlink_global_position_int_t>();

                                    if (loc.lat == 0 || loc.lon == 0)
                                    {
                                        continue;
                                    }

                                    var id = packet.sysid * 256 + packet.compid;

                                    if (!loc_list.ContainsKey(id))
                                    {
                                        loc_list[id] = new List <PointLatLngAlt>();
                                    }

                                    loc_list[id].Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f));

                                    minx = Math.Min(minx, loc.lon / 10000000.0f);
                                    maxx = Math.Max(maxx, loc.lon / 10000000.0f);
                                    miny = Math.Min(miny, loc.lat / 10000000.0f);
                                    maxy = Math.Max(maxy, loc.lat / 10000000.0f);
                                }
                            }
                            catch { }
                        }
                    }
                    cf.Close();
                }
                else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log"))
                {
                    using (
                        DFLogBuffer colbuf =
                            new DFLogBuffer(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                        )
                    {
                        loc_list[0] = new List <PointLatLngAlt>();

                        foreach (var item in colbuf.GetEnumeratorType("GPS"))
                        {
                            if (item.msgtype.StartsWith("GPS"))
                            {
                                if (!colbuf.dflog.logformat.ContainsKey("GPS"))
                                {
                                    continue;
                                }

                                var status =
                                    double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Status")]);
                                var lat = double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Lat")]);
                                var lon = double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Lng")]);

                                if (lat == 0 || lon == 0 || status < 3)
                                {
                                    continue;
                                }

                                loc_list[0].Add(new PointLatLngAlt(lat, lon));

                                minx = Math.Min(minx, lon);
                                maxx = Math.Max(maxx, lon);
                                miny = Math.Min(miny, lat);
                                maxy = Math.Max(maxy, lat);
                            }
                        }
                    }
                }

                if (loc_list.Count > 0 && loc_list.First().Value.Count > 10)
                {
                    // add a bit of buffer
                    var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001);
                    using (var map = GetMap(area))
                        using (var grap = Graphics.FromImage(map))
                        {
                            if (sitl)
                            {
                                AddTextToMap(grap, "SITL");
                            }

                            Color[] colours =
                            {
                                Color.Red,    Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo,
                                Color.Violet, Color.Pink
                            };

                            int a = 0;
                            foreach (var locs in loc_list.Values)
                            {
                                PointF lastpoint = new PointF();
                                var    pen       = new Pen(colours[a % (colours.Length - 1)]);

                                foreach (var loc in locs)
                                {
                                    PointF newpoint = GetPixel(area, loc, map.Size);

                                    if (!lastpoint.IsEmpty)
                                    {
                                        grap.DrawLine(pen, lastpoint, newpoint);
                                    }

                                    lastpoint = newpoint;
                                }

                                a++;
                            }

                            map.Save(logfile + ".jpg", SKEncodedImageFormat.Jpeg);

                            File.SetLastWriteTime(logfile + ".jpg", new FileInfo(logfile).LastWriteTime);
                        }
                }
                else
                {
                    DoTextMap(logfile + ".jpg", "No gps data");

                    File.SetLastWriteTime(logfile + ".jpg", new FileInfo(logfile).LastWriteTime);
                }
            }
            catch (Exception ex)
            {
                if (ex.ToString().Contains("Mavlink 0.9"))
                {
                    DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9");
                }
            }
        }