Readded url hash updating
as a "side-effect", the current coords remain centered when switching tilesets. at least in theory. needs more work
This commit is contained in:
@@ -37,10 +37,20 @@ overviewer.util = {
|
|||||||
|
|
||||||
var coordsdiv = new overviewer.views.CoordboxView({tagName: 'DIV'});
|
var coordsdiv = new overviewer.views.CoordboxView({tagName: 'DIV'});
|
||||||
coordsdiv.render();
|
coordsdiv.render();
|
||||||
|
|
||||||
// Update coords on mousemove
|
// Update coords on mousemove
|
||||||
google.maps.event.addListener(overviewer.map, 'mousemove', function (event) {
|
google.maps.event.addListener(overviewer.map, 'mousemove', function (event) {
|
||||||
coordsdiv.updateCoords(event.latLng);
|
coordsdiv.updateCoords(event.latLng);
|
||||||
});
|
});
|
||||||
|
google.maps.event.addListener(overviewer.map, 'dragend', function (event) {
|
||||||
|
overviewer.util.updateHash();
|
||||||
|
});
|
||||||
|
google.maps.event.addListener(overviewer.map, 'zoom_changed', function (event) {
|
||||||
|
overviewer.util.updateHash();
|
||||||
|
});
|
||||||
|
google.maps.event.addListener(overviewer.map, 'dblclick', function (event) {
|
||||||
|
overviewer.util.updateHash();
|
||||||
|
});
|
||||||
|
|
||||||
google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function(event) {
|
google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function(event) {
|
||||||
// it's handy to keep track of the currently visible tileset. we let
|
// it's handy to keep track of the currently visible tileset. we let
|
||||||
@@ -49,6 +59,17 @@ overviewer.util = {
|
|||||||
|
|
||||||
compass.render();
|
compass.render();
|
||||||
|
|
||||||
|
// re-center on the last viewport
|
||||||
|
var currentWorldView = overviewer.mapModel.get("currentWorldView");
|
||||||
|
if (currentWorldView.options.lastViewport) {
|
||||||
|
var x = currentWorldView.options.lastViewport[0];
|
||||||
|
var y = currentWorldView.options.lastViewport[1];
|
||||||
|
var z = currentWorldView.options.lastViewport[2];
|
||||||
|
var latlngcoords = overviewer.util.fromWorldToLatLng(x, y, z,
|
||||||
|
overviewer.mapView.options.currentTileSet);
|
||||||
|
overviewer.map.setCenter(latlngcoords);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var worldSelector = new overviewer.views.WorldSelectorView({tagName:'DIV'});
|
var worldSelector = new overviewer.views.WorldSelectorView({tagName:'DIV'});
|
||||||
@@ -60,6 +81,10 @@ overviewer.util = {
|
|||||||
|
|
||||||
overviewer.mapView.render();
|
overviewer.mapView.render();
|
||||||
|
|
||||||
|
// Jump to the hash if given
|
||||||
|
overviewer.util.initHash();
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
overviewer.util.initializeMapTypes();
|
overviewer.util.initializeMapTypes();
|
||||||
overviewer.util.initializeMap();
|
overviewer.util.initializeMap();
|
||||||
@@ -340,93 +365,92 @@ overviewer.util = {
|
|||||||
// Clean up the hash.
|
// Clean up the hash.
|
||||||
overviewer.util.updateHash();
|
overviewer.util.updateHash();
|
||||||
|
|
||||||
// Add a marker indicating the user-supplied position
|
|
||||||
var coordinates = overviewer.util.fromLatLngToWorld(overviewer.map.getCenter().lat(),
|
|
||||||
overviewer.map.getCenter().lng(),
|
|
||||||
overviewerConfig.tilesets[overviewer.currentTilesetId].zoomLevels);
|
|
||||||
overviewer.collections.markerDatas.push([{
|
|
||||||
'msg': 'Coordinates ' + Math.floor(coordinates.x) + ', ' + Math.floor(coordinates.y) + ', ' + Math.floor(coordinates.z),
|
|
||||||
'x': coordinates.x,
|
|
||||||
'y': coordinates.y,
|
|
||||||
'z': coordinates.z,
|
|
||||||
'type': 'querypos'}]);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'setHash': function(x, y, z, zoom, maptype) {
|
'setHash': function(x, y, z, zoom, w, maptype) {
|
||||||
// remove the div prefix from the maptype (looks better)
|
// save this info is a nice easy to parse format
|
||||||
if (maptype)
|
var currentWorldView = overviewer.mapModel.get("currentWorldView");
|
||||||
{
|
currentWorldView.options.lastViewport = [x,y,z,zoom];
|
||||||
maptype = maptype.replace(overviewerConfig.CONST.mapDivId, "");
|
window.location.replace("#/" + Math.floor(x) + "/" + Math.floor(y) + "/" + Math.floor(z) + "/" + zoom + "/" + w + "/" + maptype);
|
||||||
}
|
|
||||||
window.location.replace("#/" + Math.floor(x) + "/" + Math.floor(y) + "/" + Math.floor(z) + "/" + zoom + "/" + maptype);
|
|
||||||
},
|
},
|
||||||
'updateHash': function() {
|
'updateHash': function() {
|
||||||
|
var currTileset = overviewer.mapView.options.currentTileSet;
|
||||||
|
if (currTileset == null) {return;}
|
||||||
var coordinates = overviewer.util.fromLatLngToWorld(overviewer.map.getCenter().lat(),
|
var coordinates = overviewer.util.fromLatLngToWorld(overviewer.map.getCenter().lat(),
|
||||||
overviewer.map.getCenter().lng(),
|
overviewer.map.getCenter().lng(),
|
||||||
overviewerConfig.tilesets[overviewer.currentTilesetId].zoomLevels);
|
currTileset);
|
||||||
var zoom = overviewer.map.getZoom();
|
var zoom = overviewer.map.getZoom();
|
||||||
var maptype = overviewer.map.getMapTypeId();
|
var maptype = overviewer.map.getMapTypeId();
|
||||||
if (zoom == overviewerConfig.tilesets[overviewer.currentTilesetId].maxZoom) {
|
|
||||||
|
// convert mapType into a index
|
||||||
|
var currentWorldView = overviewer.mapModel.get("currentWorldView");
|
||||||
|
var maptypeId = -1;
|
||||||
|
for (id in currentWorldView.options.mapTypeIds) {
|
||||||
|
if (currentWorldView.options.mapTypeIds[id] == maptype) {
|
||||||
|
maptypeId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var worldId = -1;
|
||||||
|
for (id in overviewer.collections.worldViews) {
|
||||||
|
if (overviewer.collections.worldViews[id] == currentWorldView) {
|
||||||
|
worldId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (zoom == currTileset.get('maxZoom')) {
|
||||||
zoom = 'max';
|
zoom = 'max';
|
||||||
} else if (zoom == overviewerConfig.tilesets[overviewer.currentTilesetId].minZoom) {
|
} else if (zoom == currTileset.get('minZoom')) {
|
||||||
zoom = 'min';
|
zoom = 'min';
|
||||||
} else {
|
} else {
|
||||||
// default to (map-update friendly) negative zooms
|
// default to (map-update friendly) negative zooms
|
||||||
zoom -= overviewerConfig.tilesets[overviewer.currentTilesetId].maxZoom;
|
zoom -= currTileset.get('maxZoom');
|
||||||
}
|
}
|
||||||
overviewer.util.setHash(coordinates.x, coordinates.y, coordinates.z, zoom, maptype);
|
overviewer.util.setHash(coordinates.x, coordinates.y, coordinates.z, zoom, worldId, maptypeId);
|
||||||
},
|
},
|
||||||
'goToHash': function() {
|
'goToHash': function() {
|
||||||
// Note: the actual data begins at coords[1], coords[0] is empty.
|
// Note: the actual data begins at coords[1], coords[0] is empty.
|
||||||
var coords = window.location.hash.split("/");
|
var coords = window.location.hash.split("/");
|
||||||
var latlngcoords = overviewer.util.fromWorldToLatLng(parseInt(coords[1]),
|
|
||||||
parseInt(coords[2]),
|
|
||||||
parseInt(coords[3]),
|
|
||||||
overviewerConfig.tilesets[overviewer.currentTilesetId].zoomLevels);
|
|
||||||
var zoom;
|
var zoom;
|
||||||
var maptype = '';
|
var worldid = -1;
|
||||||
|
var maptyped = -1;
|
||||||
// The if-statements try to prevent unexpected behaviour when using incomplete hashes, e.g. older links
|
// The if-statements try to prevent unexpected behaviour when using incomplete hashes, e.g. older links
|
||||||
if (coords.length > 4) {
|
if (coords.length > 4) {
|
||||||
zoom = coords[4];
|
zoom = coords[4];
|
||||||
}
|
}
|
||||||
if (coords.length > 5) {
|
if (coords.length > 6) {
|
||||||
maptype = coords[5];
|
worldid = coords[5];
|
||||||
|
maptypeid = coords[6];
|
||||||
}
|
}
|
||||||
|
var worldView = overviewer.collections.worldViews[worldid];
|
||||||
|
overviewer.mapModel.set({currentWorldView: worldView});
|
||||||
|
|
||||||
|
var maptype = worldView.options.mapTypeIds[maptypeid];
|
||||||
|
overviewer.map.setMapTypeId(maptype);
|
||||||
|
var tsetModel = worldView.model.get("tileSets").at(maptypeid);
|
||||||
|
|
||||||
|
var latlngcoords = overviewer.util.fromWorldToLatLng(parseInt(coords[1]),
|
||||||
|
parseInt(coords[2]),
|
||||||
|
parseInt(coords[3]),
|
||||||
|
tsetModel);
|
||||||
|
|
||||||
if (zoom == 'max') {
|
if (zoom == 'max') {
|
||||||
zoom = overviewerConfig.tilesets[overviewer.currentTilesetId].maxZoom;
|
zoom = tsetModel.get('maxZoom');
|
||||||
} else if (zoom == 'min') {
|
} else if (zoom == 'min') {
|
||||||
zoom = overviewerConfig.tilesets[overviewer.currentTilesetId].minZoom;
|
zoom = tsetModel.get('minZoom');
|
||||||
} else {
|
} else {
|
||||||
zoom = parseInt(zoom);
|
zoom = parseInt(zoom);
|
||||||
if (zoom < 0 && zoom + overviewerConfig.tilesets[overviewer.currentTilesetId].maxZoom >= 0) {
|
if (zoom < 0 && zoom + tsetModel.get('maxZoom') >= 0) {
|
||||||
// if zoom is negative, treat it as a "zoom out from max"
|
// if zoom is negative, treat it as a "zoom out from max"
|
||||||
zoom += overviewerConfig.tilesets[overviewer.currentTilesetId].maxZoom;
|
zoom += tsetModel.get('maxZoom');
|
||||||
} else {
|
} else {
|
||||||
// fall back to default zoom
|
// fall back to default zoom
|
||||||
zoom = overviewerConfig.tilesets[overviewer.currentTilesetId].defaultZoom;
|
zoom = tsetModel.get('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 {
|
|
||||||
// normalize the map type (this supports old-style,
|
|
||||||
// 'mcmapLabel' style map types, converts them to 'shortname'
|
|
||||||
if (maptype.lastIndexOf(overviewerConfig.CONST.mapDivId, 0) === 0) {
|
|
||||||
maptype = maptype.replace(overviewerConfig.CONST.mapDivId, "");
|
|
||||||
for (i in overviewer.collections.mapTypes) {
|
|
||||||
var type = overviewer.collections.mapTypes[i];
|
|
||||||
if (type.name == maptype) {
|
|
||||||
maptype = type.shortname;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
overviewer.map.setMapTypeId(overviewerConfig.CONST.mapDivId + maptype);
|
|
||||||
}
|
|
||||||
|
|
||||||
overviewer.map.setCenter(latlngcoords);
|
overviewer.map.setCenter(latlngcoords);
|
||||||
overviewer.map.setZoom(zoom);
|
overviewer.map.setZoom(zoom);
|
||||||
|
|||||||
@@ -209,6 +209,9 @@ overviewer.views.GoogleMapView = Backbone.View.extend({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for this world, remember our current viewport (as worldcoords, not LatLng)
|
||||||
|
//
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user