Skip to content

Commit

Permalink
fixes to Ovi, particularly related to getBounds and setBounds. Unlike…
Browse files Browse the repository at this point in the history
… almost

every other map provider it seems Ovi uses the north-west and south-east
corners for bounds. I've thus also added getNorthWest and getSouthEast methods
to mxn.BoundingBox as well.
  • Loading branch information
freyfogle committed Nov 2, 2011
1 parent 1a937d1 commit d584000
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
28 changes: 24 additions & 4 deletions source/mxn.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,9 +1248,9 @@ var LatLonPoint = mxn.LatLonPoint = function(lat, lon) {
// TODO error if undefined?
// if (lat == undefined) alert('undefined lat');
// if (lon == undefined) alert('undefined lon');
this.lat = lat;
this.lon = lon;
this.lng = lon; // lets be lon/lng agnostic
this.lat = lat*1; // force to be numeric
this.lon = lon*1;
this.lng = lon*1; // lets be lon/lng agnostic

this.invoker = new mxn.Invoker(this, 'LatLonPoint');
};
Expand Down Expand Up @@ -1346,9 +1346,10 @@ LatLonPoint.prototype.lonConv = function() {
*/
var BoundingBox = mxn.BoundingBox = function(swlat, swlon, nelat, nelon) {
//FIXME throw error if box bigger than world
//alert('new bbox ' + swlat + ',' + swlon + ',' + nelat + ',' + nelon);
this.sw = new LatLonPoint(swlat, swlon);
this.ne = new LatLonPoint(nelat, nelon);
this.se = new LatLonPoint(swlat, nelon);
this.nw = new LatLonPoint(nelat, swlon);
};

/**
Expand All @@ -1360,6 +1361,15 @@ BoundingBox.prototype.getSouthWest = function() {
return this.sw;
};

/**
* getSouthWest returns a LatLonPoint of the south-west point of the bounding box
* @returns the south-east point of the bounding box
* @type LatLonPoint
*/
BoundingBox.prototype.getSouthEast = function() {
return this.se;
};

/**
* getNorthEast returns a LatLonPoint of the north-east point of the bounding box
* @returns the north-east point of the bounding box
Expand All @@ -1369,6 +1379,16 @@ BoundingBox.prototype.getNorthEast = function() {
return this.ne;
};

/**
* getNorthWest returns a LatLonPoint of the north-west point of the bounding box
* @returns the north-west point of the bounding box
* @type LatLonPoint
*/
BoundingBox.prototype.getNorthWest = function() {
return this.nw;
};


/**
* isEmpty finds if this bounding box has zero area
* @returns whether the north-east and south-west points of the bounding box are the same point
Expand Down
27 changes: 15 additions & 12 deletions source/mxn.ovi.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ Mapstraction: {
eventStates.mapsize = false;
me.load.fire();
}
}
if (eventStates.center) {
} else {
if (eventStates.center) {
eventStates.center = false;
me.moveendHandler(me);
me.endPan.fire();
}
}
if (eventStates.zoom) {
eventStates.zoom = false;
Expand All @@ -88,7 +89,12 @@ Mapstraction: {
},

applyOptions: function() {
// TODO
var map = this.maps[this.api];
if(this.options.enableScrollWheelZoom){
map.addComponent(new ovi.mapsapi.map.component.zoom.MouseWheel());
} else{
map.removeComponent(map.getComponentById("zoom.MouseWheel"));
}
},

resizeTo: function(width, height) {
Expand Down Expand Up @@ -135,13 +141,11 @@ Mapstraction: {
// style of Zoom controls so, for now, make them functionally equivalent
addSmallControls: function() {
var map = this.maps[this.api];

map.addComponent(new ovi.mapsapi.map.component.ZoomBar());
},

addLargeControls: function() {
var map = this.maps[this.api];

map.addComponent(new ovi.mapsapi.map.component.ZoomBar());
},

Expand Down Expand Up @@ -265,19 +269,18 @@ Mapstraction: {
getBounds: function() {
var map = this.maps[this.api];
var bbox = map.getViewBounds();
var sw = bbox.topLeft;
var ne = bbox.bottomRight;
var nw = bbox.topLeft;
var se = bbox.bottomRight;
return new mxn.BoundingBox(se.latitude,nw.longitude,nw.latitude,se.longitude);

return new mxn.BoundingBox(sw.latitude, sw.longitude, ne.latitude, ne.longitude);
},

setBounds: function(bounds) {
var map = this.maps[this.api];
var sw = bounds.getSouthWest().toProprietary(this.api);
var ne = bounds.getNorthEast().toProprietary(this.api);
var ovi_bb = new ovi.mapsapi.geo.BoundingBox(sw, ne);
var nw = bounds.getNorthWest().toProprietary(this.api);
var se = bounds.getSouthEast().toProprietary(this.api);
var ovi_bb = new ovi.mapsapi.geo.BoundingBox(nw,se);
var keepCentre = false;

map.zoomTo(ovi_bb, keepCentre);
},

Expand Down

0 comments on commit d584000

Please sign in to comment.