private void Button_Click_1(object sender, RoutedEventArgs e) { double[] GPS_Values = TCP.GPS_Information(); var point = new Mapsui.Geometries.Point(GPS_Values[1], GPS_Values[0]); var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(point.X, point.Y); MyMapControl.Map.NavigateTo(sphericalMercatorCoordinate); MyMapControl.Map.NavigateTo(MyMapControl.Map.Resolutions[18]); MyMapControl.Map.Layers.Add(OpenStreetMap.CreateTileLayer()); MyMapControl.Map.Layers.Add(Auxiliary.CreatePointLayer(sphericalMercatorCoordinate)); }
public void Update(GeoPosition position, double rotation) { Position = position; Rotation = rotation; LocationFeature.RenderedGeometry.Clear(); LocationFeature.Geometry = SphericalMercator.FromLonLat(Position.Longitude, Position.Latitude); _style.SymbolRotation = rotation; DataHasChanged(); }
public void Move() { if (selectedLand == null) { return; } var spherical = SphericalMercator.FromLonLat(selectedLand.Longitude, selectedLand.Latitude); var point = Current.Instance.MapControl.Viewport.WorldToScreen(spherical.x, spherical.y); Margin = new Thickness(point.X + 20, point.Y - 30, 0, 0); }
private void BtnZoomToClick(object sender, RoutedEventArgs e) { var polyCoords = news.Wkt.Replace("POLYGON ((", "").Replace("))", ""); var splitCoords = polyCoords.Split(','); var firstCoord = splitCoords[0].TrimStart().Split(' '); var secondCoord = splitCoords[2].TrimStart().Split(' '); var leftSpherical = SphericalMercator.FromLonLat(Double.Parse(firstCoord[0], CultureInfo.InvariantCulture), Double.Parse(firstCoord[1], CultureInfo.InvariantCulture)); var rightSpherical = SphericalMercator.FromLonLat(Double.Parse(secondCoord[0], CultureInfo.InvariantCulture), Double.Parse(secondCoord[1], CultureInfo.InvariantCulture)); Current.Instance.MapControl.ZoomToBox(new Point(leftSpherical.x, leftSpherical.y), new Point(rightSpherical.x, rightSpherical.y)); }
public MainWindow() { InitializeComponent(); LoadData(); MyMapControl.Map.Layers.Add(new TileLayer(KnownTileSources.Create())); var point1 = SphericalMercator.FromLonLat(4.875269, 52.327419); var point2 = SphericalMercator.FromLonLat(4.956937, 52.355972); MyMapControl.Map.NavigateTo(new BoundingBox(point1.X, point1.Y, point2.X, point2.Y)); MyMapControl.Map.NavigateTo(MyMapControl.Map.Resolutions[18]); MyMapControl.Map.Layers.Add(CreatePointLayer()); MyMapControl.Map.Layers.Add(CreateLineLayer()); }
private static float CalcStepMeters(float step, Point origin) { const double earthRadius = 6371000; //meters const double deg2rad = Math.PI / 180; Point offseted = origin + new Point(step, 0); double lat = deg2rad * SphericalMercator.ToLonLat(origin.X, origin.Y).X; double lon1 = deg2rad * SphericalMercator.ToLonLat(origin.X, origin.Y).X; double lon2 = deg2rad * SphericalMercator.ToLonLat(offseted.X, offseted.Y).X; double deltaLon = lon2 - lon1; return((float)(2 * earthRadius * Math.Asin(Math.Abs(Math.Sin(deltaLon / 2) * Math.Cos(lat / 2))))); }
private void Button_Click_1(object sender, RoutedEventArgs e) { //MyMapControl.ZoomOut(); var centerOfCC = new Mapsui.Geometries.Point(-6.3714, 39.4768); var center = GetCoordenates(); // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(center.X, center.Y); MyMapControl.Map.NavigateTo(sphericalMercatorCoordinate); MyMapControl.Map.NavigateTo(MyMapControl.Map.Resolutions[15]); }
public Map CreateMap(ITransitLocation stop) { var map = new Map(); map.Layers.Add(OpenStreetMap.CreateTileLayer()); map.NavigateTo(map.Resolutions[14]); map.NavigateTo(SphericalMercator. FromLonLat(stop.Location.X, stop.Location.Y)); return(map); }
private LineString GetLine(RepeatedField <double> lonlats) { var linestring = new LineString(); for (int i = 0; i < lonlats.Count; i++) { var point = SphericalMercator.FromLonLat(lonlats[i], lonlats[i + 1]); linestring.Vertices.Add(point); i++; } return(linestring); }
private void MapControlMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!isScoreAdding) //esto evita que abran el hexagono nuevamente mientras se está guardando un puntaje { if ((Current.Instance.TutorialStarted && tutorialCompletePhase1) || (Current.Instance.Tutorial2Started && tutorialCompletePhase2) || (!Current.Instance.TutorialStarted && !Current.Instance.Tutorial2Started)) { leftMouseButtonDown = true; if (!layerHelper.FindLayer(Constants.Hexagonlayername).Enabled) { return; } var mousePos = e.GetPosition(mapControl); var sphericalCoordinate = mapControl.Viewport.ScreenToWorld(mousePos.X, mousePos.Y); //TODO: posicionar bien el tooltip var lonLat = SphericalMercator.ToLonLat(sphericalCoordinate.X, sphericalCoordinate.Y); var feature = hexagonInfo.GetFeature(lonLat.x, lonLat.y, 7); var hexCode = GeoHex.Encode(lonLat.x, lonLat.y, 7); if (feature == null) { // try on level 6... hexCode = GeoHex.Encode(lonLat.x, lonLat.y, 6); } bool showHex = true; if ((Current.Instance.TutorialStarted || Current.Instance.Tutorial2Started) && !selectedLand.GeohexKey.Equals(hexCode)) { showHex = false; } if (showHex) { if (Current.Instance.TutorialStarted) { this.Tutorial5.Visibility = System.Windows.Visibility.Collapsed; this.Tutorial5Arrow.Visibility = System.Windows.Visibility.Collapsed; } if (Current.Instance.Tutorial2Started) { this.Tutorial23.Visibility = System.Windows.Visibility.Collapsed; this.Tutorial5Arrow.Visibility = System.Windows.Visibility.Collapsed; } hexagonInfo.ShowInfo(lonLat.x, lonLat.y); } } } }
private void DrawArrows(SKSurface skSurface, IReadOnlyViewport viewport, Route route, int scale) { const string resourceId = "FamilieWandelPad.RouteImager.Arrow_Up.png"; var assembly = GetType().GetTypeInfo().Assembly; SKBitmap resourceBitmap; using (var stream = assembly.GetManifestResourceStream(resourceId)) { resourceBitmap = SKBitmap.Decode(stream); resourceBitmap = resourceBitmap.Resize(new SKSizeI(25, 25), SKFilterQuality.High); } var arrowSteps = Distance.FromMeters(50); for (var index = 0; index < route.Waypoints.Count; index++) { var waypoint = route.Waypoints[index]; var nextWaypoint = route.Waypoints[(index + 1) % route.Waypoints.Count]; var a = new Vector2((float)waypoint.Latitude, (float)waypoint.Longitude); var b = new Vector2((float)nextWaypoint.Latitude, (float)nextWaypoint.Longitude); var aToB = b - a; //Vector from A to B var steps = Math.Max( Distance.FromMiles(waypoint.Distance(nextWaypoint)).Meters / arrowSteps.Meters, 2 ); for (var step = 1; step < steps; step++) { var arrow = a + aToB * (float)(step / steps); var screenPoint = viewport.WorldToScreen( SphericalMercator.FromLonLat(arrow.Y, arrow.X) ); skSurface.Canvas.Save(); skSurface.Canvas.RotateDegrees((float)waypoint.DegreeBearing(nextWaypoint), (float)screenPoint.X, (float)screenPoint.Y); skSurface.Canvas.DrawBitmap( resourceBitmap, (float)screenPoint.X - resourceBitmap.Width / 2f, (float)screenPoint.Y - resourceBitmap.Height / 2f ); skSurface.Canvas.Restore(); // skSurface.Canvas.DrawCircle((float) screenPoint.X, (float) screenPoint.Y, 10, new SKPaint() {Color = SKColors.Blue}); } } }
void InitMap() { //MAP _mapControl = FindViewById <MapControl>(Resource.Id.mapControl1); Map map = new Map(); map.Layers.Add(OpenStreetMap.CreateTileLayer()); var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(UserPosition.Longitude.Degrees, UserPosition.Latitude.Degrees); map.NavigateTo(sphericalMercatorCoordinate); map.NavigateTo(map.Resolutions[15]); _mapControl.Map = map; map.Widgets.Add(new ZoomInOutWidget(map) { MarginX = 20, MarginY = 20, HorizontalAlignment = Mapsui.Widgets.HorizontalAlignment.Left, VerticalAlignment = Mapsui.Widgets.VerticalAlignment.Top }); map.Widgets.Add(new Mapsui.Widgets.ScaleBar.ScaleBarWidget(map) { TextAlignment = Mapsui.Widgets.Alignment.Center, HorizontalAlignment = Mapsui.Widgets.HorizontalAlignment.Center, VerticalAlignment = Mapsui.Widgets.VerticalAlignment.Top }); lineLayer = new MemoryLayer { //DataSource = new MemoryProvider(feature), Name = "LineStringLayer", Style = CreateLineStringStyle(), }; UserPosPointsLayer = new MemoryLayer { Name = "UserPoint", Style = CreateUserPinStyle(), }; CalibPointsLayer = new MemoryLayer { Name = "CalibPoints", Style = CreateCalibPinStyle(), }; map.Layers.Add(lineLayer); map.Layers.Add(UserPosPointsLayer); map.Layers.Add(CalibPointsLayer); map.Info += Map_Info; }
void UpdateCalibPoints() { //update map var feature = new Feature(); var point = SphericalMercator.FromLonLat(CalibPosition.Longitude.Degrees, CalibPosition.Latitude.Degrees); feature.Geometry = point; feature["name"] = "Calib"; CalibPointsLayer.DataSource = new MemoryProvider(feature); //update direction BluetoothClass.map1_correction_yaw = get_direction(CalibPosition); }
private void SetLocation(double longitude, double latitude) { Point sphericalLocation = SphericalMercator.FromLonLat(longitude, latitude); mapControl.Viewport.Center = sphericalLocation; if (Dispatcher.HasThreadAccess) { mapControl.Refresh(); } else { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => mapControl.Refresh()); } }
private void callback(QueryResult queryResult) { if (queryResult != null) { var xyStart = SphericalMercator.FromLonLat(queryResult.bbox[0], queryResult.bbox[1]); var xyEnd = SphericalMercator.FromLonLat(queryResult.bbox[2], queryResult.bbox[3]); var beginPoint = new Mapsui.Geometries.Point(xyStart.x, xyStart.y); var endPoint = new Mapsui.Geometries.Point(xyEnd.x, xyEnd.y); Deployment.Current.Dispatcher.BeginInvoke(() => mapControl.ZoomToBox(beginPoint, endPoint) ); } }
public static void UpdateLocationMarker(bool navigate) { try { //var location = Geolocation.GetLastKnownLocationAsync().Result; _ = GetCurrentLocation(); var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(location.Longitude, location.Latitude); if (navigate) { Fragments.Fragment_map.mapControl.Navigator.CenterOn(sphericalMercatorCoordinate); } /**///This is bad. Is there not a better way to update the current location than removing and adding layers? foreach (ILayer layer in Fragments.Fragment_map.map.Layers.FindLayer(LocationLayerName)) { Fragments.Fragment_map.map.Layers.Remove(layer); } Fragments.Fragment_map.map.Layers.Add(CreateLocationLayer(sphericalMercatorCoordinate)); //Fragments.Fragment_map.map.Layers.Remove(Fragments.Fragment_map.map.Layers.FindLayer(LocationLayerName).First()); //Fragments.Fragment_map.map.Layers.Add(CreateLocationLayer(sphericalMercatorCoordinate)); /*var b = new MemoryLayer * { * Name = LocationLayerName, * DataSource = CreateMemoryProviderWithDiverseSymbols(sphericalMercatorCoordinate), * Style = null, * IsMapInfoLayer = true * }; * * ILayer locationlayer = Fragments.Fragment_map.map.Layers.FindLayer(LocationLayerName).FirstOrDefault(); * locationlayer = b; * locationlayer.DataHasChanged();*/ /*IEnumerable<ILayer> layers = Fragments.Fragment_map.map.Layers.Where(x => (string)x.Tag == "route"); * layers[0]; * foreach (ILayer rt in layers) * { * Fragments.Fragment_map.map.Layers.Remove(rt); * }*/ } catch (Exception ex) { Serilog.Log.Information($"No location information? '{ex}'"); } }
void Tutorial0StoryBoard_Completed(object sender, EventArgs e) { this.Overlay.Visibility = System.Windows.Visibility.Collapsed; //Navego hacia Salta var sphericalTopLeft = SphericalMercator.FromLonLat(-65.742188, -21.988895); var sphericalBottomRight = SphericalMercator.FromLonLat(-62.3364, -26.335268); mapControl.ZoomToBox(new Mapsui.Geometries.Point(sphericalTopLeft.x, sphericalTopLeft.y), new Mapsui.Geometries.Point(sphericalBottomRight.x, sphericalBottomRight.y)); //TODO: Blergh awfull dirty dirty hack to show hexagon after zoomToHexagon (problem = Extend is a center point after ZoomToBox) mapControl.ZoomIn(); mapControl.ZoomOut(); }
private Features GetFeatures() { LocationFeature = new Feature { Geometry = SphericalMercator.FromLonLat(Position.Longitude, Position.Latitude), Styles = new List <IStyle> { _style } }; return(new Features { LocationFeature }); }
public static ILayer CreateLineStringLayer(IStyle style = null) { var lineString = (LineString)Geometry.GeomFromText(WKTGr5); lineString = new LineString(lineString.Vertices.Select(v => SphericalMercator.FromLonLat(v.Y, v.X))); return(new MemoryLayer { DataSource = new MemoryProvider(new Feature { Geometry = lineString }), Name = "LineStringLayer", Style = CreateLineStringStyle() }); }
internal void MoveTo(double latitude, double longitude, int zoom = -1) { if (latitude == 0 && longitude == 0) { return; } var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(longitude, latitude); _map.NavigateTo(sphericalMercatorCoordinate); if (zoom > 0) { _map.NavigateTo(_map.Resolutions[zoom]); } }
private static IEnumerable <IFeature> GetCitiesFromEmbeddedResource() { var path = "Mapsui.Samples.Common.EmbeddedResources.congo.json"; var assembly = typeof(PointsSample).GetTypeInfo().Assembly; using var stream = assembly.GetManifestResourceStream(path); var cities = DeserializeFromStream <City>(stream); return(cities.Select(c => { var feature = new PointFeature(SphericalMercator.FromLonLat(c.Lng, c.Lat).ToMPoint()); feature["name"] = c.Name; feature["country"] = c.Country; return feature; })); }
//private void DrawImage() //{ // //var img = System.Drawing // ////var raster = new Raster(); // var feature = new Feature { Geometry = null }; // var vStyle = new VectorStyle // { // Fill = new Brush { Color = Color.FromArgb(50, 255, 255, 0) } // }; // feature.Styles.Add(vStyle); // _source.Features.Add(feature); // Current.Instance.MapControl.OnViewChanged(true); //} //Convert lon lat coordinates into spherical for use on map private static List <Point> ConvertHexCoordinates(IList <Location> locations) { if (locations == null || locations.Count == 0) { return(null); } var newLocations = locations.Select(location => SphericalMercator.FromLonLat(location.Longitude, location.Latitude)).Select(spherical => new Point(spherical.x, spherical.y)).ToList(); var sphericalClosing = SphericalMercator.FromLonLat(locations[0].Longitude, locations[0].Latitude); newLocations.Add(new Point(sphericalClosing.x, sphericalClosing.y)); return(newLocations); }
private IEnumerable <Feature> RenderSections(Route route) { return(route.Sections .Select(section => new Polygon { ExteriorRing = new LinearRing( section.Polygon.Select(gp => SphericalMercator.FromLonLat(gp.Longitude, gp.Latitude)) ) }) .Select(polygon => new Feature { Geometry = polygon })); }
/// <summary> /// Find the centroid of the geometry /// </summary> /// <param name="geometryId"></param> /// <returns>A point object representing the centroid</returns> public static Mapsui.Geometries.Point GetCentreOfGeometry(int geometryId) { var items = DataDAO.getDataForMap(App.CurrentProjectId); foreach (var item in items) { if (item.geomId == geometryId) { var coords = item.shapeGeom.Centroid; var centre = SphericalMercator.FromLonLat(coords.X, coords.Y); return(centre); } } return(null); }
public void SphericalMercatorPrecisionTest() { // Arrange var inLon = 101.71046179910427; var inLat = 3.1567427968766819; // Act var(x, y) = SphericalMercator.FromLonLat(inLon, inLat); var(outLon, outLat) = SphericalMercator.ToLonLat(x, y); // Assert var distanceInKilometer = Haversine.Distance(inLon, inLat, outLon, outLat); var distanceInCentimer = distanceInKilometer * 100000; Assert.Less(distanceInCentimer, 1); }
public void Update(Route route) { _memoryProvider.Clear(); _memoryProvider.ReplaceFeatures( route.Sections .SelectMany(section => section.Polygon) .Select(polygonPoint => new SectionPointFeature { Section = route.Sections.Find(section => section.Polygon.Contains(polygonPoint)), Point = polygonPoint, Geometry = SphericalMercator.FromLonLat(polygonPoint.Longitude, polygonPoint.Latitude) }) ); DataHasChanged(); }
private static WritableLayer CreatePointLayer() { var pointLayer = new WritableLayer { Name = "PointLayer", Style = CreatePointStyle() }; var dgt = new Feature { Geometry = SphericalMercator.FromLonLat(18.568066, 54.277201) }; pointLayer.Add(dgt); return(pointLayer); }
public static IGeometry?GpxWaypointsToMapsuiGeometry( this IEnumerable <GpxWaypoint> waypoints, ILoadedGpxFileTourInfo tour, ILoadedGpxFileTourSegmentInfo segment) { var linePoints = new List <Point>(); foreach (var actPoint in waypoints) { linePoints.Add(SphericalMercator.FromLonLat(actPoint.Longitude, actPoint.Latitude)); } if (linePoints.Count < 2) { return(null); } return(new GpxViewerLineString(tour, segment, linePoints)); }
/// <summary> /// New informations from Geolocator arrived /// </summary> /// <param name="sender">Geolocator</param> /// <param name="e">Event arguments for new position</param> private void MyLocationPositionChanged(object sender, PositionEventArgs e) { Device.BeginInvokeOnMainThread(() => { var coords = new Plugin.Geolocator.Abstractions.Position(e.Position.Latitude, e.Position.Longitude); //info.Text = $"{coords.ToString()} - D:{(int)e.Position.Heading} S:{Math.Round(e.Position.Speed, 2)}"; //mapView.Map.Viewport.Resolution = 1; //= new Mapsui.Geometries.Point( -46.38,-23.32); var coord = SphericalMercator.FromLonLat(coords.Longitude, coords.Latitude); var map = mapView.Map; mapView.Map.Home = n => n.NavigateTo(coord, map.Resolutions[9]); //mapView.Map.Viewport.Rotation = coords.Heading; //mapView..UpdateMyLocation(new UI.Forms.Position(e.Position.Latitude, e.Position.Longitude)); //mapView.MyLocationLayer.UpdateMyDirection(e.Position.Heading, mapView.Viewport.Rotation); //mapView.MyLocationLayer.UpdateMySpeed(e.Position.Speed); }); }
public static Map CreateMap() { var map = new Map(); map.Layers.Add(OpenStreetMap.CreateTileLayer()); // Get the lon lat coordinates from somewhere (Mapsui can not help you there) var centerOfLondonOntario = new MPoint(-81.2497, 42.9837); // OSM uses spherical mercator coordinates. So transform the lon lat coordinates to spherical mercator var sphericalMercatorCoordinate = SphericalMercator.FromLonLat(centerOfLondonOntario.X, centerOfLondonOntario.Y).ToMPoint(); // Set the center of the viewport to the coordinate. The UI will refresh automatically // Additionally you might want to set the resolution, this could depend on your specific purpose map.Home = n => n.NavigateTo(sphericalMercatorCoordinate, map.Resolutions[9]); return(map); }