示例#1
0
        private bool CriminalEventsToBingMap(out string result)
        {
            double longtitude;
            double latitude;

            result = string.Empty;

            try
            {
                if ((criminalEvents == null) || (criminalEvents.Count == 0))
                {
                    result = "אין אירועים להצגה";

                    return(false);
                }

                LocationService locationService = new LocationService(locationServiceInformation.LocationServiceUrl,
                                                                      locationServiceInformation.BingKey,
                                                                      locationServiceInformation.Country,
                                                                      locationServiceInformation.City);

                VectorItemsLayer vectorItemsLayer = new VectorItemsLayer();
                MapItemStorage   mapItemStorage   = new MapItemStorage();

                MapPushpin mapPushpin;

                foreach (CriminalEvent criminalEvent in criminalEvents)
                {
                    string houseNumber = (criminalEvent.HouseNumber != 0) ? criminalEvent.HouseNumber.ToString() : string.Empty;
                    string address     = $"{criminalEvent.Street} {houseNumber}";
                    address = address.Trim();

                    if (string.IsNullOrEmpty(address))
                    {
                        continue;
                    }

                    if (!locationService.AddressToLongtitudeLatitude($"{address}", out longtitude, out latitude, out result))
                    {
                        OnAudit($"לא נמצא מיקום ל: {address}", AuditSeverity.Warning);

                        continue;
                    }

                    mapPushpin = new MapPushpin()
                    {
                        Location = new GeoPoint(longtitude, latitude), Image = Properties.Resources.PushPin, ToolTipPattern = CriminalEventToolTip(criminalEvent)
                    };
                    mapItemStorage.Items.Add(mapPushpin);
                }

                vectorItemsLayer.Data = mapItemStorage;

                bingMap.Layers.Add(vectorItemsLayer);

                return(true);
            }
            catch (Exception e)
            {
                result = e.Message;

                return(false);
            }
        }