Add "center" config option

This option allows you to specify your own initial center for a
tileset, which is useful if your map is extremely asymmetric or
you don't really care about what's around the spawn.

Future work needs to be done on the JS side in order to fix the
fromWorldToLatLng and friends, as they're currently off by -24 in X
and +24 in Z direction.

Closes #1350.
This commit is contained in:
Nicolas F 2019-07-06 19:06:15 +02:00
parent 5b0430f94b
commit 204bcd0310
7 changed files with 31 additions and 5 deletions

View File

@ -951,6 +951,16 @@ Other HTML/JS output options
**Default:** ``#1a1a1a``
``center``
This is allows you to specify a list or a tuple of Minecraft world coordinates
that should be used as the map's default center, e.g. ``[800, 64, -334]``.
You may also specify only two coordinates, in case they will be interpreted as
X and Z coordinates, and Y is assumed to be ``64`` (sea level).
**Default:** The coordinates of your spawn, or ``[0, 64, 0]`` if the regionset
has no spawn.
Map update behavior
~~~~~~~~~~~~~~~~~~~

View File

@ -555,7 +555,7 @@ def main():
"name", "imgformat", "renderchecks", "rerenderprob", "bgcolor", "defaultzoom",
"imgquality", "imglossless", "optimizeimg", "rendermode", "worldname_orig", "title",
"dimension", "changelist", "showspawn", "overlay", "base", "poititle", "maxzoom",
"showlocationmarker", "minzoom"])
"showlocationmarker", "minzoom", "center"])
tileSetOpts.update({"spawn": w.find_true_spawn()}) # TODO find a better way to do this
for rset in rsets:
tset = tileset.TileSet(w, rset, assetMrg, tex, tileSetOpts, tileset_dir)

View File

@ -128,7 +128,6 @@ top-level directory.
dump['map']['debug'] = True
dump['map']['cacheTag'] = str(int(time.time()))
dump['map']['north_direction'] = 'lower-left' # only temporary
dump['map']['center'] = [-314, 67, 94]
dump['map']['controls'] = {
'pan': True,
'zoom': True,

View File

@ -422,8 +422,8 @@ overviewer.util = {
myLayer["tileSetConfig"] = obj;
if (typeof(obj.spawn) == "object") {
var latlng = overviewer.util.fromWorldToLatLng(obj.spawn[0], obj.spawn[1], obj.spawn[2], obj);
if (typeof(obj.center) == "object") {
var latlng = overviewer.util.fromWorldToLatLng(obj.center[0], obj.center[1], obj.center[2], obj);
overviewer.collections.centers[obj.world] = [ latlng, obj.defaultZoom ];
} else {
overviewer.collections.centers[obj.world] = [ [0, 0], obj.defaultZoom ];

View File

@ -93,6 +93,7 @@ renders = Setting(required=True, default=OrderedDict(),
"minzoom": Setting(required=False, validator=validateInt, default=0),
"manualpois": Setting(required=False, validator=validateManualPOIs, default=[]),
"showlocationmarker": Setting(required=False, validator=validateBool, default=True),
"center": Setting(required=False, validator=validateCoords, default=None),
# Remove this eventually (once people update their configs)
"worldname": Setting(required=False, default=None,
validator=error("The option 'worldname' is now called 'world'. Please update your config files")),

View File

@ -308,6 +308,20 @@ def validateManualPOIs(d):
return d
def validateCoords(c):
if not isinstance(c, (list, tuple)):
raise ValidationException("Your coordinates '{}' are not a list or a tuple.".format(c))
if len(c) not in [2, 3]:
raise ValidationException("'{}' is not a valid list or tuple of coordinates, "
"because we expect either 2 or 3 elements.".format(c))
if len(c) == 2:
x, z = [validateInt(i) for i in c]
y = 64
else:
x, y, z = [validateInt(i) for i in c]
return (x, y, z)
def make_dictValidator(keyvalidator, valuevalidator):
"""Compose and return a dict validator -- a validator that validates each
key and value in a dictionary.

View File

@ -589,7 +589,9 @@ class TileSet(object):
imgextension=self.imgextension,
isOverlay=isOverlay,
poititle=self.options.get("poititle"),
showlocationmarker=self.options.get("showlocationmarker")
showlocationmarker=self.options.get("showlocationmarker"),
center=(self.options.get("center") or self.options.get("spawn")
or [0, 64, 0])
)
d['maxZoom'] = self.options.get('maxzoom', self.treedepth)
if d['maxZoom'] < 0: