The coords box now displays the correct coords for every rotation
This commit is contained in:
@@ -32,7 +32,8 @@ overviewer.util = {
|
|||||||
// with controls on the outside of the page being added first
|
// with controls on the outside of the page being added first
|
||||||
|
|
||||||
var compass = new overviewer.views.CompassView({tagName: 'DIV', model:overviewer.mapModel});
|
var compass = new overviewer.views.CompassView({tagName: 'DIV', model:overviewer.mapModel});
|
||||||
compass.render();
|
// no need to render the compass now. it's render event will get fired by
|
||||||
|
// the maptypeid_chagned event
|
||||||
|
|
||||||
var coordsdiv = new overviewer.views.CoordboxView({tagName: 'DIV'});
|
var coordsdiv = new overviewer.views.CoordboxView({tagName: 'DIV'});
|
||||||
coordsdiv.render();
|
coordsdiv.render();
|
||||||
@@ -42,7 +43,10 @@ overviewer.util = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function(event) {
|
google.maps.event.addListener(overviewer.map, 'maptypeid_changed', function(event) {
|
||||||
//overviewer.map.getMapTypeId();
|
// it's handy to keep track of the currently visible tileset. we let
|
||||||
|
// the GoogleMapView manage this
|
||||||
|
overviewer.mapView.updateCurrentTileset();
|
||||||
|
|
||||||
compass.render();
|
compass.render();
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -170,23 +174,28 @@ overviewer.util = {
|
|||||||
* @param int x
|
* @param int x
|
||||||
* @param int z
|
* @param int z
|
||||||
* @param int y
|
* @param int y
|
||||||
|
* @param TileSetModel model
|
||||||
*
|
*
|
||||||
* @return google.maps.LatLng
|
* @return google.maps.LatLng
|
||||||
*/
|
*/
|
||||||
'fromWorldToLatLng': function(x, z, y, zoomLevels) {
|
'fromWorldToLatLng': function(x, z, y, model) {
|
||||||
|
|
||||||
|
var zoomLevels = model.get("zoomLevels");
|
||||||
|
var north_direction = model.get('north_direction');
|
||||||
|
|
||||||
// the width and height of all the highest-zoom tiles combined,
|
// the width and height of all the highest-zoom tiles combined,
|
||||||
// inverted
|
// inverted
|
||||||
var perPixel = 1.0 / (overviewerConfig.CONST.tileSize *
|
var perPixel = 1.0 / (overviewerConfig.CONST.tileSize *
|
||||||
Math.pow(2, zoomLevels));
|
Math.pow(2, zoomLevels));
|
||||||
|
|
||||||
if(overviewerConfig.map.north_direction == 'upper-left'){
|
if (north_direction == overviewerConfig.CONST.UPPERRIGHT){
|
||||||
temp = x;
|
temp = x;
|
||||||
x = -y-1;
|
x = -y-1;
|
||||||
y = temp;
|
y = temp;
|
||||||
} else if(overviewerConfig.map.north_direction == 'upper-right'){
|
} else if(north_direction == overviewerConfig.CONST.LOWERRIGHT){
|
||||||
x = -x-1;
|
x = -x-1;
|
||||||
y = -y-1;
|
y = -y-1;
|
||||||
} else if(overviewerConfig.map.north_direction == 'lower-right'){
|
} else if(north_direction == overviewerConfig.CONST.LOWERLEFT){
|
||||||
temp = x;
|
temp = x;
|
||||||
x = y;
|
x = y;
|
||||||
y = -temp-1;
|
y = -temp-1;
|
||||||
@@ -232,7 +241,10 @@ overviewer.util = {
|
|||||||
*
|
*
|
||||||
* @return Array
|
* @return Array
|
||||||
*/
|
*/
|
||||||
'fromLatLngToWorld': function(lat, lng, zoomLevels) {
|
'fromLatLngToWorld': function(lat, lng, model) {
|
||||||
|
var zoomLevels = model.get("zoomLevels");
|
||||||
|
var north_direction = model.get("north_direction");
|
||||||
|
|
||||||
// Initialize world x/y/z object to be returned
|
// Initialize world x/y/z object to be returned
|
||||||
var point = Array();
|
var point = Array();
|
||||||
point.x = 0;
|
point.x = 0;
|
||||||
@@ -255,25 +267,25 @@ overviewer.util = {
|
|||||||
// A (lng) and B (lat). But Wolfram Alpha did. :) I'd welcome
|
// A (lng) and B (lat). But Wolfram Alpha did. :) I'd welcome
|
||||||
// suggestions for splitting this up into long form and documenting
|
// suggestions for splitting this up into long form and documenting
|
||||||
// it. -RF
|
// it. -RF
|
||||||
point.x = (lng - 2 * lat) / (24 * perPixel)
|
point.x = (lng - 2 * lat) / (24 * perPixel);
|
||||||
point.z = (lng + 2 * lat) / (24 * perPixel)
|
point.z = (lng + 2 * lat) / (24 * perPixel);
|
||||||
|
|
||||||
// Adjust for the fact that we we can't figure out what Y is given
|
// Adjust for the fact that we we can't figure out what Y is given
|
||||||
// only latitude and longitude, so assume Y=64.
|
// only latitude and longitude, so assume Y=64.
|
||||||
point.x += 64;
|
point.x += 64;
|
||||||
point.z -= 64;
|
point.z -= 64;
|
||||||
|
|
||||||
if(overviewerConfig.map.north_direction == 'upper-left'){
|
if(north_direction == overviewerConfig.CONST.UPPERRIGHT){
|
||||||
temp = point.z;
|
temp = point.z;
|
||||||
point.z = -point.x;
|
point.z = -point.x+16;
|
||||||
point.x = temp;
|
point.x = temp;
|
||||||
} else if(overviewerConfig.map.north_direction == 'upper-right'){
|
} else if(north_direction == overviewerConfig.CONST.LOWERRIGHT){
|
||||||
point.x = -point.x;
|
point.x = -point.x+16;
|
||||||
point.z = -point.z;
|
point.z = -point.z+16;
|
||||||
} else if(overviewerConfig.map.north_direction == 'lower-right'){
|
} else if(north_direction == overviewerConfig.CONST.LOWERLEFT){
|
||||||
temp = point.z;
|
temp = point.z;
|
||||||
point.z = point.x;
|
point.z = point.x;
|
||||||
point.x = -temp;
|
point.x = -temp+16;
|
||||||
}
|
}
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
|
|||||||
@@ -82,11 +82,7 @@ overviewer.views.CompassView = Backbone.View.extend({
|
|||||||
* CompassView::render
|
* CompassView::render
|
||||||
*/
|
*/
|
||||||
render: function() {
|
render: function() {
|
||||||
var currentWorldView = this.model.get("currentWorldView");
|
var tsetModel = overviewer.mapView.options.currentTileSet;
|
||||||
var gmapCurrent = overviewer.map.getMapTypeId();
|
|
||||||
for (id in currentWorldView.options.mapTypeIds) {
|
|
||||||
if (currentWorldView.options.mapTypeIds[id] == gmapCurrent) {
|
|
||||||
var tsetModel = currentWorldView.model.get("tileSets").at(id);
|
|
||||||
var northdir = tsetModel.get("north_direction");
|
var northdir = tsetModel.get("north_direction");
|
||||||
if (northdir == overviewerConfig.CONST.UPPERLEFT)
|
if (northdir == overviewerConfig.CONST.UPPERLEFT)
|
||||||
this.$("IMG").attr("src","compass_upper-left.png");
|
this.$("IMG").attr("src","compass_upper-left.png");
|
||||||
@@ -97,8 +93,6 @@ overviewer.views.CompassView = Backbone.View.extend({
|
|||||||
if (northdir == overviewerConfig.CONST.LOWERRIGHT)
|
if (northdir == overviewerConfig.CONST.LOWERRIGHT)
|
||||||
this.$("IMG").attr("src", "compass_lower-right.png");
|
this.$("IMG").attr("src", "compass_lower-right.png");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +106,7 @@ overviewer.views.CoordboxView = Backbone.View.extend({
|
|||||||
updateCoords: function(latLng) {
|
updateCoords: function(latLng) {
|
||||||
var worldcoords = overviewer.util.fromLatLngToWorld(latLng.lat(),
|
var worldcoords = overviewer.util.fromLatLngToWorld(latLng.lat(),
|
||||||
latLng.lng(),
|
latLng.lng(),
|
||||||
overviewer.mapModel.get("currentWorldView").model.get("tileSets").at(0).get("zoomLevels"));
|
overviewer.mapView.options.currentTileSet);
|
||||||
this.el.innerHTML = "Coords: X " + Math.round(worldcoords.x) + ", Z " + Math.round(worldcoords.z);
|
this.el.innerHTML = "Coords: X " + Math.round(worldcoords.x) + ", Z " + Math.round(worldcoords.z);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -198,6 +192,23 @@ overviewer.views.GoogleMapView = Backbone.View.extend({
|
|||||||
|
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* GoogleMapView::updateCurrentTileset()
|
||||||
|
* Keeps track of the currently visible tileset
|
||||||
|
*/
|
||||||
|
updateCurrentTileset: function() {
|
||||||
|
console.log("GoogleMapView::updateCurrentTileset()");
|
||||||
|
var currentWorldView = this.model.get("currentWorldView");
|
||||||
|
var gmapCurrent = overviewer.map.getMapTypeId();
|
||||||
|
for (id in currentWorldView.options.mapTypeIds) {
|
||||||
|
if (currentWorldView.options.mapTypeIds[id] == gmapCurrent) {
|
||||||
|
console.log("updating currenttileset");
|
||||||
|
this.options.currentTileSet = currentWorldView.model.get("tileSets").at(id);
|
||||||
|
console.log(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user