From 7c5a809e713184a316d1ab4e2bd2395b731637da Mon Sep 17 00:00:00 2001 From: CounterPillow Date: Fri, 20 May 2011 14:18:05 +0200 Subject: [PATCH 1/4] Added maptypes to live hash updating, implemented some checks to catch incomplete hashes --- web_assets/overviewer.js | 64 +++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/web_assets/overviewer.js b/web_assets/overviewer.js index 4cbfc11..ae8b0b7 100644 --- a/web_assets/overviewer.js +++ b/web_assets/overviewer.js @@ -225,27 +225,28 @@ var overviewer = { overviewer.collections.mapTypes[i].name, overviewer.collections.mapTypes[i]); } - - // Make the link again whenever the map changes + + // Jump to the hash if given + overviewer.util.initHash(); + + // Add live hash update listeners + // Note: It is important to add them after jumping to the hash + google.maps.event.addListener(overviewer.map, 'dragend', function() { + overviewer.util.updateHash(); + }); + + google.maps.event.addListener(overviewer.map, 'zoom_changed', function() { + overviewer.util.updateHash(); + }); + + // Make the link again whenever the map changes google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function() { $('#'+overviewerConfig.CONST.mapDivId).css( 'background-color', overviewer.util.getMapTypeBackgroundColor( overviewer.map.getMapTypeId())); + //smuggled this one in here for maptypeid hash generation --CounterPillow + overviewer.util.updateHash(); }); - - // Add live hash update listener - google.maps.event.addListener(overviewer.map, 'dragend', function() { - overviewer.util.updateHash(); - }); - google.maps.event.addListener(overviewer.map, 'zoom_changed', function() { - overviewer.util.updateHash(); - }); - // Jump to the hash if given - overviewer.util.initHash(); - - - // We can now set the map to use the 'coordinate' map type - overviewer.map.setMapTypeId(overviewer.util.getDefaultMapTypeId()); }, /** * Read through overviewer.collections.markerDatas and create Marker @@ -782,6 +783,8 @@ var overviewer = { 'initHash': function() { if(window.location.hash.split("/").length > 1) { overviewer.util.goToHash(); + // Clean up the hash. + overviewer.util.updateHash(); // Add a marker indicating the user-supplied position var coordinates = overviewer.util.fromLatLngToWorld(overviewer.map.getCenter().lat(), overviewer.map.getCenter().lng()); @@ -791,14 +794,15 @@ var overviewer = { 'y': coordinates.y, 'z': coordinates.z, 'type': 'querypos'}]); - } + } }, - 'setHash': function(x, y, z, zoom) { - window.location.replace("#/" + Math.floor(x) + "/" + Math.floor(y) + "/" + Math.floor(z) + "/" + zoom); + 'setHash': function(x, y, z, zoom, maptype) { + window.location.replace("#/" + Math.floor(x) + "/" + Math.floor(y) + "/" + Math.floor(z) + "/" + zoom + "/" + maptype); }, 'updateHash': function() { var coordinates = overviewer.util.fromLatLngToWorld(overviewer.map.getCenter().lat(), overviewer.map.getCenter().lng()); var zoom = overviewer.map.getZoom(); + var maptype = overviewer.map.getMapTypeId(); if (zoom == overviewerConfig.map.maxZoom) { zoom = 'max'; } else if (zoom == overviewerConfig.map.minZoom) { @@ -807,12 +811,22 @@ var overviewer = { // default to (map-update friendly) negative zooms zoom -= overviewerConfig.map.maxZoom; } - overviewer.util.setHash(coordinates.x, coordinates.y, coordinates.z, zoom); + overviewer.util.setHash(coordinates.x, coordinates.y, coordinates.z, zoom, maptype); }, 'goToHash': function() { + // Note: the actual data begins at coords[1], coords[0] is empty. var coords = window.location.hash.split("/"); var latlngcoords = overviewer.util.fromWorldToLatLng(parseInt(coords[1]), parseInt(coords[2]), parseInt(coords[3])); - var zoom = coords[4]; + var zoom; + var maptype = ''; + // The if-statements try to prevent unexpected behaviour when using incomplete hashes, e.g. older links + if (coords.length > 4) { + zoom = coords[4]; + } + if (coords.length > 5) { + maptype = coords[5]; + } + if (zoom == 'max') { zoom = overviewerConfig.map.maxZoom; } else if (zoom == 'min') { @@ -827,6 +841,14 @@ var overviewer = { zoom = overviewerConfig.map.defaultZoom; } } + // If the maptype isn't set, set the default one. + if (maptype == '') { + // We can now set the map to use the 'coordinate' map type + overviewer.map.setMapTypeId(overviewer.util.getDefaultMapTypeId()); + } else { + overviewer.map.setMapTypeId(maptype); + } + overviewer.map.setCenter(latlngcoords); overviewer.map.setZoom(zoom); }, From f82911e04e607894a922d9de9c579f4a80842ba7 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Tue, 24 May 2011 18:22:08 -0400 Subject: [PATCH 2/4] added overview map control (tiny, zoomed out map in corner) (hidden by default) --- web_assets/overviewer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web_assets/overviewer.js b/web_assets/overviewer.js index 4cbfc11..13bd106 100644 --- a/web_assets/overviewer.js +++ b/web_assets/overviewer.js @@ -194,6 +194,7 @@ var overviewer = { }, mapTypeId: overviewer.util.getDefaultMapTypeId(), streetViewControl: false, + overviewMapControl: true, zoomControl: overviewerConfig.map.controls.zoom, backgroundColor: overviewer.util.getMapTypeBackgroundColor( overviewer.util.getDefaultMapTypeId()) From dc12ba2751e48a82ea610574569f4e1b7fdf2892 Mon Sep 17 00:00:00 2001 From: aheadley Date: Thu, 26 May 2011 16:35:47 -0400 Subject: [PATCH 3/4] fixed issue #374 --- web_assets/overviewerConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_assets/overviewerConfig.js b/web_assets/overviewerConfig.js index acb4529..ce38479 100644 --- a/web_assets/overviewerConfig.js +++ b/web_assets/overviewerConfig.js @@ -79,7 +79,7 @@ var overviewerConfig = { * Set to true to turn on debug mode, which adds a grid to the map along * with co-ordinates and a bunch of console output. */ - 'debug': false, + 'debug': false }, /** * Group definitions for objects that are partially selectable (signs and From d3551324b7560f54344ee6691b9b3c3b6e09794c Mon Sep 17 00:00:00 2001 From: Andrew Chin Date: Thu, 26 May 2011 20:44:45 -0400 Subject: [PATCH 4/4] --regionlist should be working now --- overviewer.py | 10 +++++----- quadtree.py | 4 +++- world.py | 13 ++++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/overviewer.py b/overviewer.py index 396cee8..5f3400c 100755 --- a/overviewer.py +++ b/overviewer.py @@ -93,7 +93,7 @@ def main(): parser.add_option("-p", "--processes", dest="procs", help="How many worker processes to start. Default %s" % cpus, default=cpus, action="store", type="int") parser.add_option("-z", "--zoom", dest="zoom", help="Sets the zoom level manually instead of calculating it. This can be useful if you have outlier chunks that make your world too big. This value will make the highest zoom level contain (2**ZOOM)^2 tiles", action="store", type="int", configFileOnly=True) parser.add_option("-d", "--delete", dest="delete", help="Clear all caches. Next time you render your world, it will have to start completely over again. This is probably not a good idea for large worlds. Use this if you change texture packs and want to re-render everything.", action="store_true", commandLineOnly=True) - parser.add_option("--chunklist", dest="chunklist", help="A file containing, on each line, a path to a chunkfile to update. Instead of scanning the world directory for chunks, it will just use this list. Normal caching rules still apply.") + parser.add_option("--regionlist", dest="regionlist", help="A file containing, on each line, a path to a regionlist to update. Instead of scanning the world directory for regions, it will just use this list. Normal caching rules still apply.") parser.add_option("--rendermodes", dest="rendermode", help="Specifies the render types, separated by commas. Use --list-rendermodes to list them all.", type="choice", choices=avail_rendermodes, required=True, default=avail_rendermodes[0], listify=True) parser.add_option("--list-rendermodes", dest="list_rendermodes", action="store_true", help="List available render modes and exit.", commandLineOnly=True) parser.add_option("--imgformat", dest="imgformat", help="The image output format to use. Currently supported: png(default), jpg.", configFileOnly=True ) @@ -189,10 +189,10 @@ def main(): if options.delete: return delete_all(worlddir, destdir) - if options.chunklist: - chunklist = open(options.chunklist, 'r') + if options.regionlist: + regionlist = map(str.strip, open(options.regionlist, 'r')) else: - chunklist = None + regionlist = None if options.imgformat: if options.imgformat not in ('jpg','png'): @@ -221,7 +221,7 @@ def main(): logging.info("Notice: Not using biome data for tinting") # First do world-level preprocessing - w = world.World(worlddir, useBiomeData=useBiomeData) + w = world.World(worlddir, useBiomeData=useBiomeData, regionlist=regionlist) w.go(options.procs) logging.info("Rending the following tilesets: %s", ",".join(options.rendermode)) diff --git a/quadtree.py b/quadtree.py index 688db93..5d240db 100644 --- a/quadtree.py +++ b/quadtree.py @@ -246,7 +246,7 @@ class QuadtreeGen(object): regiony = regiony_ _, _, c, mcr = get_region((regionx, regiony),(None,None,None,None)) - if c is not None and mcr.chunkExists(chunkx,chunky): + if c is not None and mcr.chunkExists(chunkx,chunky): chunklist.append((col, row, chunkx, chunky, c)) return chunklist @@ -427,6 +427,8 @@ class QuadtreeGen(object): for col, row, chunkx, chunky, regionfile in chunks: # check region file mtime first. region,regionMtime = get_region_mtime(regionfile) + if self.world.regionlist and region._filename not in self.world.regionlist: + continue if regionMtime <= tile_mtime: continue diff --git a/world.py b/world.py index 7f7bab1..348aff3 100644 --- a/world.py +++ b/world.py @@ -78,7 +78,8 @@ class World(object): logging.info("Scanning regions") regionfiles = {} self.regions = {} - for x, y, regionfile in self._iterate_regionfiles(): + self.regionlist = regionlist # a list of paths + for x, y, regionfile in self._iterate_regionfiles(): mcr = self.reload_region(regionfile) mcr.get_chunk_info() regionfiles[(x,y)] = (x,y,regionfile,mcr) @@ -277,16 +278,22 @@ class World(object): """Returns an iterator of all of the region files, along with their coordinates + Note: the regionlist here will be used to determinte the size of the + world. + Returns (regionx, regiony, filename)""" join = os.path.join if regionlist is not None: for path in regionlist: - if path.endswith("\n"): - path = path[:-1] + path = path.strip() f = os.path.basename(path) if f.startswith("r.") and f.endswith(".mcr"): p = f.split(".") + logging.debug("Using path %s from regionlist", f) yield (int(p[1]), int(p[2]), join(self.worlddir, 'region', f)) + else: + logging.warning("Ignore path '%s' in regionlist", f) + else: for path in glob(os.path.join(self.worlddir, 'region') + "/r.*.*.mcr"): dirpath, f = os.path.split(path)