Beispiel #1
0
        public void Add(GMapPolygon footprint)
        {
            // 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);
        }
        void GmapWidget_OnSelectionChange(RectLatLng Selection, bool ZoomToFit)
        {
            if (poligonSelection)
            {
                return;
            }
            var selected = addressesOverlay.Markers.Where(m => Selection.Contains(m.Position)).ToList();

            UpdateSelectedInfo(selected);
        }
        void ThreadUpDateBound()
        {
            while (true)
            {
                Thread.Sleep(1000);
                if (Control == null)
                {
                    continue;
                }
                if (Control.IsDragging)
                {
                    continue;
                }

                Control.Dispatcher.Invoke(new Action(() =>
                {
                    ShowList.Clear();
                    ShowListExpand.Clear();
                    AllList = Markers.ToList();
                }));


                RectLatLng ViewAreaExpand = new RectLatLng(Control.ViewArea.Top + Control.ViewArea.HeightLat,
                                                           Control.ViewArea.Left - Control.ViewArea.WidthLng, Control.ViewArea.WidthLng * 3, Control.ViewArea.HeightLat * 3);

                foreach (var item in AllList)
                {
                    if (ViewAreaExpand.Contains(item.Position.Lat, item.Position.Lng))
                    {
                        if (Control.ViewArea.Contains(item.Position.Lat, item.Position.Lng))
                        {
                            ShowList.Add(item);
                        }
                        ShowListExpand.Add(item);
                    }
                }
                Control.Dispatcher.Invoke(new Action(() =>
                {
                    if (Control.Zoom < MarkerShowRealZoomSize)
                    {
                        MarkerCanvas.Visibility  = System.Windows.Visibility.Collapsed;
                        PreViewCanvas.Visibility = System.Windows.Visibility.Visible;
                    }
                    else
                    {
                        MarkerCanvas.Visibility  = System.Windows.Visibility.Visible;
                        PreViewCanvas.Visibility = System.Windows.Visibility.Collapsed;
                    }
                }));
                UpdateBounds();
            }
        }
        /// <summary>
        /// 获取区域内图标
        /// </summary>
        void GetShowList()
        {
            ShowList.Clear();
            if (Control == null || Visibility != Visibility.Visible)
            {
                return;
            }

            try
            {
                if (Control.Zoom < MarkerShowZoomSize)
                {
                    PreViewCanvas.Visibility = System.Windows.Visibility.Collapsed;
                }
                else if (Control.Zoom < MarkerShowRealZoomSize)
                {
                    PreViewCanvas.Visibility = System.Windows.Visibility.Visible;
                }
                if (ShowMarkerReal == null)
                {
                    return;
                }

                lock (Markers)
                    AllList = Markers.ToList();

                RectLatLng ViewAreaExpand = new RectLatLng(Control.ViewArea.Top + Control.ViewArea.HeightLat / 2,
                                                           Control.ViewArea.Left - Control.ViewArea.WidthLng / 2, Control.ViewArea.WidthLng * 2, Control.ViewArea.HeightLat * 2);

                foreach (var item in AllList)
                {
                    if (item != null)
                    {
                        if (ViewAreaExpand.Contains(item.Position.Lat, item.Position.Lng))
                        {
                            ShowList.Add(item);
                        }
                    }
                }
            }
            catch
            {
            }
        }
        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();
                    }
                }
            }
        }
 public bool Contains(PointLatLng location) => _rect.Contains(location) && Contains(_locations, location);