When i remove a tile with the coords (example: X: 15, Y: 9) with
TiledMapTileLayer tiledMapTileLayer = (TiledMapTileLayer)map.getLayers().get(0);
tiledMapTileLayer.setCell(15, 9, null);
I notice that actually the wrong tile is removed from the map. Instead tile with the coords X:15 Y: 6 is being removed. What am i doing wrong?
I believe this would be due to libgdx inverting the map to match better with their coordinate system. If your map is 16 tiles high, trying to remove tile at Y: 9 will result in removal of tile at Y: 16 - 9 - 1 = 6.
If you want to copy a Y coordinate from Tiled and put it in your code, you'll in general need to apply the following conversion to turn it into the same location in libgdx:
int y = tileLayer.getHeight() - 1 - [Y coordinate from Tiled];
Related
Is there a method similar to ClientToWorld, that can give me the X,Y world coords if I provide it with X,Y screen coords?
I know that ClientToWorld gives me a Z coord of where it interacts with the model, but I am happy to have no Z coord as it will not raycast to a point on the model.
How about Viewer3dImpl.clientToViewport?
let coords = viewer.impl.clientToViewport(client.x, client.y); //c.Vector3 {x: -0.9696521095484826, y: 0.9200779727095516, z: 1 (always 1)}
let finalCoords = coords.unproject(viewer.impl.camera) //c.Vector3 {x: -26.379134321221724, y: 5.162777223710702, z: 1.3846547842336627}
See unofficial doc (not authoritative & subject to change w/o notice) for this method here
I'm trying to draw an arbitrary polygon with a transformed texture with Graphics API .
Here's what I'm trying to do in 3 steps:
First, I have a texture (as a BitmapData)
Second, Transform the texture - Tile it and rotate it around x, y or z axis. (y-axis for now).
Third, Draw a polygon using the transformed texture.
I could rotate it around z-axis with the code below:
var gr:Graphics = sp.graphics;
gr.clear();
var mat:Matrix = new Matrix();
mat.scale( 0.5, 0.5 );
mat.rotate( angle );
gr.beginBitmapFill( bd, mat, true, true );
gr.moveTo( points[0].x, points[0].y );
for ( var lp1:int = 1; lp1 < points.length; lp1++ )
gr.lineTo( points[lp1].x, points[lp1].y );
gr.lineTo( points[0].x, points[0].y );
gr.endFill();
But I couldn't rotate the texture around x or y axis as it requires some sort of projection I guess.
I thought about drawing a rotated Bitmap object onto a BitmapData and using it as a texture:
var bmp:Bitmap = new Bitmap( bd );
bmp.rotationY = angle;
var transformedBd:BitmapData = new BitmapData( 256, 256, true, 0 );
transformedBd.draw( bmp );
… and call gr.beginBitmapFill() with the transformedBd …
But with this code, the texture won't be tiled.
I also looked at drawTriangles() method but AFIK, it only let me draw a rotated polygon, not a polygon with rotated texture.
If anyone has insights on this issue, please share.
Any help will be greatly appreciated!
Perhaps you can:
put your 2D Texture inside a Sprite or other container
3D transform that container, for example by using
myContainer.rotationX = 20;
myContainer.rotationY = 200;
3 - then you create a new BitmapData()
4 - and you DRAW the entire myContainer into the bitmapdata.
myBitmapData.draw(myContainer, myMatrix, myColorTransform, blendMode, myRectangle, smooth);
5 - and finally you delete the original 2D texture and myContainer.
Voila, you now have a 3d transformed texture inside a single bitmapdata.
I'm trying to develop heat map, now initially I would have to draw the intensity mask, and since I'm using GWT so I have randomly generated some coordinates and placed my circles ( with required gradience ) at those locations so the output comes out to be circles overlapping each other. And If I look at the intensity mask from Dylan Vester, it comes to be very smooth How can I draw my heat map ?? Also how the output is achieved similar to Dylan Vester?? Question also is if I'm drawing circles then how to decide the intensity at the intersection of two or more circles, how they have achieved ?? Here is my code
// creating the object for the heat points
Heat_Point x = new Heat_Point();
// Variables for random locations
int Min = 1,Max = 300;
int randomx,randomy;
// Generating set of random values
for( int i = 0 ; i < 100 ; i++ ) {
// Generating random x and y coordinates
randomx = Min + (int)(Math.random() * ((Max - Min) + 1));
randomy = Min + (int)(Math.random() * ((Max - Min) + 1));
// Drawing the heat points at generated locations
x.Draw_Heatpoint(c1, randomx, randomy);
}
And Here is how I'm plotting my heat point that is Heat_Point class
Context con1 = c1.getContext2d(); // c1 is my canvas
CanvasGradient x1;
x1 = ((Context2d) con1).createRadialGradient(x,y,10,x,y,20);
x1.addColorStop(0,"black");
x1.addColorStop(1,"white");
((Context2d) con1).beginPath();
((Context2d) con1).setFillStyle(x1);
((Context2d) con1).arc(x,y,20, 0, Math.PI * 2.0, true);
((Context2d) con1).fill();
((Context2d) con1).closePath();`
here I was supposed to add some images but I didn't have enough reputation :D :P
I took a quick look at HeatmapJS (http://www.patrick-wied.at/static/heatmapjs/) and it seems he uses radial gradients (like you have above) and he also uses opacity and a color filter called "multiply blend" to smooth out the intensity of the colors in the heat map.
His code is quite impressive. It's open source, so you might want to check it out!
I'm using a DisplacementMapFilter to created a globe-like effect on a flat map. My problem is, I also want to sync some labels to this map. I have the x/y coordinates for their locations on the flat map, but I need to map them to the now-displaced image.
I would like to be able to do this using the BitmapData that contains the displacement map, so that changing the Bitmap changes both the displacement filter and the label locations. Also, the labels will not be static, and accuracy is fairly important.
There is a formula in DisplacementMapFilter reference:
dstPixel[x, y] =
srcPixel[
x + ((componentX(x, y) - 128) * scaleX) / 256,
y + ((componentY(x, y) - 128) *scaleY) / 256)
]
componentX/Y are color channels in the bitmap (you can bind any channel to coordinates).
As I understand, you need to shift map labels as filter would do. Just take label coordinates (x, y), sample source bitmap with getPixel32(x, y). Then you need to figure out which bytes to take for x, y - I guess by default it would be R, G components, respectively. Then use formula to get displaced label coordinates.
Note: getPixel32 returns uint color in ARGB format. Use shift operator (>>) to get color components:
uint ARGB = bitmap.getPixel32(x, y);
int B = ARGB & 0xFF;
int G = (ARGB >> 8) & 0xFF;
int R = (ARGB >> 16) & 0xFF;
This is with reference to Google Tile Map or Bing Maps. Is it possible to get Tile Count, Tile X, Tile Y details without specifying zoom Level (or LevelOfDetails) with any kind of internal calculations?
Client will give just Coordinates P1 and P2 and ask for a Tile Map and Bound Box, etc.
Shilpa
Each tile is 256 pixels by 256 pixels.
Zoom level 0 is 1 tile. (1 x 1)
Zoom level 1 is 4 tiles. (2 x 2)
Zoom level 2 is 16 tiles. (4 x 4)
Zoom level 3 is 64 tiles. (8 x 8)
Zoom level 4 is 256 tiles (16 x 16)
The x and y counts are doubled for each zoom level. Per 88ad's comment, the formula for the number of tiles is (2^zoom x 2^zoom).
I hope you can do the rest of the math through zoom level 18. To save space, ocean tiles aren't stored. They're created as a response to the request.
At zoom level 3, the tiles are numbered from 0 to 7 in the x direction (longitude) and numbered from 0 to 7 in the y direction (latitude).
The tiles start on the American side of near the International Date Line (longitude -180 or +180). The tile 0,0 starts at about latitude 70 north.
See the Wikipedia article Mercator Projection for more details about how a sphere is mapped to a plane. The calculations for converting longitude and latitude to x and y coordinates are in the Wikipedia article.
You can map any point on the Mercator Projection to a tile set. A tile set is the set of tiles at a zoom level. You have to know the zoom level to know which tile set to access and to calculate which tile in the tile set to retrieve and display.
This blog post, Google Mapping, gives the formula for converting (latitude, longitude, zoom) to (x, y, zoom), where x and y represent the tile from the zoom set.
You may want to check out wiki of OSM tilenames. They are almost the same as google tiles except of y axis direction. Description with a lot of code examples is here: http://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
If you have a bounding box, you can use this python function for finding zoom level (or similar function in your programming language choice):
def level_dic():
'''
http://wiki.openstreetmap.org/wiki/Zoom_levels
'''
data = {0: 360.0,
1: 180.0,
2: 90.0,
3: 45.0,
4: 22.5,
5: 11.25,
6: 5.625,
7: 2.813,
8: 1.406,
9: 0.703,
10: 0.352,
11: 0.176,
12: 0.088,
13: 0.044,
14: 0.022,
15: 0.011,
16: 0.005,
17: 0.003,
18: 0.001,
19: 0.0005}
return data
def getzoom(self):
data = level_dic() # our presets
a, b, c, d = bbox
r = 3
dne = abs(round(float(c) - float(a), r)) # ne: North East point
mylist = [round(i, r) for i in data.values()] + [dne]
new = sorted(mylist, reverse=True)
return new.index(dne)
I used this reference. The rest is simple. You need to use Slippy_map_tilenames.