Esempio n. 1
0
        public void ZoomToBounds()
        {
            CoordsRect rt = PlacesLoader.GetPointsFrame(fMapPoints);

            if (rt.MinLon == rt.MaxLon || rt.MinLat == rt.MaxLat)
            {
                return;
            }

            double centerLongtude = ((rt.MaxLon + rt.MinLon) / 2.0);
            double centerLatitude = ((rt.MaxLat + rt.MinLat) / 2.0);

            string script =
                "var point1 = new google.maps.LatLng({0}, {1});" +
                "var point2 = new google.maps.LatLng({2}, {3});" +
                "var bounds = new google.maps.LatLngBounds(point1, point2);" +
                "map.fitBounds(bounds);" +
                "map.setCenter(new google.maps.LatLng({4}, {5}));";

            script = string.Format(script, new object[]
                                   { PlacesLoader.CoordToStr(rt.MinLat), PlacesLoader.CoordToStr(rt.MinLon),
                                     PlacesLoader.CoordToStr(rt.MaxLat), PlacesLoader.CoordToStr(rt.MaxLon),
                                     PlacesLoader.CoordToStr(centerLatitude), PlacesLoader.CoordToStr(centerLongtude) });

            gm_ExecScript(script);
        }
Esempio n. 2
0
        public void Test_GetPointsFrame()
        {
            CoordsRect coordsRect = PlacesLoader.GetPointsFrame(null);

            Assert.AreEqual(0.0d, coordsRect.MinLon);
            Assert.AreEqual(0.0d, coordsRect.MinLat);
            Assert.AreEqual(0.0d, coordsRect.MaxLon);
            Assert.AreEqual(0.0d, coordsRect.MaxLat);

            ExtList <GeoPoint> mapPoints = new ExtList <GeoPoint>();

            mapPoints.Add(new GeoPoint(11, 13, "pt1"));
            mapPoints.Add(new GeoPoint(22, 25, "pt1"));
            coordsRect = PlacesLoader.GetPointsFrame(mapPoints);
            Assert.AreEqual(13.0d, coordsRect.MinLon);
            Assert.AreEqual(11.0d, coordsRect.MinLat);
            Assert.AreEqual(25.0d, coordsRect.MaxLon);
            Assert.AreEqual(22.0d, coordsRect.MaxLat);

            mapPoints.Clear();
            mapPoints.Add(new GeoPoint(21, 21, "pt1"));
            coordsRect = PlacesLoader.GetPointsFrame(mapPoints);
            Assert.AreEqual(1.0d, coordsRect.MinLon);
            Assert.AreEqual(1.0d, coordsRect.MinLat);
            Assert.AreEqual(41.0d, coordsRect.MaxLon);
            Assert.AreEqual(41.0d, coordsRect.MaxLat);
        }
Esempio n. 3
0
        public void VerifyPlacesLoaderGetGeoPlacesFromEmbeddedFile()
        {
            var places = PlacesLoader.GetGeoPlacesFromEmbeddedFile().OrderByDescending(gp => gp.Population).ToArray();

            Assert.AreEqual <string>("New York City", places.First().ShortName);
            Assert.AreEqual <string>("40.7--74.0", places.First().Location.ShortKey);
            Assert.AreEqual <string>("St Marys", places.Last().ShortName);
        }
        public override void UpdateView()
        {
            fView.Name.Text      = fLocationRecord.LocationName;
            fView.Latitude.Text  = PlacesLoader.CoordToStr(fLocationRecord.Map.Lati);
            fView.Longitude.Text = PlacesLoader.CoordToStr(fLocationRecord.Map.Long);

            fView.NotesList.ListModel.DataOwner = fLocationRecord;
            fView.MediaList.ListModel.DataOwner = fLocationRecord;
        }
Esempio n. 5
0
        public void SelectPlaces()
        {
            GDMIndividualRecord ind = null;

            bool condBirth     = false;
            bool condDeath     = false;
            bool condResidence = false;

            if (fView.TotalRadio.Checked)
            {
                condBirth     = fView.BirthCheck.Checked;
                condDeath     = fView.DeathCheck.Checked;
                condResidence = fView.ResidenceCheck.Checked;
            }
            else if (fView.SelectedRadio.Checked && (fView.PersonsCombo.SelectedIndex >= 0))
            {
                ind = (fView.PersonsCombo.GetSelectedTag <GDMIndividualRecord>());
            }

            fView.MapBrowser.ShowLines = (ind != null && fView.LinesVisibleCheck.Checked);
            fMapPoints.Clear();

            int num = fPlaces.Count;

            for (int i = 0; i < num; i++)
            {
                MapPlace place = fPlaces[i];
                if (place.Points.Count < 1)
                {
                    continue;
                }

                int num2 = place.PlaceRefs.Count;
                for (int j = 0; j < num2; j++)
                {
                    var            placeRef       = place.PlaceRefs[j];
                    GDMCustomEvent evt            = placeRef.Event;
                    var            evtType        = evt.GetTagType();
                    bool           checkEventType = (condBirth && evtType == GEDCOMTagType.BIRT) ||
                                                    (condDeath && evtType == GEDCOMTagType.DEAT) || (condResidence && evtType == GEDCOMTagType.RESI);

                    if ((ind != null && (placeRef.Owner == ind)) || checkEventType)
                    {
                        PlacesLoader.AddPoint(fMapPoints, place.Points[0], placeRef);
                    }
                }
            }

            if (ind != null)
            {
                // sort points by date
                fMapPoints.QuickSort(MapPointsCompare);
            }

            PlacesLoader.CopyPoints(fView.MapBrowser, fMapPoints, ind != null);
        }
Esempio n. 6
0
        public void Test_AddPoint()
        {
            var gmapPoints = new ExtList <GeoPoint>();

            PlacesLoader.AddPoint(gmapPoints, new GeoPoint(0, 0, "test"), new PlaceRef(null, null));
            Assert.AreEqual(1, gmapPoints.Count);

            PlacesLoader.AddPoint(gmapPoints, new GeoPoint(0, 0, "test"), new PlaceRef(null, null));
            Assert.AreEqual(1, gmapPoints.Count); // duplicate will be excluded
        }
Esempio n. 7
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            GKListItem item = ListGeoCoords.GetSelectedItem();

            if (item != null)
            {
                GeoPoint pt = (GeoPoint)item.Data;
                txtLatitude.Text  = PlacesLoader.CoordToStr(pt.Latitude);
                txtLongitude.Text = PlacesLoader.CoordToStr(pt.Longitude);
            }
        }
Esempio n. 8
0
        public void Test_CopyPoints()
        {
            var mapBrowser = Substitute.For <IMapBrowser>();

            Assert.Throws(typeof(ArgumentNullException), () => { PlacesLoader.CopyPoints(mapBrowser, null, true); });

            var gmapPoints = new ExtList <GeoPoint>();

            gmapPoints.Add(new GeoPoint(0, 0, "test"));
            PlacesLoader.CopyPoints(mapBrowser, gmapPoints, true);
        }
        public void SelectCoords()
        {
            GeoPoint pt = GetSelectedGeoPoint();

            if (pt == null)
            {
                return;
            }

            fView.Latitude.Text  = PlacesLoader.CoordToStr(pt.Latitude);
            fView.Longitude.Text = PlacesLoader.CoordToStr(pt.Longitude);
        }
Esempio n. 10
0
        private void SetLocationRecord(GEDCOMLocationRecord value)
        {
            fLocationRecord   = value;
            txtName.Text      = fLocationRecord.LocationName;
            txtLatitude.Text  = PlacesLoader.CoordToStr(fLocationRecord.Map.Lati);
            txtLongitude.Text = PlacesLoader.CoordToStr(fLocationRecord.Map.Long);

            fNotesList.ListModel.DataOwner = fLocationRecord;
            fMediaList.ListModel.DataOwner = fLocationRecord;

            txtName.Focus();
        }
Esempio n. 11
0
        private void btnSelectPlaces_Click(object sender, EventArgs e)
        {
            GEDCOMIndividualRecord ind = null;

            bool condBirth     = false;
            bool condDeath     = false;
            bool condResidence = false;

            if (radTotal.Checked)
            {
                condBirth     = chkBirth.Checked.GetValueOrDefault();
                condDeath     = chkDeath.Checked.GetValueOrDefault();
                condResidence = chkResidence.Checked.GetValueOrDefault();
            }
            else if (radSelected.Checked && (cmbPersons.SelectedIndex >= 0))
            {
                GKComboItem item = (GKComboItem)cmbPersons.Items[cmbPersons.SelectedIndex];
                ind = (item.Tag as GEDCOMIndividualRecord);
            }

            fMapBrowser.ShowLines = (ind != null && chkLinesVisible.Checked.GetValueOrDefault());
            fMapPoints.Clear();

            int num = fPlaces.Count;

            for (int i = 0; i < num; i++)
            {
                MapPlace place = fPlaces[i];
                if (place.Points.Count < 1)
                {
                    continue;
                }

                int num2 = place.PlaceRefs.Count;
                for (int j = 0; j < num2; j++)
                {
                    GEDCOMCustomEvent evt = place.PlaceRefs[j].Event;

                    if ((ind != null && (evt.Parent == ind)) || (condBirth && evt.Name == "BIRT") || (condDeath && evt.Name == "DEAT") || (condResidence && evt.Name == "RESI"))
                    {
                        PlacesLoader.AddPoint(fMapPoints, place.Points[0], place.PlaceRefs[j]);
                    }
                }
            }

            if (ind != null)
            {
                // sort points by date
                fMapPoints.QuickSort(MapPointsCompare);
            }

            PlacesLoader.CopyPoints(fMapBrowser, fMapPoints, ind != null);
        }
Esempio n. 12
0
        public void SelectPlaces()
        {
            GEDCOMIndividualRecord ind = null;

            bool condBirth     = false;
            bool condDeath     = false;
            bool condResidence = false;

            if (fView.TotalRadio.Checked)
            {
                condBirth     = fView.BirthCheck.Checked;
                condDeath     = fView.DeathCheck.Checked;
                condResidence = fView.ResidenceCheck.Checked;
            }
            else if (fView.SelectedRadio.Checked && (fView.PersonsCombo.SelectedIndex >= 0))
            {
                ind = (fView.PersonsCombo.SelectedTag as GEDCOMIndividualRecord);
            }

            fView.MapBrowser.ShowLines = (ind != null && fView.LinesVisibleCheck.Checked);
            fMapPoints.Clear();

            int num = fPlaces.Count;

            for (int i = 0; i < num; i++)
            {
                MapPlace place = fPlaces[i];
                if (place.Points.Count < 1)
                {
                    continue;
                }

                int num2 = place.PlaceRefs.Count;
                for (int j = 0; j < num2; j++)
                {
                    GEDCOMCustomEvent evt = place.PlaceRefs[j].Event;

                    if ((ind != null && (evt.Parent == ind)) || (condBirth && evt.Name == "BIRT") || (condDeath && evt.Name == "DEAT") || (condResidence && evt.Name == "RESI"))
                    {
                        PlacesLoader.AddPoint(fMapPoints, place.Points[0], place.PlaceRefs[j]);
                    }
                }
            }

            if (ind != null)
            {
                // sort points by date
                fMapPoints.QuickSort(MapPointsCompare);
            }

            PlacesLoader.CopyPoints(fView.MapBrowser, fMapPoints, ind != null);
        }
Esempio n. 13
0
        public void RefreshPoints()
        {
            gm_ClearPoints();
            if (fMapPoints.Count <= 0)
            {
                return;
            }

            string pointsScript   = "";
            string polylineScript = "";

            int num = fMapPoints.Count;

            for (int i = 0; i < num; i++)
            {
                GeoPoint pt = fMapPoints[i];
                pointsScript += string.Format("addMarker({0}, {1}, \"{2}\");", new object[]
                                              { PlacesLoader.CoordToStr(pt.Latitude), PlacesLoader.CoordToStr(pt.Longitude), pt.Hint });

                /*polylineScript = string.Concat(new string[]
                 *                                 {
                 *                                     polylineScript, "new google.maps.LatLng(",
                 *                                     CoordToStr(pt.Latitude), ",", CoordToStr(pt.Longitude), "),"
                 *                                 });*/

                polylineScript = string.Concat(new string[]
                {
                    polylineScript,
                    "{lat:", PlacesLoader.CoordToStr(pt.Latitude), ",lng:", PlacesLoader.CoordToStr(pt.Longitude), "},"
                });
            }

            if (ShowPoints)
            {
                gm_ExecScript(pointsScript);
            }

            if (ShowLines)
            {
                if (!string.IsNullOrEmpty(polylineScript))
                {
                    polylineScript = polylineScript.Remove(polylineScript.Length - 1, 1);
                }

                polylineScript =
                    "var polyline = new google.maps.Polyline({path: [" + polylineScript + "],strokeColor: '#FF0000', strokeWeight: 3}); " +
                    "polyline.setMap(map);" /*+
                                             * "markersArray.push(polyline);"*/;
                gm_ExecScript(polylineScript);
            }
        }
Esempio n. 14
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string location = txtName.Text.Trim();

            if (string.IsNullOrEmpty(location))
            {
                return;
            }

            ListGeoCoords.BeginUpdate();
            fMapBrowser.BeginUpdate();
            try
            {
                IList <GeoPoint> searchPoints = new List <GeoPoint>();

                AppHost.Instance.RequestGeoCoords(location, searchPoints);
                ListGeoCoords.Items.Clear();
                fMapBrowser.ClearPoints();

                int num = searchPoints.Count;
                for (int i = 0; i < num; i++)
                {
                    GeoPoint pt = searchPoints[i];

                    GKListItem item = new GKListItem(pt.Hint, pt);
                    item.AddSubItem(PlacesLoader.CoordToStr(pt.Latitude));
                    item.AddSubItem(PlacesLoader.CoordToStr(pt.Longitude));
                    ListGeoCoords.Items.Add(item);

                    fMapBrowser.AddPoint(pt.Latitude, pt.Longitude, pt.Hint);

                    if (i == 0)
                    {
                        fMapBrowser.SetCenter(pt.Latitude, pt.Longitude, -1);
                    }
                }

                //this.fMapBrowser.ZoomToBounds();
            }
            finally
            {
                fMapBrowser.EndUpdate();
                ListGeoCoords.EndUpdate();
            }
        }
Esempio n. 15
0
        public void VerifyCitiesTableRecords()
        {
            var places = PlacesLoader.GetGeoPlacesFromEmbeddedFile();

            List <GeoPlace> allGeo = new List <GeoPlace>();

            using (var conn = new NpgsqlConnection(PlacesLoader.PGConnection))
            {
                conn.Open();

                string selectQuery = "SELECT id,shortname,name,lat,lng,population FROM cities order by name asc";

                using (NpgsqlCommand command = new NpgsqlCommand(selectQuery, conn))
                {
                    var dr = command.ExecuteReader();

                    while (dr.Read())
                    {
                        GeoPlace place = new GeoPlace();
                        place.ID        = dr.GetString(0);
                        place.ShortName = dr.GetString(1);
                        place.Name      = dr.GetString(2);

                        place.Location     = new Location();
                        place.Location.Lat = dr.GetDouble(3);
                        place.Location.Lon = dr.GetDouble(4);
                        place.Population   = dr.GetInt64(5);

                        allGeo.Add(place);
                    }
                }
            }

            foreach (var place in places)
            {
                var exists = allGeo.Where(x => x.ID == place.ID).Any();

                Assert.AreEqual <bool>(true, exists);
            }
        }
        public void Search()
        {
            string location = fView.Name.Text.Trim();

            if (string.IsNullOrEmpty(location))
            {
                return;
            }

            fView.GeoCoordsList.BeginUpdate();
            fView.MapBrowser.BeginUpdate();
            try {
                var searchPoints = new List <GeoPoint>();

                AppHost.Instance.RequestGeoCoords(location, searchPoints);
                fView.GeoCoordsList.ClearItems();
                fView.MapBrowser.ClearPoints();

                int num = searchPoints.Count;
                for (int i = 0; i < num; i++)
                {
                    GeoPoint pt = searchPoints[i];

                    fView.GeoCoordsList.AddItem(pt, pt.Hint,
                                                PlacesLoader.CoordToStr(pt.Latitude), PlacesLoader.CoordToStr(pt.Longitude));

                    fView.MapBrowser.AddPoint(pt.Latitude, pt.Longitude, pt.Hint);

                    if (i == 0)
                    {
                        fView.MapBrowser.SetCenter(pt.Latitude, pt.Longitude, -1);
                    }
                }
            } finally {
                fView.MapBrowser.EndUpdate();
                fView.GeoCoordsList.EndUpdate();
            }
        }
Esempio n. 17
0
        public void SetCenter(double latitude, double longitude, int scale)
        {
            string script;

            if (scale >= 0)
            {
                script = string.Concat(new string[] {
                    "var point = new google.maps.LatLng(",
                    PlacesLoader.CoordToStr(latitude), ",", PlacesLoader.CoordToStr(longitude), "); ",
                    "map.setCenter(point)",
                    "map.setZoom(", scale.ToString(), ")"
                });
            }
            else
            {
                script = string.Concat(new string[] {
                    "var point = new google.maps.LatLng(",
                    PlacesLoader.CoordToStr(latitude), ",", PlacesLoader.CoordToStr(longitude), "); ",
                    "map.setCenter(point)"
                });
            }

            gm_ExecScript(script);
        }
Esempio n. 18
0
        public void Test_CoordToStr()
        {
            string coord = PlacesLoader.CoordToStr(2.005216);

            Assert.AreEqual("2.005216", coord);
        }
Esempio n. 19
0
 public void VerifyTableCreationWithoutErrors()
 {
     PlacesLoader.CreateTable();
 }