private bool CheckCoords(Location apiCoords, Tuple <double, double> wikiCoords)
        {
            var dx = Math.Abs(wikiCoords.Item1 - apiCoords.Latitude);
            var dy = Math.Abs(wikiCoords.Item2 - apiCoords.Longitude);

            return(dx / wikiCoords.Item1 <= epsilon && dy / wikiCoords.Item2 <= epsilon);
        }
        public Microsoft.Maps.MapControl.WPF.Location Center(List <Report> listOfReport)
        {
            double latitude_Min;
            double latitude_Max;
            double longitude_Min;
            double longitude_Max;
            double latitude_Center;
            double longitude_Center;

            Microsoft.Maps.MapControl.WPF.Location center_location = new Microsoft.Maps.MapControl.WPF.Location();

            if (listOfReport.Count == 0)
            {
                return(null);
            }
            latitude_Min              = listOfReport.Min(r => r.Latitude);
            latitude_Max              = listOfReport.Max(r => r.Latitude);
            longitude_Min             = listOfReport.Min(r => r.Longitude);
            longitude_Max             = listOfReport.Max(r => r.Longitude);
            latitude_Center           = (latitude_Min + latitude_Max) / 2;
            longitude_Center          = (longitude_Min + longitude_Max) / 2;
            center_location.Latitude  = latitude_Center;
            center_location.Longitude = longitude_Center;
            return(center_location);
        }
示例#3
0
        private void AddLocationAsync()
        {
            if (Events == null)
            {
                return;
            }

            foreach (var e in Events)
            {
                if (e.GeodanAdresX == null)
                {
                    e.GeodanAdresX = "51.690090";
                    e.GeodanAdresY = "5.303690";
                }

                var y = Convert.ToDouble(e.GeodanAdresY);
                var x = Convert.ToDouble(e.GeodanAdresX);

                if (y > 10000)
                {
                    y = Convert.ToDouble(e.GeodanAdresY, CultureInfo.InvariantCulture);
                    x = Convert.ToDouble(e.GeodanAdresX, CultureInfo.InvariantCulture);
                }
                Zoom            = 10;
                CurrentLocation = new Location(y, x);
                Locations.Add(CurrentLocation);
            }
        }
 private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
 {
     currentLocation  = new Microsoft.Maps.MapControl.WPF.Location(e.Position.Location.Latitude, e.Position.Location.Longitude);
     currentLongitude = e.Position.Location.Longitude.ToString();
     currentLatitude  = e.Position.Location.Latitude.ToString();
     RaisePropertyChanged("currentLongitude");
     RaisePropertyChanged("currentLatitude");
     RaisePropertyChanged("CurrentLocation");
 }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {

            var location = value as Models.Location;

            var mapLocation = new Microsoft.Maps.MapControl.WPF.Location(location.Latitude, location.Longitude);

            return mapLocation;
        }
示例#6
0
 // this function shows the route between two points in the map. The points are identified with entity type toLocation and fromLocation.
 // in case of no 'to' and 'from' location found, the next entity would be abstract location "here" and "there" based on which the route information would be shown
 // Parameters:
 //   luisJson:
 //       contains the intent and entity info from Luis.
 //  isContinuation:
 //      if true, this method is called as a continuation of previous route info request in case both from and to location info is not provided at one go.
 // (this is possible in case of abstract location "here", "there" instead of providing actual location like "berlin", "munich"
 private void ProcessRouteIntent(LUISJsonObject luisJson, bool isContinuation)
 {
     this.WriteLine("{0}", "------------------ProcessShowRouteIntent------------------:");
     if (!isContinuation)
     {
         this.Dispatcher.Invoke(() =>
         {
             clearMap();
         });
     }
     if (luisJson.Entities.Length > 0)
     {
         foreach (Entity entity in luisJson.Entities)
         {
             if (entity.Type.Contains(LuisEntityTypes.TOLOCATION))
             {
                 RouteParameters.INSTANCE.toLocation = entity.EntityValue;
                 Trace.WriteLine(entity.Type + " : " + RouteParameters.INSTANCE.toLocation);
             }
             else if (entity.Type.Contains(LuisEntityTypes.FROMLOCATION))
             {
                 RouteParameters.INSTANCE.fromLocation = entity.EntityValue;
                 Trace.WriteLine(entity.Type + " : " + RouteParameters.INSTANCE.fromLocation);
             }
             else if (entity.Type.Contains(LuisEntityTypes.ABSTRACTLOCATION))
             {
                 // abstract location points to a location on the screen. getLocationFromScreenPoint() gets the location where the kinect hand is pointing on the application.
                 Microsoft.Maps.MapControl.WPF.Location l = getLocationFromScreenPoint();
                 // the route information is
                 if (isContinuation)
                 {
                     RouteParameters.INSTANCE.toCLocation = new Coordinate(l.Latitude, l.Longitude);
                 }
                 else
                 {
                     RouteParameters.INSTANCE.fromCLocation = new Coordinate(l.Latitude, l.Longitude);
                 }
                 addPushpinToLocation(l.Latitude, l.Longitude);
             }
             else if (entity.Type.Contains(LuisEntityTypes.PLACE))
             {
                 if (isContinuation)
                 {
                     RouteParameters.INSTANCE.toLocation = entity.EntityValue;
                 }
                 else
                 {
                     RouteParameters.INSTANCE.fromLocation = entity.EntityValue;
                 }
             }
         }
         // shows the route info if all the necessary input is available
         showRoute();
     }
 }
 public PushPinControl(Microsoft.Maps.MapControl.WPF.Location pinLocation)
 {
     InitializeComponent();
     // TODO: Complete member initialization
     this.pinLocation = pinLocation;
     Push_Image_container.DataContext = "libraryContainer1";
     _Latitude= pinLocation.Latitude ;
        _longitude= pinLocation.Longitude ;
        Push_Image_container.ItemsSource = Names;
       // Loaded += new RoutedEventHandler(OnLoaded);
 }
示例#8
0
        private void getWeatherButton_Click(object sender, RoutedEventArgs e)
        {
            // clear search list
            searchCriteria.Clear();

            // add lat, long to search list
            searchCriteria.Add(Map.Center.Latitude.ToString());
            searchCriteria.Add(Map.Center.Longitude.ToString());

            // get new woeid
            set.updateWOEID(searchCriteria);

            // if no woeid could be found reset it to default
            if (set.WOEID.Equals(""))
            {
                // clear search term list
                searchCriteria.Clear();

                // read settings file to get default postcode
                set.readSettingsFile();

                // add postcode to search term list
                searchCriteria.Add(set.Postcode);

                // get default location
                set.updateWOEID(searchCriteria);

                // update xm
                xm.updateXmlDocument(set.WOEID);

                // update location
                loc.updateLocation(xm);

                // update day
                day.updateDay(xm);

                // update map location
                Microsoft.Maps.MapControl.WPF.Location l = new Microsoft.Maps.MapControl.WPF.Location(Convert.ToDouble(loc.Latitude), Convert.ToDouble(loc.Longitude));
                Map.SetView(l, 11);

                displayError("Could not retrieve location information. Returned to default location.");
                return;
            }

            // update xm
            xm.updateXmlDocument(set.WOEID);

            // update location
            loc.updateLocation(xm);

            // update day
            day.updateDay(xm);
        }
示例#9
0
        private void PinSelected(Event inspectionEvent)
        {
            var y = Convert.ToDouble(inspectionEvent.GeodanAdresY);
            var x = Convert.ToDouble(inspectionEvent.GeodanAdresX);

            if (y > 10000)
            {
                y = Convert.ToDouble(inspectionEvent.GeodanAdresY, CultureInfo.InvariantCulture);
                x = Convert.ToDouble(inspectionEvent.GeodanAdresX, CultureInfo.InvariantCulture);
            }

            CurrentLocation = new Location(y, x);
            Zoom            = 12;
        }
示例#10
0
        public DashboardViewModel(IEventRepository repository)
        {
            CurrentLocation = new Location(51.690090, 5.303690);
            Locations       = new ObservableCollection <Location>();

            SetPinsCommand = new RelayCommand <Event>(PinSelected);

            Task.Run(async() =>
            {
                Events = await repository.GetUpcommingEvents();
                RaisePropertyChanged("Events");
                AddLocationAsync();
            });
        }
示例#11
0
        private Microsoft.Maps.MapControl.WPF.Location location(string line)
        {
            Microsoft.Maps.MapControl.WPF.Location loc = new Microsoft.Maps.MapControl.WPF.Location();


            string[] split = line.Split(';');



            loc.Latitude  = Convert.ToDouble(split[1]);
            loc.Longitude = Convert.ToDouble(split[2]);


            return(loc);
        }
示例#12
0
        private void searchButton_Click(object sender, RoutedEventArgs e)
        {
            // add the search terms to a list
            searchCriteria.Clear();
            searchCriteria.Add(townSearchTextbox.Text);
            searchCriteria.Add(countySearchTextbox.Text);
            searchCriteria.Add(postcodeSearchTextbox.Text);

            // check if that there is at least one search term
            if (!isValidSearchCriteria())
            {
                displayError("Please provide one or more search criteria.");
                return;
            }

            // get new woeid based on the new search terms
            set.updateWOEID(searchCriteria);

            // check if a woeid was found
            if (set.WOEID.Length <= 0)
            {
                displayError("Could not retrieve WOEID, please try again.");
                return;
            }

            // update xm
            xm.updateXmlDocument(set.WOEID);

            // update location
            loc.updateLocation(xm);

            // update day
            day.updateDay(xm);

            // update map location
            Microsoft.Maps.MapControl.WPF.Location l = new Microsoft.Maps.MapControl.WPF.Location(Convert.ToDouble(loc.Latitude), Convert.ToDouble(loc.Longitude));
            Map.SetView(l, 11);
        }
示例#13
0
        /// <summary>
        /// Método para visualizar localização passada como parametro no construtor
        /// </summary>
        private void SetLocation()
        {
            //Instanciando objeto para recuperar as cordenadas
            IGeocoder geocoder = new BingMapsGeocoder(
                "AsHgFB0MOC02SgIYNbIwV9WOuo94eLp3brN5PvlD9Vu-p9DSjVUYfUZZIS5jfOeb"
                );
            IEnumerable <Address> results = geocoder.Geocode(this.location);

            //Recuperando primeiro endereco
            loc = new Microsoft.Maps.MapControl.WPF.Location();
            foreach (Address a in results)
            {
                loc = new Microsoft.Maps.MapControl.WPF.Location(
                    a.Coordinates.Latitude,
                    a.Coordinates.Longitude
                    );
                break;
            }

            //Visualizando coordenadas encontradas no mapa com zoom proprio
            bingMap.SetView(loc, zoom);    //Visualização em mapa
            bingMarker.Location = loc;     //Marcador de destino
        }
示例#14
0
        /// <summary>
        /// Método estatico para exportar pdf de mapas
        /// </summary>
        public static string ExportMapPdf(string location, Microsoft.Maps.MapControl.WPF.Location loc)
        {
            //Criando um novo documento com margem 40
            Document document = new Document(PageSize.A4);

            document.SetMargins(40, 40, 40, 40);
            document.AddCreationDate();

            //Definindo o caminho que será salvo o arquivo PDF
            string oldPath = Directory.GetCurrentDirectory();

            if (!Directory.Exists(mapsDirectoryPath))
            {
                Directory.CreateDirectory(mapsDirectoryPath);
            }
            Directory.SetCurrentDirectory(mapsDirectoryPath);

            //Configurando arquivo a ser salvo
            string path = Path.Combine(Directory.GetCurrentDirectory(), $"{DateTime.Now.ToString("ddMMyyyyhhmmss")}roadmap.pdf");

            //Criando arquivo em branco para testes
            PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));

            writer.CompressionLevel = PdfStream.NO_COMPRESSION;

            //Editando o documento
            document.Open();

            //Recuperando imagem do mapa
            string      mapURl = $"https://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{loc.Latitude.ToString().Replace(',', '.')},{loc.Longitude.ToString().Replace(',', '.')}/15?mapSize=700,700&pp={loc.Latitude.ToString().Replace(',', '.')},{loc.Longitude.ToString().Replace(',', '.')};21;Destino&key=AsHgFB0MOC02SgIYNbIwV9WOuo94eLp3brN5PvlD9Vu-p9DSjVUYfUZZIS5jfOeb";
            BitmapImage src    = new BitmapImage();
            Uri         uri    = new Uri(mapURl);

            src.BeginInit();
            src.UriSource = uri;
            src.EndInit();

            var width  = Convert.ToInt32(Math.Round(document.PageSize.Width - 40));
            var height = Convert.ToInt32(Math.Round(((float)src.Height / (float)src.Width) * (width)));

            //Adicionando conteudo
            Paragraph title = new Paragraph("Visualização em Mapa", new Font(Font.NORMAL, 20));

            title.Alignment = Element.ALIGN_CENTER;
            Paragraph adress = new Paragraph($"\n{location}\n\n", new Font(Font.NORMAL, 14));

            adress.Alignment = Element.ALIGN_CENTER;
            Paragraph footer = new Paragraph($"\n\n\nEmitido dia {DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss")} - ProERP", new Font(Font.NORMAL, 12));

            footer.Alignment = Element.ALIGN_CENTER;

            Image image = Image.GetInstance(uri);

            image.Alignment = Element.ALIGN_CENTER;
            image.SetDpi(600, 600);
            image.ScaleToFit(width, height);

            document.Add(title);
            document.Add(adress);
            document.Add(image);
            document.Add(footer);

            //Finalizando Edições
            document.Close();
            System.Diagnostics.Process.Start(path);

            //Sinalizando usuario sobre criação do arquivo e restaurando diretorio
            Directory.SetCurrentDirectory(oldPath);
            return($"Arquivo PDF do mapa salvo no diretorio {path}");
        }
示例#15
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // attempt to load data from .txt and .xml files
            try
            {
                // read settings from file
                set.readSettingsFile();

                // load saved postcode
                searchCriteria.Add(set.Postcode);

                // get woeid using saved postcode
                set.updateWOEID(searchCriteria);

                // check if a woeid was found
                if (set.WOEID.Length <= 0)
                {
                    // set a new valid postcode and save it to settings file
                    set.Postcode = "ip333rl";
                    set.writeSettingsFile();

                    // use this default woeid to load program
                    set.WOEID = "14714";

                    // notify user of invalid postcode
                    displayError("Invalid saved postcode, reverted to system default location. Settings updated.\nPlease set a valid postcode in settings.");
                }

                // instantiate the Xml access object to be used for retrieving weather data
                xm = new XmlAccessManager(set.WOEID);

                // load todays info from saved postcode
                day = new Day();
                day.updateDay(xm);

                // load location info from settings
                loc = new Location();
                loc.updateLocation(xm);

                // load reusable forecast UI component
                UserControlLibrary.ForecastControl fc = new UserControlLibrary.ForecastControl();
                rightStackPanel.Children.Add(fc);

                // set the data context for the various labels to display the correct data
                dayInfo.DataContext            = day.Weather;
                lastBuildDateLabel.DataContext = day;
                townLabel.DataContext          = loc;

                fc.Forecast1DC = day.Weather.ForecastList[0];
                fc.Forecast2DC = day.Weather.ForecastList[1];
                fc.Forecast3DC = day.Weather.ForecastList[2];
                fc.Forecast4DC = day.Weather.ForecastList[3];
                fc.Forecast5DC = day.Weather.ForecastList[4];



                // set default location of  map
                Microsoft.Maps.MapControl.WPF.Location l = new Microsoft.Maps.MapControl.WPF.Location(Convert.ToDouble(loc.Latitude), Convert.ToDouble(loc.Longitude));
                Map.SetView(l, 11);
            }

            catch (Exception ex)
            {
                // display any errors in the error window
                Error errorWindow = new Error();
                errorWindow.Show();
                errorWindow.errorMessage.Text = ex.Message + "\n" + ex.StackTrace;
            }
        }