Implemented FlatMap fullrender + required clientlib.
This commit is contained in:
parent
e4fb902420
commit
9eb2d1a6a0
2 changed files with 81 additions and 21 deletions
|
|
@ -18,41 +18,59 @@ import org.dynmap.debug.Debug;
|
||||||
import org.dynmap.kzedmap.KzedMap;
|
import org.dynmap.kzedmap.KzedMap;
|
||||||
|
|
||||||
public class FlatMap extends MapType {
|
public class FlatMap extends MapType {
|
||||||
|
|
||||||
public FlatMap(Map<String, Object> configuration) {
|
public FlatMap(Map<String, Object> configuration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapTile[] getTiles(Location l) {
|
public MapTile[] getTiles(Location l) {
|
||||||
return new MapTile[] {
|
return new MapTile[] { new FlatMapTile(l.getWorld(), this, (int) Math.floor(l.getBlockX() / 128.0), (int) Math.floor(l.getBlockZ() / 128.0), 128) };
|
||||||
new FlatMapTile(l.getWorld(), this, (int)Math.floor(l.getBlockX() / 128.0), (int)Math.floor(l.getBlockZ() / 128.0), 128)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapTile[] getAdjecentTiles(MapTile tile) {
|
public MapTile[] getAdjecentTiles(MapTile tile) {
|
||||||
// TODO Auto-generated method stub
|
FlatMapTile t = (FlatMapTile) tile;
|
||||||
return null;
|
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
|
@Override
|
||||||
public DynmapChunk[] getRequiredChunks(MapTile tile) {
|
public DynmapChunk[] getRequiredChunks(MapTile tile) {
|
||||||
// TODO Auto-generated method stub
|
FlatMapTile t = (FlatMapTile) tile;
|
||||||
return null;
|
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
|
@Override
|
||||||
public boolean render(MapTile tile, File outputFile) {
|
public boolean render(MapTile tile, File outputFile) {
|
||||||
FlatMapTile t = (FlatMapTile)tile;
|
FlatMapTile t = (FlatMapTile) tile;
|
||||||
World w = t.getWorld();
|
World w = t.getWorld();
|
||||||
|
|
||||||
|
boolean rendered = false;
|
||||||
BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB);
|
BufferedImage im = new BufferedImage(t.size, t.size, BufferedImage.TYPE_INT_RGB);
|
||||||
WritableRaster r = im.getRaster();
|
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++) {
|
for (int y = 0; y < t.size; y++) {
|
||||||
int mx = x+t.x*t.size;
|
int mx = x + t.x * t.size;
|
||||||
int mz = y+t.y*t.size;
|
int mz = y + t.y * t.size;
|
||||||
int my = w.getHighestBlockYAt(mx, mz) - 1;
|
int my = w.getHighestBlockYAt(mx, mz) - 1;
|
||||||
int blockType = w.getBlockTypeIdAt(mx, my, mz);
|
int blockType = w.getBlockTypeIdAt(mx, my, mz);
|
||||||
Color[] colors = KzedMap.colors.get(blockType);
|
Color[] colors = KzedMap.colors.get(blockType);
|
||||||
|
|
@ -65,8 +83,9 @@ public class FlatMap extends MapType {
|
||||||
c.getRed(),
|
c.getRed(),
|
||||||
c.getGreen(),
|
c.getGreen(),
|
||||||
c.getBlue() });
|
c.getBlue() });
|
||||||
|
rendered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ImageIO.write(im, "png", outputFile);
|
ImageIO.write(im, "png", outputFile);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
@ -75,22 +94,22 @@ public class FlatMap extends MapType {
|
||||||
Debug.error("Failed to save image (NullPointerException): " + outputFile.getPath(), e);
|
Debug.error("Failed to save image (NullPointerException): " + outputFile.getPath(), e);
|
||||||
}
|
}
|
||||||
im.flush();
|
im.flush();
|
||||||
return false;
|
return rendered;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FlatMapTile extends MapTile {
|
public class FlatMapTile extends MapTile {
|
||||||
|
|
||||||
public int x;
|
public int x;
|
||||||
public int y;
|
public int y;
|
||||||
public int size;
|
public int size;
|
||||||
|
|
||||||
public FlatMapTile(World world, FlatMap map, int x, int y, int size) {
|
public FlatMapTile(World world, FlatMap map, int x, int y, int size) {
|
||||||
super(world, map);
|
super(world, map);
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
return "flat_" + size + "_" + x + "_" + y + ".png";
|
return "flat_" + size + "_" + x + "_" + y + ".png";
|
||||||
|
|
|
||||||
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…
Add table
Add a link
Reference in a new issue