mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-25 10:07:37 +01:00
Implemented FlatMap fullrender + required clientlib.
This commit is contained in:
parent
1755411545
commit
f4f4a33b8b
@ -24,35 +24,53 @@ public class FlatMap extends MapType {
|
||||
|
||||
@Override
|
||||
public MapTile[] getTiles(Location l) {
|
||||
return new MapTile[] {
|
||||
new FlatMapTile(l.getWorld(), this, (int)Math.floor(l.getBlockX() / 128.0), (int)Math.floor(l.getBlockZ() / 128.0), 128)
|
||||
};
|
||||
return new MapTile[] { new FlatMapTile(l.getWorld(), this, (int) Math.floor(l.getBlockX() / 128.0), (int) Math.floor(l.getBlockZ() / 128.0), 128) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapTile[] getAdjecentTiles(MapTile tile) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
FlatMapTile t = (FlatMapTile) tile;
|
||||
World w = t.getWorld();
|
||||
int x = t.x;
|
||||
int y = t.y;
|
||||
int s = t.size;
|
||||
return new MapTile[] {
|
||||
new FlatMapTile(w, this, x, y - 1, s),
|
||||
new FlatMapTile(w, this, x + 1, y, s),
|
||||
new FlatMapTile(w, this, x, y + 1, s),
|
||||
new FlatMapTile(w, this, x - 1, y, s) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public DynmapChunk[] getRequiredChunks(MapTile tile) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
FlatMapTile t = (FlatMapTile) tile;
|
||||
int chunksPerTile = t.size / 16;
|
||||
int sx = t.x * chunksPerTile;
|
||||
int sz = t.y * chunksPerTile;
|
||||
|
||||
DynmapChunk[] result = new DynmapChunk[chunksPerTile * chunksPerTile];
|
||||
int index = 0;
|
||||
for (int x = 0; x < chunksPerTile; x++)
|
||||
for (int z = 0; z < chunksPerTile; z++) {
|
||||
result[index] = new DynmapChunk(sx + x, sz + z);
|
||||
index++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean render(MapTile tile, File outputFile) {
|
||||
FlatMapTile t = (FlatMapTile)tile;
|
||||
FlatMapTile t = (FlatMapTile) tile;
|
||||
World w = t.getWorld();
|
||||
|
||||
boolean rendered = false;
|
||||
BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB);
|
||||
WritableRaster r = im.getRaster();
|
||||
|
||||
for(int x = 0; x < t.size; x++)
|
||||
for (int x = 0; x < t.size; x++)
|
||||
for (int y = 0; y < t.size; y++) {
|
||||
int mx = x+t.x*t.size;
|
||||
int mz = y+t.y*t.size;
|
||||
int mx = x + t.x * t.size;
|
||||
int mz = y + t.y * t.size;
|
||||
int my = w.getHighestBlockYAt(mx, mz) - 1;
|
||||
int blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||
Color[] colors = KzedMap.colors.get(blockType);
|
||||
@ -65,6 +83,7 @@ public class FlatMap extends MapType {
|
||||
c.getRed(),
|
||||
c.getGreen(),
|
||||
c.getBlue() });
|
||||
rendered = true;
|
||||
}
|
||||
|
||||
try {
|
||||
@ -75,7 +94,7 @@ public class FlatMap extends MapType {
|
||||
Debug.error("Failed to save image (NullPointerException): " + outputFile.getPath(), e);
|
||||
}
|
||||
im.flush();
|
||||
return false;
|
||||
return rendered;
|
||||
}
|
||||
|
||||
public class FlatMapTile extends MapTile {
|
||||
|
41
web/flatmap.js
Normal file
41
web/flatmap.js
Normal file
@ -0,0 +1,41 @@
|
||||
function FlatProjection() {}
|
||||
FlatProjection.prototype = {
|
||||
fromLatLngToPoint: function(latLng) {
|
||||
return new google.maps.Point(latLng.lat()*128.0, latLng.lng()*128.0);
|
||||
},
|
||||
fromPointToLatLng: function(point) {
|
||||
return new google.maps.LatLng(point.x/128.0, point.y/128.0);
|
||||
},
|
||||
fromWorldToLatLng: function(x, y, z) {
|
||||
return new google.maps.LatLng(x / 128.0, z / 128.0);
|
||||
}
|
||||
};
|
||||
|
||||
function FlatMapType(configuration) { $.extend(this, configuration); }
|
||||
FlatMapType.prototype = $.extend(new DynMapType(), {
|
||||
constructor: FlatMapType,
|
||||
projection: new FlatProjection(),
|
||||
tileSize: new google.maps.Size(128.0, 128.0),
|
||||
minZoom: 0,
|
||||
maxZoom: 0,
|
||||
getTile: function(coord, zoom, doc) {
|
||||
var tileName;
|
||||
var tile = $('<img/>')
|
||||
.attr('src', this.dynmap.getTileUrl(tileName = 'flat_128_' + coord.x + '_' + coord.y + '.png'))
|
||||
.error(function() { tile.hide(); })
|
||||
.bind('load', function() { tile.show(); })
|
||||
.css({
|
||||
width: '128px',
|
||||
height: '128px',
|
||||
borderStyle: 'none'
|
||||
})
|
||||
.hide();
|
||||
this.dynmap.registerTile(this, tileName, tile);
|
||||
//this.dynmap.unregisterTile(this, tileName);
|
||||
return tile.get(0);
|
||||
},
|
||||
updateTileSize: function(zoom) {
|
||||
}
|
||||
});
|
||||
|
||||
maptypes.FlatMapType = function(configuration) { return new FlatMapType(configuration); };
|
Loading…
Reference in New Issue
Block a user