コード例 #1
0
        private void SearchPlaceAndNearbys()
        {
            // Reset UI and clear existing before search again.
            ClearupPreviousSearchResult();

            searchPoint = GetSearchPoint();

            // osmReverseGeocoder only support 4326, we need convert point to 4326
            var projectedSearchPoint = (PointShape)projection.ConvertToInternalProjection(searchPoint);
            // Create the searchPreference by UI controls.
            SearchPreference searchPreference = GetSearchPreferenceFromUI();

            searchResult = osmReverseGeocoder.Search(projectedSearchPoint, searchPreference);
            if (searchResult != null)
            {
                // convert result to 3857
                foreach (var place in searchResult.Nearby)
                {
                    place.Geometry = projection.ConvertToExternalProjection(place.Geometry);
                    var point = projection.ConvertToExternalProjection(place.CenterLongitude, place.CenterLatitude);
                    place.CenterLongitude = point.X;
                    place.CenterLatitude  = point.Y;
                }

                // Update search result to map markers.
                DisplaySearchResult(searchResult);

                // Update search result to left panel list.
                tabSearchResult.SelectedIndex = 0;
                TabSearchResult_SelectionChanged(tabSearchResult, null);
            }
        }
コード例 #2
0
 private void ClearupPreviousSearchResult()
 {
     // Clear existing before doing search.
     searchResult                = null;
     lsbPlaces.ItemsSource       = null;
     lsbAddress.ItemsSource      = null;
     lsbIntersection.ItemsSource = null;
     serachedPlaces              = new Collection <Place>();
     serachedIntersetions        = new Collection <Place>();
     serachedAddress             = new Collection <Place>();
     bestmatchingMarkerOverlay.Markers.Clear();
 }
コード例 #3
0
        private void DisplaySearchResult(ReverseGeocoderResult searchResult)
        {
            if (searchResult != null && searchResult.BestMatch != null)
            {
                // Display address of the BestMatchingPlace in the left panel and add a marker.
                if (searchResult.BestMatch is Intersection)
                {
                    Intersection  intersection = (Intersection)searchResult.BestMatch;
                    string        roadInfos    = string.Empty;
                    List <string> roadNames    = intersection.Description.Split(',').ToList();
                    string        lastRoadName = roadNames[roadNames.Count - 1];
                    roadNames.RemoveAt(roadNames.Count - 1);

                    txtBestMatchingPlace.Text = string.Format("Intersection between {0} and {1} in {2}", string.Join(", ", roadNames), lastRoadName, intersection.Address);
                }
                else
                {
                    txtBestMatchingPlace.Text = searchResult.BestMatch.Address;
                }


                // the best mach disctance is samller than 200 meter. if not, it sholud be a larger area place
                var distance1 = searchResult.BestMatch.Geometry.GetDistanceTo(searchPoint, GeographyUnit.Meter, DistanceUnit.Meter);
                // The distance between SearchPoint and the center of BestMatch.
                PointShape bestMatchGeometry = searchResult.BestMatch.Geometry.GetCenterPoint();
                var        distance2         = bestMatchGeometry.GetDistanceTo(searchPoint, GeographyUnit.Meter, DistanceUnit.Meter);

                if (distance1 == 0)
                {
                    // BestMatch contains search point
                    if (distance2 > 210)
                    {
                        bestMatchGeometry = searchPoint;
                    }
                }

                Marker marker = CreateMarkerByCategory("BestMatchingPlace", bestMatchGeometry, searchResult.BestMatch.Address);
                bestmatchingMarkerOverlay.Markers.Add(marker);

                // Add index,distance and direction for addresses, places and intersections.
                int placeIndex        = 0;
                int intersectionIndex = 0;
                int addressIndex      = 0;

                foreach (Place place in searchResult.Nearby)
                {
                    if (place.PlaceCategory != PlaceCategories.Road)
                    {
                        if (place.PlaceCategory.ToString().Contains(PlaceCategories.AddressPoint.ToString()) || (string.IsNullOrEmpty(place.Name) && !string.IsNullOrEmpty(place.HouseNumber)))
                        {
                            serachedAddress.Add(place);
                            AddPropertiesForPlace(place, addressIndex);
                            addressIndex++;
                        }
                        else if (place.PlaceCategory.ToString().Contains(PlaceCategories.Intersection.ToString()))
                        {
                            serachedIntersetions.Add(place);
                            AddPropertiesForPlace(place, intersectionIndex);
                            intersectionIndex++;
                        }
                        else
                        {
                            serachedPlaces.Add(place);
                            AddPropertiesForPlace(place, placeIndex);
                            placeIndex++;
                        }
                    }
                }

                // Bind addresses,intersections,places to listbox.
                lsbAddress.ItemsSource      = serachedAddress;
                lsbPlaces.ItemsSource       = serachedPlaces;
                lsbIntersection.ItemsSource = serachedIntersetions;
            }
        }