WorldToTilePos() public method

public WorldToTilePos ( double lon, double lat, int zoom ) : DVector2
lon double
lat double
zoom int
return DVector2
Ejemplo n.º 1
0
		public static LinesGisLayer GenerateGrid(Game Game, DVector2 leftTop, DVector2 rightBottom, int dimX, int dimY, Color color, MapProjection projection, bool keepQuad = false)
		{
			var lt = projection.WorldToTilePos(leftTop.X,		leftTop.Y, 0);
			var rb = projection.WorldToTilePos(rightBottom.X,	rightBottom.Y, 0);

			if (keepQuad) {
				rb.Y = lt.Y + (rb.X - lt.X);
			}

			double stepX = Math.Abs(rb.X - lt.X) / (dimX - 1);
			double stepY = Math.Abs(rb.Y - lt.Y) / (dimY - 1);


			List<Gis.GeoPoint> points = new List<Gis.GeoPoint>();
			
			// Too lazy
			for (int row = 1; row < dimY-1; row++) {
				for (int col = 0; col < dimX-1; col++) {
					var coords0 = projection.TileToWorldPos(lt.X + stepX * col,		lt.Y + stepY * row, 0);
					var coords1 = projection.TileToWorldPos(lt.X + stepX * (col+1), lt.Y + stepY * row, 0);

					points.Add(new Gis.GeoPoint {
						Lon		= DMathUtil.DegreesToRadians(coords0.X),
						Lat		= DMathUtil.DegreesToRadians(coords0.Y),
						Color	= color
					});
					points.Add(new Gis.GeoPoint {
						Lon		= DMathUtil.DegreesToRadians(coords1.X),
						Lat		= DMathUtil.DegreesToRadians(coords1.Y),
						Color	= color
					});
				} 
			}
			for (int col = 1; col < dimX-1; col++) {
				for (int row = 0; row < dimY-1; row++) {
					var coords0 = projection.TileToWorldPos(lt.X + stepX * col,	lt.Y + stepY * row, 0);
					var coords1 = projection.TileToWorldPos(lt.X + stepX * col, lt.Y + stepY * (row+1), 0);

					points.Add(new Gis.GeoPoint {
						Lon		= DMathUtil.DegreesToRadians(coords0.X),
						Lat		= DMathUtil.DegreesToRadians(coords0.Y),
						Color	= color
					});
					points.Add(new Gis.GeoPoint {
						Lon		= DMathUtil.DegreesToRadians(coords1.X),
						Lat		= DMathUtil.DegreesToRadians(coords1.Y),
						Color	= color
					});
				} 
			}

			var linesLayer = new LinesGisLayer(Game, points.Count);
			Array.Copy(points.ToArray(), linesLayer.PointsCpu, points.Count);
			linesLayer.UpdatePointsBuffer();
			linesLayer.Flags = (int)(LineFlags.THIN_LINE);

			return linesLayer;
		}
Ejemplo n.º 2
0
		public static HeatMapLayer GenerateHeatMapWithRegularGrid(Game engine, double left, double right, double top, double bottom, int density, int dimX, int dimY, MapProjection projection)
		{
			int[]			indexes;
			Gis.GeoPoint[]	vertices;


			var leftTop		= projection.WorldToTilePos(left, top, 0);
			var rightBottom = projection.WorldToTilePos(right, bottom, 0);

			double newleft		= leftTop.X;
			double newright		= rightBottom.X;
			double newtop		= leftTop.Y;
			double newbottom	= newtop + (newright - newleft);

			var newRightBottom = projection.TileToWorldPos(newright, newbottom, 0);
			bottom = newRightBottom.Y;

			CalculateVertices(out vertices, out indexes, density, left, right, top, bottom, projection);

			return new HeatMapLayer(engine, vertices, indexes, dimX, dimY, false)
			{
				Left		= newleft,
				Right		= newright,
				Top			= newtop,
				Bottom		= newbottom,
				GridDensity = density,
				Projection	= projection
			};
		}