Skip to content

Commit

Permalink
fix(maps): enforce float type for coords
Browse files Browse the repository at this point in the history
  • Loading branch information
haruspeks committed Jul 30, 2024
1 parent de1b4e0 commit 92c35c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
13 changes: 6 additions & 7 deletions src/core/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ class Maps {

switch (true) {
case screen.isProviderGoogle() && screen.isTypeAerial():
screen.map.setCenter({lat: coords.lat, lng: coords.lng });
screen.map.setCenter(coords);
return true;

case screen.isProviderGoogle() && screen.isTypeBirdsEye():
screen.map.setCenter({lat: coords.lat, lng: coords.lng });
screen.map.setCenter(coords);
/**
* Google's tilt, when unavailable, defaults back to aerial
* which doesn't support heading. And we don't know
Expand All @@ -248,14 +248,13 @@ class Maps {
screen.map.setPosition(coords);
return true;

case screen.isProviderGoogle() && screen.isTypeAerial():
case screen.isProviderAzure() && screen.isTypeAerial():
case screen.isProviderAzure() && screen.isTypeBirdsEye():
screen.map.setCamera({
center: coords.toLngLat()
});
return true;

case screen.isProviderBing() && screen.isTypeAerial():
case screen.isProviderBing() && screen.isTypeBirdsEye():
const location = new Microsoft.Maps.Location(coords.lat, coords.lng);
Microsoft.Maps.getIsBirdseyeAvailable(location, Microsoft.Maps.Heading.north, function(isAvailable) {
Expand Down Expand Up @@ -298,12 +297,12 @@ class Maps {
* @param {String} lng
*/
jumpTo(lat, lng) {
const latitude = new Number(lat);
const longitude = new Number(lng);
const latitude = parseFloat(lat);
const longitude = parseFloat(lng);
if(latitude < -90 || latitude > 90 || longitude < -180 || longitude > 180)
return alert('Wrong format');

const coords = new Coords(new Number(lat), new Number(lng));
const coords = new Coords(latitude, longitude);
this.emitPositionChange(coords, true);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/types/coords.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class Coords {
* @param {Number} lng
*/
constructor(lat, lng) {
this.lat = lat;
this.lng = lng;
this.lat = parseFloat(lat);
this.lng = parseFloat(lng);

Coords.prototype.valueOf = function () {
return {
Expand Down

0 comments on commit 92c35c8

Please sign in to comment.