private RaycastMapResult RayCastToMap(Point startPoint) { RayHitTestResult rayHitTestResult = VisualTreeHelper.HitTest(viewport, startPoint) as RayHitTestResult; if (rayHitTestResult != null) { Point3D hitPoint = rayHitTestResult.PointHit; // Convert to tile coords var hitPointOnTile = new Vector2 <double>(hitPoint.X - rayHitTestResult.ModelHit.Bounds.X, -(rayHitTestResult.ModelHit.Bounds.Y - hitPoint.Y)); hitPointOnTile.X = 4096 - hitPointOnTile.X; hitPointOnTile = hitPointOnTile.Multiply(2); Projection projection = CalculateProjection(); var hitTile = new Vector2 <double>(hitPoint.X, hitPoint.Y).Divide(4096).ToVectorInt().Multiply(4096); double startPosX = (int)Math.Floor((hitTile.X - (projection.Bottom / 2)) / 4096) + 1; double startPosY = (int)Math.Floor((hitTile.Y - (projection.Left / 2)) / 4096) + 1; double cZoom = dataController.ConvertToMapZoom(zoom); Vector2 <double> startTileCoordinations = MercatorProjection.LatLngToTile(Settings.startPosition, cZoom); LatLng tileLatLng = MercatorProjection.TileToLatLng(new Vector2 <double>(startTileCoordinations.X - startPosX, startTileCoordinations.Y + startPosY), cZoom); //LatLng pointLatLng = MercatorProjection.TileToLatLng(, cZoom); Vector2 <double> tile = MercatorProjection.LatLngToTile(tileLatLng, cZoom).Floor(); Graph graph = dataController.GetRoads(new Vector3 <double>(tile.X, tile.Y, cZoom)); help.Content = graph.FindNearest(hitPointOnTile); return(new RaycastMapResult(tileLatLng, hitPointOnTile, hitPoint)); } return(null); }
/// <summary> /// Computes the coordinates of this bounding box relative to a tile. </summary> /// <param name="tile"> the tile to compute the relative position for. </param> /// <returns> rectangle giving the relative position. </returns> public virtual Rectangle GetPositionRelativeToTile(Tile tile) { Point upperLeft = MercatorProjection.GetPixelRelativeToTile(new LatLong(this.MaxLatitude, MinLongitude), tile); Point lowerRight = MercatorProjection.GetPixelRelativeToTile(new LatLong(this.MinLatitude, MaxLongitude), tile); return(new Rectangle(upperLeft.X, upperLeft.Y, lowerRight.X, lowerRight.Y)); }
/// <param name="tileX"> /// the X number of the tile. </param> /// <param name="tileY"> /// the Y number of the tile. </param> /// <param name="zoomLevel"> /// the zoom level of the tile. </param> /// <exception cref="IllegalArgumentException"> /// if any of the parameters is invalid. </exception> public Tile(int tileX, int tileY, sbyte zoomLevel, int tileSize) { if (tileX < 0) { throw new System.ArgumentException("tileX must not be negative: " + tileX); } else if (tileY < 0) { throw new System.ArgumentException("tileY must not be negative: " + tileY); } else if (zoomLevel < 0) { throw new System.ArgumentException("zoomLevel must not be negative: " + zoomLevel); } long maxTileNumber = GetMaxTileNumber(zoomLevel); if (tileX > maxTileNumber) { throw new System.ArgumentException("invalid tileX number on zoom level " + zoomLevel + ": " + tileX); } else if (tileY > maxTileNumber) { throw new System.ArgumentException("invalid tileY number on zoom level " + zoomLevel + ": " + tileY); } this.TileSize = tileSize; this.TileX = tileX; this.TileY = tileY; this.ZoomLevel = zoomLevel; this.MapSize = MercatorProjection.GetMapSize(zoomLevel, tileSize); }
// Use this for initialization void Start() { nodes = new Dictionary <ulong, OsmNode> (); ways = new List <OsmWay> (); var txtAsset = Resources.Load <TextAsset> (resourceFile); XmlDocument doc = new XmlDocument(); doc.LoadXml(txtAsset.text); SetBounds(doc.SelectSingleNode("/osm/bounds")); GetNodes(doc.SelectNodes("/osm/node")); GetWays(doc.SelectNodes("/osm/way")); float minx = (float)MercatorProjection.lonToX(bounds.MinLon); float maxx = (float)MercatorProjection.lonToX(bounds.MaxLon); float miny = (float)MercatorProjection.latToY(bounds.MinLat); float maxy = (float)MercatorProjection.latToY(bounds.MaxLat); groundPlane.transform.localScale = new Vector3((maxx - minx) / 2, 1, (maxy - miny) / 2); IsReady = true; }
/// <summary> /// Spawns new enemies when they are sent from the server. /// </summary> /// <param name="enemies">List of type Enemy of all the enemies to be spawned.</param> void Spawn(List <Enemy> enemies) { //Only execute in the Map scene. if (SceneManager.GetActiveScene().name == "Map Reader Test") { //Destroy any current spawned enemies for (int i = enemyParent.transform.childCount; i > 0; i--) { Destroy(enemyParent.transform.GetChild(i - 1).gameObject); } //Instantiate each new enemy. foreach (Enemy e in enemies) { float x = (float)MercatorProjection.lonToX(e.lon); float y = (float)MercatorProjection.latToY(e.lat); Vector3 position = new Vector3(x, 0, y); position = position - map.bounds.centre; if (e.name == "wizard") { var newWizard = Instantiate(wizard, position, transform.rotation); newWizard.transform.localScale = new Vector3(1.5f, 1.5f, 1.5f); newWizard.transform.SetParent(enemyParent.transform); } else if (e.name == "skeleton") { var newSkeleton = Instantiate(skeleton, position, transform.rotation); newSkeleton.transform.SetParent(enemyParent.transform); } } } }
internal SubFileParameter(SubFileParameterBuilder subFileParameterBuilder) { this.StartAddress = subFileParameterBuilder.StartAddress; this.IndexStartAddress = subFileParameterBuilder.IndexStartAddress; this.SubFileSize = subFileParameterBuilder.SubFileSize; this.BaseZoomLevel = subFileParameterBuilder.BaseZoomLevel; this.ZoomLevelMin = subFileParameterBuilder.ZoomLevelMin; this.ZoomLevelMax = subFileParameterBuilder.ZoomLevelMax; this.HashCodeValue = CalculateHashCode(); // calculate the XY numbers of the boundary tiles in this sub-file this.BoundaryTileBottom = MercatorProjection.LatitudeToTileY(subFileParameterBuilder.BoundingBox.MinLatitude, this.BaseZoomLevel); this.BoundaryTileLeft = MercatorProjection.LongitudeToTileX(subFileParameterBuilder.BoundingBox.MinLongitude, this.BaseZoomLevel); this.BoundaryTileTop = MercatorProjection.LatitudeToTileY(subFileParameterBuilder.BoundingBox.MaxLatitude, this.BaseZoomLevel); this.BoundaryTileRight = MercatorProjection.LongitudeToTileX(subFileParameterBuilder.BoundingBox.MaxLongitude, this.BaseZoomLevel); // calculate the horizontal and vertical amount of blocks in this sub-file this.BlocksWidth = this.BoundaryTileRight - this.BoundaryTileLeft + 1; this.BlocksHeight = this.BoundaryTileBottom - this.BoundaryTileTop + 1; // calculate the total amount of blocks in this sub-file this.NumberOfBlocks = this.BlocksWidth * this.BlocksHeight; this.IndexEndAddress = this.IndexStartAddress + this.NumberOfBlocks * BYTES_PER_INDEX_ENTRY; }
/** * @param zoomLevel * the zoom level at which this {@code PolygonalChain} should draw itself. * @param canvasPosition * the top-left pixel position of the canvas on the world map at the given zoom level. * @param closeAutomatically * whether the generated path should always be closed. * @return a {@code Path} representing this {@code PolygonalChain} (may be null). */ public Path draw ( byte zoomLevel, MapPoint canvasPosition, bool closeAutomatically ) { lock (this.GeoPoints) { int numberOfGeoPoints = this.GeoPoints.Count; if (numberOfGeoPoints < 2) { return null; } Path path = new Path(); PathGeometry geometry = new PathGeometry(); PathFigure figure = new PathFigure(); for (int i = 0; i < numberOfGeoPoints; ++i) { GeoPoint GeoPoint = this.GeoPoints[i]; double latitude = GeoPoint.Latitude; double longitude = GeoPoint.Longitude; float pixelX = (float)(MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.X); float pixelY = (float)(MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.Y); if (i == 0) { figure.StartPoint = new Point(pixelX, pixelY); } else { var segment = new LineSegment(); segment.point = new Point(pixelX, pixelY); figure.Segments.Add(segment); } } if (closeAutomatically && !isClosed()) { var segment = new LineSegment(); segment.point = figure.StartPoint; figure.Segments.Add(segment); } return path; } }
//@Override public bool draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, MapCore.Model.MapPoint canvasPosition) { if (this.GeoPoint == null || this.Shape == null) { return(false); } double latitude = this.GeoPoint.Latitude; double longitude = this.GeoPoint.Longitude; double pixelX = (MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.X); double pixelY = (MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.Y); Rect drawableBounds = this.Shape.GetPosition(); double left = pixelX + drawableBounds.Left; double top = pixelY + drawableBounds.Top; double right = pixelX + drawableBounds.Right; double bottom = pixelY + drawableBounds.Bottom; if (!intersect(canvas, left, top, right, bottom)) { return(false); } var clone = this.Shape.Clone(); canvas.Children.Add(clone); Canvas.SetTop(clone, pixelX); Canvas.SetLeft(clone, pixelY); return(true); }
public void RenderPointOfInterestCircle(RenderContext renderContext, float radius, IPaint fill, IPaint stroke, int level, PointOfInterest poi) { Point poiPosition = MercatorProjection.GetPixelRelativeToTile(poi.Position, renderContext.rendererJob.tile); renderContext.AddToCurrentDrawingLayer(level, new ShapePaintContainer(new CircleContainer(poiPosition, radius), stroke)); renderContext.AddToCurrentDrawingLayer(level, new ShapePaintContainer(new CircleContainer(poiPosition, radius), fill)); }
/// <summary> /// Updates the models position using GPS coordinates. /// Also creates smooth walking animation between the old model /// position and new model position. /// </summary> void Update() { x = (float)MercatorProjection.lonToX(Gps.instance.longitude); y = (float)MercatorProjection.latToY(Gps.instance.latitude); newPos = new Vector3(x, 0f, y); newPos = newPos - map.bounds.centre; float t = Mathf.SmoothStep(0f, 1f, Mathf.PingPong(1 / 25f, 1f)); //Linearly adjusts rotation and position. transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(newPos), 0.15f); transform.position = Vector3.Lerp(transform.position, newPos, t); float distance = Vector3.Distance(transform.position, newPos); if (distance < 2) { anim.SetFloat("MoveSpeed", Mathf.SmoothStep(v, 0f, time)); } else { v = Mathf.SmoothStep(0f, 1f, time); anim.SetFloat("MoveSpeed", v); } time += 0.5f * Time.deltaTime; if (time > 1.0f) { time = 1.0f; } }
protected internal virtual void addPOI(TDNode poi) { if (!poi.POI) { return; } sbyte minZoomLevel = poi.ZoomAppear; for (int i = 0; i < this.zoomIntervalConfiguration.NumberOfZoomIntervals; i++) { // is POI seen in a zoom interval? if (minZoomLevel <= this.zoomIntervalConfiguration.getMaxZoom(i)) { long tileCoordinateX = MercatorProjection.longitudeToTileX(LatLongUtils.microdegreesToDegrees(poi.Longitude), this.zoomIntervalConfiguration.getBaseZoom(i)); long tileCoordinateY = MercatorProjection.latitudeToTileY(LatLongUtils.microdegreesToDegrees(poi.Latitude), this.zoomIntervalConfiguration.getBaseZoom(i)); TileData tileData = getTileImpl(i, (int)tileCoordinateX, (int)tileCoordinateY); if (tileData != null) { tileData.addPOI(poi); countPoiTags(poi); } } } }
public BaseTileBasedDataProcessor(MapWriterConfiguration configuration) : base() { this.boundingbox = configuration.BboxConfiguration; this.zoomIntervalConfiguration = configuration.ZoomIntervalConfiguration; this.tileGridLayouts = new TileGridLayout[this.zoomIntervalConfiguration.NumberOfZoomIntervals]; this.bboxEnlargement = configuration.BboxEnlargement; this.preferredLanguages = configuration.PreferredLanguages; this.skipInvalidRelations = configuration.SkipInvalidRelations; this.outerToInnerMapping = new TLongObjectHashMap <>(); this.innerWaysWithoutAdditionalTags = new TLongHashSet(); this.tilesToCoastlines = new Dictionary <>(); this.countWays = new float[this.zoomIntervalConfiguration.NumberOfZoomIntervals]; this.countWayTileFactor = new float[this.zoomIntervalConfiguration.NumberOfZoomIntervals]; this.histogramPoiTags = new TShortIntHashMap(); this.histogramWayTags = new TShortIntHashMap(); // compute horizontal and vertical tile coordinate offsets for all // base zoom levels for (int i = 0; i < this.zoomIntervalConfiguration.NumberOfZoomIntervals; i++) { TileCoordinate upperLeft = new TileCoordinate((int)MercatorProjection.longitudeToTileX(this.boundingbox.minLongitude, this.zoomIntervalConfiguration.getBaseZoom(i)), (int)MercatorProjection.latitudeToTileY(this.boundingbox.maxLatitude, this.zoomIntervalConfiguration.getBaseZoom(i)), this.zoomIntervalConfiguration.getBaseZoom(i)); this.tileGridLayouts[i] = new TileGridLayout(upperLeft, computeNumberOfHorizontalTiles(i), computeNumberOfVerticalTiles(i)); } }
//@Override public bool draw(BoundingBox boundingBox, byte zoomLevel, Canvas canvas, MapPoint canvasPosition) { if (this.GeoPoint == null || (this.paintStroke == null && this.paintFill == null)) { return(false); } double latitude = this.GeoPoint.Latitude; double longitude = this.GeoPoint.Longitude; float pixelX = (float)(MercatorProjection.longitudeToPixelX(longitude, zoomLevel) - canvasPosition.X); float pixelY = (float)(MercatorProjection.latitudeToPixelY(latitude, zoomLevel) - canvasPosition.Y); float radiusInPixel = (float)metersToPixels(latitude, this.radius, zoomLevel); var shape = new S.Ellipse(); shape.Width = radiusInPixel * 2; shape.Height = radiusInPixel * 2; OverlayUtils.SetShapeFormat(this.paintStroke, this.paintFill, shape); canvas.Children.Add(shape); Canvas.SetTop(shape, pixelY - radius); Canvas.SetLeft(shape, pixelX - radius); return(true); }
internal static void RunTest(MapFile mapFile) { // Calculate tile X and Y for lat=0 and lon=0 int tileX = MercatorProjection.LongitudeToTileX(0, ZOOM_LEVEL); int tileY = MercatorProjection.LatitudeToTileY(0, ZOOM_LEVEL); Tile tile = new Tile(tileX, tileY, ZOOM_LEVEL); MapReadResult mapReadResult = mapFile.ReadMapData(tile); mapFile.Close(); Assert.AreEqual(mapReadResult.PointOfInterests.Count, 0); Assert.AreEqual(1, mapReadResult.Ways.Count); Point point1 = new Point(0.0, 0.0); Point point2 = new Point(0.1, 0.0); Point point3 = new Point(0.1, -0.1); Point point4 = new Point(0.0, -0.1); Point[][] latLongsExpected = new Point[][] { new Point[] { point1, point2, point3, point4, point1 } }; Way way = mapReadResult.Ways[0]; // TODO: Was ArrayEquals() Assert.AreEqual(latLongsExpected, way.Points); }
// Computes the amount of latitude degrees for a given distance in pixel at a given zoom level. private static double deltaLat(double deltaPixel, double lat, sbyte zoom, int tileSize) { long mapSize = MercatorProjection.getMapSize(zoom, tileSize); double pixelY = MercatorProjection.latitudeToPixelY(lat, mapSize); double lat2 = MercatorProjection.pixelYToLatitude(pixelY + deltaPixel, mapSize); return(Math.Abs(lat2 - lat)); }
public Vector2 GetUnityMapCenter() { Vector2 gpsMapCenter = GetGPSMapCenter(); double x = MercatorProjection.lonToX(gpsMapCenter.x); double y = MercatorProjection.latToY(gpsMapCenter.y); return(new Vector2((float)x, (float)y)); }
public OsmNode(XmlNode node) { ID = GetAttribute <ulong>("id", node.Attributes); Latitude = GetAttribute <float>("lat", node.Attributes); Longitude = GetAttribute <float>("lon", node.Attributes); X = (float)MercatorProjection.lonToX(Longitude); Y = (float)MercatorProjection.latToY(Latitude); }
private static Vector3[] ParseCoords(Model model, MultiResidenceInputs input) { var rows = ParseCSV(System.IO.File.ReadAllText(input.Site.LocalFilePath)); var points = new List <Vector3>(); double x = 0.0; var xCorrect = 0.0; var yCorrect = 0.0; for (int i = 0; i < rows[0].Count(); i++) { if (i == 0 && double.TryParse(rows[0][0].ToString(), out double lon) && double.TryParse(rows[0][1].ToString(), out double lat)) { xCorrect = MercatorProjection.lonToX(lon); yCorrect = MercatorProjection.lonToX(lat); model.Origin = new Position(lon, lat); } if (i % 2 == 0 && double.TryParse(rows[0][i].ToString(), out lon)) { x = MercatorProjection.lonToX(lon) - xCorrect; } else if (double.TryParse(rows[0][i].ToString(), out lat)) { points.Add(new Vector3(x, MercatorProjection.lonToX(lat) - yCorrect)); } } //double.TryParse(rows[1][0].ToString(), out double parkX); //double.TryParse(rows[1][1].ToString(), out double parkY); //parkX = (MercatorProjection.lonToX(parkX) - xCorrect) * 0.001; //parkY = (MercatorProjection.latToY(parkY) - yCorrect) * 0.001; //double.TryParse(rows[2][0].ToString(), out double busX); //double.TryParse(rows[2][1].ToString(), out double busY); //busX = (MercatorProjection.lonToX(busX) - xCorrect) * 0.001; //busY = (MercatorProjection.latToY(busY) - yCorrect) * 0.001; //double.TryParse(rows[3][0].ToString(), out double schoolX); //double.TryParse(rows[3][1].ToString(), out double schoolY); //schoolX = (MercatorProjection.lonToX(schoolX) - xCorrect) * 0.001; //schoolY = (MercatorProjection.latToY(schoolY) - yCorrect) * 0.001; //model.AddElement(new Mass(new Profile(Elements.Geometry.Polygon.Circle(20.0, 50)), // 0.1, // new Material("park", Palette.Green), // new Transform(parkX, parkY, 0.5))); //model.AddElement(new Mass(new Profile(Elements.Geometry.Polygon.Circle(1.0)), // 5.0, // new Material("bus", Palette.Cobalt), // new Transform(busX, busY, 0.0))); //model.AddElement(new Mass(new Profile(Elements.Geometry.Polygon.Rectangle(30.0, 30.0)), // 5.0, // new Material("school", Palette.Lavender), // new Transform(schoolX, schoolY, 0.0))); return(points.Distinct().ToArray()); }
public OsmNode(XmlNode node) // 读每个node 的id, lat and lon; { ID = GetAttribute <ulong>("id", node.Attributes); Latitude = GetAttribute <float>("lat", node.Attributes);// lat 和 lon 是在球面的,现在要转换成平面 Longitude = GetAttribute <float>("lon", node.Attributes); X = (float)MercatorProjection.lonToX(Longitude); Y = (float)MercatorProjection.latToY(Latitude); }
public void MercatorProjection_Test_Simple() { Point p = new Point(0, 0); MercatorProjection proj = new MercatorProjection(); Point mercPoint = proj.Convert(p); int stop = 0; }
/** * Converts the given GeoPoint into XY coordinates on the current tile. * * @param GeoPoint * the GeoPoint to convert. * @return the XY coordinates on the current tile. */ private MapPoint scaleGeoPoint(GeoPoint GeoPoint) { double pixelX = MercatorProjection.longitudeToPixelX(GeoPoint.Longitude, this.currentTile.ZoomFactor) - this.currentTile.PixelX; double pixelY = MercatorProjection.latitudeToPixelY(GeoPoint.Latitude, this.currentTile.ZoomFactor) - this.currentTile.PixelY; return(new MapPoint((float)pixelX, (float)pixelY)); }
/// <summary> /// Creates an OsmNode with id, latitude and longitude from the given node. /// </summary> /// <param name="node">The from which the values are extracted.</param> public OsmNode(XmlNode node) { id = GetAttribute <ulong>("id", node.Attributes); latitude = GetAttribute <float>("lat", node.Attributes); longitude = GetAttribute <float>("lon", node.Attributes); x = (float)MercatorProjection.lonToX(longitude); y = (float)MercatorProjection.latToY(latitude); }
public void TestMercatorProjection() { LatLng startPosition = new LatLng(48.464717, 35.046183); Vector2 <double> tile = MercatorProjection.LatLngToTile(startPosition, 13); LatLng latLng = MercatorProjection.TileToLatLng(tile, 13); LatLng latLng1 = MercatorProjection.TileToLatLng(tile.X, tile.Y, 13); Assert.IsTrue(startPosition.IsEquals(latLng.Round(6)) && startPosition.IsEquals(latLng1.Round(6))); }
/// <summary> /// sets projection using specific map /// </summary> /// <param name="type"></param> /// <param name="Projection"></param> public void AdjustProjection(MapType type, ref PureProjection Projection, out int maxZoom) { maxZoom = MaxZoom; if (false == (Projection is MercatorProjection)) { Projection = new MercatorProjection(); maxZoom = GMaps.Instance.MaxZoom; } }
/// <summary> /// Constructor. /// </summary> /// <param name="node">Xml node</param> public OsmNode(XmlNode node) { // Get the attribute values ID = GetAttribute <ulong>("id", node.Attributes); Latitude = GetAttribute <float>("lat", node.Attributes); Longitude = GetAttribute <float>("lon", node.Attributes); // Calculate the position in Unity units X = (float)MercatorProjection.lonToX(Longitude); Y = (float)MercatorProjection.latToY(Latitude); }
/// <summary> /// Instantiate a new point from a coordinate array /// </summary> /// <param name="projection">The projection owning these coordinates</param> /// <param name="xy">List of xy coordinates</param> /// <exception cref="IndexOutOfRangeException"></exception> public EuclidianCoordinate(MercatorProjection projection, IReadOnlyList <double> xy) { if (xy.Count != 2) { throw new IndexOutOfRangeException(Properties.Resources.COORD_ARRAY_MUST_BE_2DIM); } Projection = projection; X = xy[0]; Y = xy[1]; }
public void CalculateVertices(BoundingBox box) { LeftBottom = new Vector3((float)(MercatorProjection.lonToX(box.West)), 0, (float)(MercatorProjection.latToY(box.South))); LeftTop = new Vector3((float)(MercatorProjection.lonToX(box.West)), 0, (float)(MercatorProjection.latToY(box.North))); RightBottom = new Vector3((float)(MercatorProjection.lonToX(box.East)), 0, (float)(MercatorProjection.latToY(box.South))); RightTop = new Vector3((float)(MercatorProjection.lonToX(box.East)), 0, (float)(MercatorProjection.latToY(box.North))); }
public SqlPointRepository(string connectionString) { if (string.IsNullOrEmpty(connectionString)) { throw new ArgumentNullException("connection string"); } _connectionString = connectionString; _projection = new MercatorProjection(); }
/// <summary> /// Constructor /// </summary> public NodeFactory(XmlNode node) { id = GetAttributes <ulong>("id", node.Attributes); // visible = GetAttributes<bool>("visible", node.Attributes); lat = GetAttributes <float>("lat", node.Attributes); lon = GetAttributes <float>("lon", node.Attributes); // Calculate x and y coordinates x = (float)MercatorProjection.lonToX(lon); y = (float)MercatorProjection.latToY(lat); }
public OsmBounds(XmlNode node) { MinLat = GetAttribute <float>("minlat", node.Attributes); MaxLat = GetAttribute <float>("maxlat", node.Attributes); MinLon = GetAttribute <float>("minlon", node.Attributes); MaxLon = GetAttribute <float>("maxlon", node.Attributes); float x = (float)(MercatorProjection.lonToX(MaxLon) + MercatorProjection.lonToX(MinLon)) / 2; float y = (float)(MercatorProjection.latToY(MaxLat) + MercatorProjection.latToY(MinLat)) / 2; Centre = new Vector3(x, 0, y); }
private void Start() { routeNavigation = new RouteNavigation(lineRenderer, directLineRenderer, this); toolBox = ToolBox.Instance; directLineRenderer.enabled = true; toolBox.loadingScreen.enable(true); userGPSLocation = new GeoCoordinate(); projection = new MercatorProjection(zoom); mapImageSize = MapSize(Screen.width, Screen.height); mapExpandRatio = Screen.width / mapImageSize.x; mapLimit = new Vector2(Screen.width / 4, Screen.height / 4); toolBox.sensorManager.gps.AddObserver(this); toolBox.sensorManager.orientation.AddObserver(this); toolBox.download.AddObserver(this); }
private void Zoom() { projection = new MercatorProjection(zoom); toolBox.download.EnqueueStaticMap(mapCenterGPS, zoom, SCALE, mapImageSize.x, mapImageSize.y); }
float[] getCorners(G_LatLng center, float zoom, float mapWidth, float mapHeight) { float scale = Mathf.Pow(2, zoom); MercatorProjection proj = new MercatorProjection(); G_Point centerPx = proj.fromLatLngToPoint(center); //G_LatLng centerPx = new G_LatLng (0, 0); G_Point SWPoint = new G_Point(centerPx.x-(mapWidth/2)/scale, centerPx.y+(mapHeight/2)/scale); G_LatLng SWLatLon = proj.fromPointToLatLng(SWPoint); G_Point NEPoint = new G_Point(centerPx.x+(mapWidth/2)/scale, centerPx.y-(mapHeight/2)/scale); G_LatLng NELatLon = proj.fromPointToLatLng(NEPoint); return new float[]{NELatLon.lat, NELatLon.lng, -SWLatLon.lat, SWLatLon.lng}; // north east south west }