private void OpenKml(object sender, RoutedEventArgs e) { OpenFileDialog opfd = new OpenFileDialog(); opfd.Filter = "Google Earth files *.kml|*.kml"; var res = opfd.ShowDialog(); if (res == true) { vm.Fields = new System.Collections.ObjectModel.ObservableCollection <VM.FieldVM>(); XmlDocument document = new XmlDocument(); document.Load(opfd.FileName); var places = document.GetElementsByTagName("Placemark"); foreach (XmlElement place in places) { var el = place.GetElementsByTagName("coordinates")[0]; try { VM.FieldVM polygon = new VM.FieldVM(); vm.Fields.Add(polygon); polygon.Fill = greenBrush; polygon.Locations = new MapControl.LocationCollection(); string[] coordStrs = ((System.Xml.XmlElement)el).InnerText.Split(' '); CultureInfo ci = new CultureInfo("en-US"); foreach (var pointStr in coordStrs) { try { if (string.IsNullOrEmpty(pointStr)) { continue; } double longitude; string[] pCoords = pointStr.Split(','); longitude = double.Parse(pCoords[0].Trim(), ci); double latitude = double.Parse(pCoords[1], ci); polygon.Locations.Add(new MapControl.Location(latitude, longitude)); } catch { } } var southWest = new MapControl.Location(polygon.Locations.Min(p => p.Latitude), polygon.Locations.Min(p => p.Longitude)); var northEast = new MapControl.Location(polygon.Locations.Max(p => p.Latitude), polygon.Locations.Max(p => p.Longitude)); mainMap.ZoomToBounds(southWest, northEast); } catch { } } } }
public MapViewModel(TrackService trackService) { this.trackService = trackService; ZoomLevel = 15; MapCenter = new MapControlLocation(53.5, 8.2); ResetToDefaultCommand = CommandFactory.Create(WrapCommandFunc(ResetDefaultFilterOptionsAsync), () => IsNotBusy); LoadCellIdCommand = CommandFactory.Create <Track>(LoadCellIdAsync); ApplyParametersCommand = CommandFactory.Create(WrapCommandFunc(ApplyParametersAsync), () => IsNotBusy); ResetDefaultFilterOptionsAsync(); LoadCachedTracks(); }
private void ButtonMap_ExecuteEvent(object sender, ExecuteEventArgs e) { try { MapControl.LocationCollection locations = new MapControl.LocationCollection(); List <ViewModel.PointItem> pointItems = new List <ViewModel.PointItem>(); MapControl.Location mapCenter = null; double distanceStart = 0; List <RecordValues> list = DataManager.Instance.RecordList; for (int i = 0; i < list.Count; i++) { double latitude = list[i].PositionLat; double longitude = list[i].PositionLong; double distance = list[i].Distance; MapControl.Location location = new MapControl.Location(latitude, longitude); if (mapCenter == null && latitude != 0) { mapCenter = location; pointItems.Add(new ViewModel.PointItem() { Location = location, Name = distanceStart.ToString() + " km" }); distanceStart += 5; } if (mapCenter != null && latitude != 0) { locations.Add(location); if (distance >= distanceStart) { pointItems.Add(new ViewModel.PointItem() { Location = location, Name = distanceStart.ToString() + " km" }); distanceStart += 5; } } } WpfMaps.MapHandler handler = new WpfMaps.MapHandler((int)SpinnerMapWidth.DecimalValue, (int)SpinnerMapHeight.DecimalValue); handler.SetLocations(mapCenter, locations, pointItems); handler.ShowDialog(); } catch { throw; } }
void mainMap_MouseLeftUp_AddPointToField(object sender, MouseButtonEventArgs e) { MapControl.Location l = mainMap.ViewportPointToLocation(e.GetPosition(mainMap)); fieldDrawn.Locations.Add(l); }
void MyMap_MouseEnter(object sender, MouseEventArgs e) { // Show a popup with data about that point Ellipse pin = sender as Ellipse; if (pin != null) { var itineraryItem = pin.Tag as ItineraryItem; if (itineraryItem != null) { Microsoft.Maps.MapControl.Location location = new MapControl.Location(itineraryItem.Location.Latitude, itineraryItem.Location.Longitude); MapLayer.SetPosition(ContentPopup, location); MapLayer.SetPositionOffset(ContentPopup, new Point(15, -50)); string contentString = itineraryItem.Text; //Remove tags from the string Regex regex = new Regex("<(.|\n)*?>"); contentString = regex.Replace(contentString, string.Empty); ContentPopupText = contentString; ContentPopup.Visibility = Visibility.Visible; } } }