Exemple #1
0
        void RenderRoute()
        {
            layer.Children.Clear();

            Microsoft.Phone.Controls.Maps.MapPolyline line = new Microsoft.Phone.Controls.Maps.MapPolyline();
            line.Locations = new Microsoft.Phone.Controls.Maps.LocationCollection();

            double maxLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double minLat = DataContextManager.SelectedRoute.RoutePoints[0].Latitude;
            double maxLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;
            double minLon = DataContextManager.SelectedRoute.RoutePoints[0].Longitude;

            foreach (MobileSrc.Commuter.Shared.GpsLocation location in DataContextManager.SelectedRoute.RoutePoints)
            {
                line.Locations.Add(new System.Device.Location.GeoCoordinate(location.Latitude, location.Longitude, location.Altitude));

                maxLat = Math.Max(maxLat, location.Latitude);
                minLat = Math.Min(minLat, location.Latitude);
                maxLon = Math.Max(maxLon, location.Longitude);
                minLon = Math.Min(minLon, location.Longitude);
            }
            Microsoft.Phone.Controls.Maps.LocationRect rect = new Microsoft.Phone.Controls.Maps.LocationRect(maxLat, minLon, minLat, maxLon);

            line.Opacity         = 0.65;
            line.StrokeThickness = 5;
            line.Visibility      = System.Windows.Visibility.Visible;
            line.Stroke          = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Blue);
            layer.Children.Add(line);

            if (_setViewPort)
            {
                BingMap.SetView(rect);
            }
        }
 private void WaitForStopDownloadingComplete(Exception ex)
 {
     if (null != _finalRect)
     {
         BingMap.SetView(_finalRect);
     }
 }
Exemple #3
0
        public async System.Threading.Tasks.Task mapInitMisspellTestAsync()
        {
            await BingMap.mapInit("Dunde");

            String expected = BingMap.Answer;

            StringAssert.Contains("56.46126937866211 : -2.967600107192993", expected);
        }
Exemple #4
0
        private void MapOnDoubleClick(object sender, MapInputEventArgs args)
        {
            var currentCamera = BingMap.ActualCamera;

            _ = BingMap.TrySetSceneAsync(MapScene.CreateFromCamera(currentCamera));

            var geopoint = args.Location;

            AddMarker(geopoint);
            ReverseGeocodePoint(geopoint);
        }
Exemple #5
0
        public void HaversineDistanceTest()
        {
            BingMap m = new BingMap();
            //Dundee 56.46913, -2.97489
            //Glasgow 55.86515, -4.25763
            LatLng dundee  = new LatLng(56.46913, -2.97489);
            LatLng glasgow = new LatLng(55.86515, -4.25763);


            Assert.That(m.HaversineDistance(dundee, glasgow), Is.EqualTo(64).Within(5.0));
        }
Exemple #6
0
 private void buttonSearch_Click(object sender, EventArgs e)
 {
     if (comboSearchStation.SelectedItem != null)
     {
         string stationName = Convert.ToString(comboSearchStation.SelectedItem.ToString());
         ListCoordinatesInfo(stationName);
         BingMap.Zoom(15);
         BingMap.ZoomToFitLayerItems(BingMap.Layers.Where(l => l is VectorItemsLayer));
     }
     return;
 }
Exemple #7
0
        public void BingMapNoResults()
        {
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey);

            BingMap bing = new BingMap(bmc);

            IGeoCodeResult Target = new GeoCodeResult();

            Target = bing.GetCoordinates("alskdfjkaadsflasd");
            Assert.AreEqual(false, Target.HasValue);
            Assert.AreEqual(0, Target.Longitude);
        }
        private void ShowLocation(object sender, MouseEventArgs e)
        {
            var poi = LBTripPlan.SelectedItem as PointOfInterest;

            if (poi != null)
            {
                BingMap.SetView(new Microsoft.Maps.MapControl.WPF.Location()
                {
                    Latitude  = poi.Lat,
                    Longitude = poi.Long
                }, 16);
            }
        }
Exemple #9
0
        public void BingMapTest()
        {
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey);

            BingMap bing = new BingMap(bmc);

            var Expected = new {
                Latitude  = 30.267599105834961,
                Longitude = -97.74298095703125
            };
            IGeoCodeResult Target = new GeoCodeResult();

            Target = bing.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemple #10
0
        /// <summary>
        /// Occurs when the user taps on the map.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BingMap_Tap(object sender, GestureEventArgs e)
        {
            if (_pin == null)
            {
                // Drop a pushpin representing the pin.
                _pin          = new Pushpin();
                _pin.Template = Resources["PinPushpinTemplate"] as ControlTemplate;
                BingMap.Children.Add(_pin);
            }

            // Determine the coordinates of the point that was tapped.
            var point          = e.GetPosition(BingMap);
            var newPinLocation = BingMap.ViewportPointToLocation(point);

            // Update pin's location and the distance to me.
            _pin.Location = newPinLocation;
            ViewModel.Pin = newPinLocation;
            ViewModel.UpdateDistance();
        }
Exemple #11
0
        public void BingMapTestAlternateUrl()
        {
            BingMapConfig bmc = new BingMapConfig()
                                .SetKey(BingKey)
                                .SetUrl("http://dev.virtualearth.net/REST/v1/Locations/?maxResults=1")
                                .SetSearchQuery("q")
                                .SetKeyQuery("key");

            BingMap bing = new BingMap(bmc);

            var Expected = new {
                Latitude  = 30.267599105834961,
                Longitude = -97.74298095703125
            };

            IGeoCodeResult Target = new GeoCodeResult();

            Target = bing.GetCoordinates("Austin, TX");
            Assert.AreEqual(Expected.Latitude, Target.Latitude);
            Assert.AreEqual(Expected.Longitude, Target.Longitude);
        }
Exemple #12
0
        private async void AddMarker(Geopoint geopoint)
        {
            var marker = new MapIcon
            {
                Location = geopoint,
                NormalizedAnchorPoint = new Point(0.5, 1.0),
                ZIndex = 0,
                Title  = "Your Shop"
            };
            var locationMarkers = new List <MapElement>();

            locationMarkers.Add(marker);
            var markersLayer = new MapElementsLayer
            {
                ZIndex      = 1,
                MapElements = locationMarkers
            };

            BingMap.Layers.Clear();
            BingMap.Layers.Add(markersLayer);
            await BingMap.TrySetSceneAsync(MapScene.CreateFromLocationAndRadius(geopoint, 5000));
        }
Exemple #13
0
 public async System.Threading.Tasks.Task mapInitVoidTestAsync()
 {
     Assert.That((Assert.ThrowsAsync <Exception>(async() => await BingMap.mapInit(""))).Message, Is.EqualTo("No Query or Address value specified."));
 }
Exemple #14
0
        public override void InstantiateIn(Control container)
        {
            var wrapper = new HtmlGenericControl("fieldset");

            container.Controls.Add(wrapper);

            var sectionTable = new HtmlGenericControl("table");

            sectionTable.Attributes.Add("role", "presentation");

            string sectionName;
            var    sectionLabel        = string.Empty;
            var    sectionCssClassName = string.Empty;
            string visibleProperty;
            var    visible = true;

            Node.TryGetAttributeValue(".", "visible", out visibleProperty);

            if (!string.IsNullOrWhiteSpace(visibleProperty))
            {
                bool.TryParse(visibleProperty, out visible);
            }

            if (!visible)
            {
                return;
            }

            if (Node.TryGetAttributeValue(".", "name", out sectionName))
            {
                sectionTable.Attributes.Add("data-name", sectionName);

                if (_webformMetadata != null)
                {
                    var sectionWebFormMetadata = _webformMetadata.FirstOrDefault(wfm => wfm.GetAttributeValue <string>("adx_sectionname") == sectionName);

                    if (sectionWebFormMetadata != null)
                    {
                        var label = sectionWebFormMetadata.GetAttributeValue <string>("adx_label");

                        if (!string.IsNullOrWhiteSpace(label))
                        {
                            sectionLabel = Localization.GetLocalizedString(label, LanguageCode);
                        }

                        sectionCssClassName = sectionWebFormMetadata.GetAttributeValue <string>("adx_cssclass") ?? string.Empty;
                    }
                }
            }

            sectionTable.Attributes.Add("class", !string.IsNullOrWhiteSpace(sectionCssClassName) ? string.Join(" ", "section", sectionCssClassName) : "section");

            if (ShowLabel)
            {
                var caption = new HtmlGenericControl("legend")
                {
                    InnerHtml = string.IsNullOrWhiteSpace(sectionLabel) ? Label : sectionLabel
                };

                var cssClass = "section-title";
                if (ShowBar)
                {
                    cssClass += " show-bar";
                }

                caption.Attributes.Add("class", cssClass);

                wrapper.Controls.Add(caption);
            }

            var colgroup = new HtmlGenericControl("colgroup");

            sectionTable.Controls.Add(colgroup);

            if (PortalSettings.Instance.BingMapsSupported && !string.IsNullOrWhiteSpace(sectionName) && sectionName.EndsWith("section_map"))
            {
                var bingmap = new BingMap {
                    ClientIDMode = ClientIDMode.Static, MappingFieldCollection = MappingFieldCollection
                };

                sectionTable.Controls.Add(bingmap);
            }

            string columns;

            if (Node.TryGetAttributeValue(".", "columns", out columns))
            {
                // For every column there is a "1" in the columns attribute... 1=1, 11=2, 111=3, etc.)
                foreach (var column in columns)
                {
                    var width = 1 / (double)columns.Length * 100;
                    var col   = new SelfClosingHtmlGenericControl("col");
                    col.Style.Add(HtmlTextWriterStyle.Width, "{0}%".FormatWith(width));
                    colgroup.Controls.Add(col);
                }
                colgroup.Controls.Add(new SelfClosingHtmlGenericControl("col"));
            }

            wrapper.Controls.Add(sectionTable);

            var rowTemplates = Node.XPathSelectElements("rows/row").Select(row => RowTemplateFactory.CreateTemplate(row, EntityMetadata, CellTemplateFactory));

            foreach (var template in rowTemplates)
            {
                template.InstantiateIn(sectionTable);
            }
        }
Exemple #15
0
        // GET api/<controller>
        public IGeoCodeResult Query(GeoQuery q)
        {
            string             key      = string.Empty;
            string             query    = string.Empty;
            string             provider = "Google";
            IGeoProviderConfig config;
            IGeoProvider       GeoProvider = null;

            IGeoCodeResult result = new GeoCodeResult();


            if (!String.IsNullOrEmpty(q.Query) && !String.IsNullOrEmpty(q.Providers))
            {
                query = q.Query;
                // we have a search
                provider = q.Providers.Replace("KEY", "");
                if (q.Providers.Contains("KEY"))
                {
                    key = q.Key;
                }

                switch (provider)
                {
                case "Google":
                    config      = new GoogleGmapConfig();
                    GeoProvider = new GoogleGmap(config);
                    break;

                case "Bing":
                    config      = new BingMapConfig().SetKey(key);
                    GeoProvider = new BingMap(config);
                    break;

                case "MapQuest":
                    config      = new MapQuestConfig().SetKey(key);
                    GeoProvider = new MapQuestMap(config);
                    break;

                case "Open Streets":
                    config      = new OpenStreetMapConfig().SetUserAgent("your email here yo");
                    GeoProvider = new OpenStreetMap(config);
                    break;

                case "YahooPlaces":
                    config      = new YahooPlaceFinderConfig().SetKey(key);
                    GeoProvider = new YahooPlaceFinder(config);
                    break;

                case "CloudMade":
                    config      = new CloudMadeConfig().SetKey(key);
                    GeoProvider = new CloudMade(config);
                    break;
                }

                GeoProvider = GeoProvider != null ? GeoProvider : new GoogleGmap();

                GeoCoder gc = new GeoCoder(GeoProvider);

                result = gc.GetCoordinates(query);
            }
            return(result);
        }
 /// <summary>
 /// Draw pin elements on the map.
 /// </summary>
 public void DrawElements()
 {
     //Clear pins
     SatanController.HandleMap.ClearMap();
     //Player pin
     if (SatanController.CurrentPlayer != null)
     {
         Pushpin pin = new Pushpin()
         {
             Text = "Me"
         };
         BingMap.Children.Add(pin);
         MapLayer.SetPosition(pin, SatanController.CurrentPlayer.Location);
         //Set view
         if (SpearHandler.State == GameState.Idle)
         {
             if (BingMap.ZoomLevel < 15.0f)
             {
                 BingMap.SetView(SatanController.CurrentPlayer.Location, 15.0f);
             }
             else
             {
                 BingMap.SetView(SatanController.CurrentPlayer.Location, BingMap.ZoomLevel);
             }
         }
     }
     //Direction pin
     if (SatanController.DirectionLocation != null)
     {
         Pushpin pin = new Pushpin
         {
             Name = "Direction_Pin"
         };
         pin.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 0, 0, 255));
         BingMap.Children.Add(pin);
         MapLayer.SetPosition(pin, SatanController.DirectionLocation);
     }
     //Spear (if available) also handles focus
     if ((SpearHandler.Gungnir != null) && (!SpearHandler.Gungnir.Available))
     {
         Pushpin pin = new Pushpin()
         {
             Text = "Spear"
         };
         pin.Background = new SolidColorBrush(Windows.UI.Color.FromArgb(255, 125, 125, 0));
         BingMap.Children.Add(pin);
         MapLayer.SetPosition(pin, SpearHandler.Gungnir.Location);
         //Set view
         if (!(SpearHandler.State == GameState.Retrieving))
         {
             if (BingMap.ZoomLevel < 15.0f)
             {
                 BingMap.SetView(SpearHandler.Gungnir.Location, 15.0f);
             }
             else
             {
                 BingMap.SetView(SpearHandler.Gungnir.Location, BingMap.ZoomLevel);
             }
         }
     }
 }
Exemple #17
0
 /// <summary>
 /// Default constructor which initializes Map property and sets current user position to null.
 /// </summary>
 public BingMapViewModel()
 {
     Map          = new BingMap();
     Map.Location = null;
 }
Exemple #18
0
        public async Task OnGet()
        {
            Task <string> UserCords;

            UserInput       = null;
            Filters         = new Dictionary <string, double>();
            UseCurrLocation = UserLocation;

            if (CostTo != null)
            {
                MaxCost = Convert.ToDouble(CostTo);
            }
            else
            {
                MaxCost = Double.MaxValue;
            }
            Filters.Add("MaxCost", MaxCost);

            if (DistanceAway != null)
            {
                MaxDistance = Convert.ToDouble(DistanceAway);
            }
            else
            {
                MaxDistance = Double.MaxValue;
            }
            Filters.Add("MaxDistance", MaxDistance);

            if ((SearchString != null) && (SearchStringDesc != null))
            {
                TwoBoxes = true;
            }
            if ((SearchString == null) && ValidateEntry(SearchStringDesc, "DESC"))
            {
                UserInput = SearchStringDesc;
                TwoBoxes  = false;
            }
            else if ((SearchStringDesc == null) && ValidateEntry(SearchString, "CODE"))
            {
                UserInput = SearchString;
                TwoBoxes  = false;
            }

            if ((UserInput != null) && (!TwoBoxes))
            {
                Data          = new List <Dictionary <string, string> >();
                RankedResults = new List <DataRow>();
                //runs the input validation method
                Validate validate = new Validate();
                if (validate.validateCode(UserInput))
                {
                    UserInput = validate.cleanInput;
                    Searching search = new Searching();

                    if (UseCurrLocation.Length == 0)
                    {
                        // Console.WriteLine("Please enter location");
                        // change to put message on screeen and don't search

                        UserCords = BingMap.mapInit("Glasgow");
                        await UserCords;
                    }
                    else
                    {
                        UserCords = BingMap.mapInit(UseCurrLocation);
                        await UserCords;
                    }
                    DataRow y = new DataRow();
                    y.SetCords(UserCords.Result);

                    List <DataRow> data        = search.SearchByCode(UserInput, Filters);
                    List <DataRow> ToBeRemoved = new List <DataRow>();
                    foreach (DataRow dt in data)
                    {
                        Task <string> cords = BingMap.mapInit(dt.address.Street + ", " + dt.address.City + "," + dt.address.State);
                        await         cords;
                        dt.SetCords(cords.Result);

                        dt.distanceFromUser = new BingMap().HaversineDistance(y.cords, dt.cords);

                        if (dt.distanceFromUser > Filters["MaxDistance"])
                        {
                            ToBeRemoved.Add(dt);
                        }
                    }

                    foreach (DataRow dt in ToBeRemoved)
                    {
                        data.Remove(dt);
                    }

                    if (data.Count == 0)
                    {
                        //error message here
                        DataFound = false;
                    }
                    else
                    {
                        DataFound = true;

                        Display dis = new Display();
                        // find cheap
                        // find closest
                        // find best

                        // filter data based on filters on GUI


                        RankedResults.Add(dis.findCheapest(data));
                        RankedResults.Add(dis.findSmallestDistance(data));
                        dis.setScore(data);
                        RankedResults.Add(dis.findBest(data));

                        foreach (var x in data)
                        {
                            //This dictionary represents a row
                            Dictionary <string, string> dict = new Dictionary <string, string>();

                            //populates the row
                            dict.Add("Label", x.CombineLabel());
                            dict.Add("Description", x.definition);
                            dict.Add("Name", x.providerName);
                            dict.Add("Address", x.address.Street);
                            dict.Add("Zip", x.address.ZipCode);
                            dict.Add("State", x.address.State);
                            dict.Add("City", x.address.City);
                            dict.Add("Cost", x.cost.ToString());
                            dict.Add("Distance", x.distanceFromUser.ToString());
                            dict.Add("Score", x.score.ToString());

                            //Adds the row to the list
                            Data.Add(dict);
                        }
                    }
                }
            }
            else
            {
                UserInput = null;
            }
        }
Exemple #19
0
 private async void Map_Loaded(object sender, RoutedEventArgs e)
 {
     Geopoint gentPoint = new Geopoint(gentLocation);
     await BingMap.TrySetSceneAsync(MapScene.CreateFromLocationAndRadius(gentPoint, 5000));
 }