diff options
| author | Keith Packard <keithp@keithp.com> | 2018-10-07 14:08:30 -0600 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2018-10-07 14:08:30 -0600 | 
| commit | e7e1e805f1358052b33103a2ffdd4e9c435c8650 (patch) | |
| tree | 92cfbb2dc9a0aa3b7e824607eac763ebb11eac67 | |
| parent | 581f700e08ec8a1c3bfc5a09e7186676c54a5460 (diff) | |
altos-mapd: Check nearest portion of tile to launch site
We limit tile queries to those within 17km of a known launch
site. Change the check to look at the portion of the tile nearest each
launch site, instead of only checking the center location of the tile.
Signed-off-by: Keith Packard <keithp@keithp.com>
| -rw-r--r-- | map-server/altos-mapd/AltosMapd.java | 46 | ||||
| -rw-r--r-- | map-server/altos-mapd/AltosMapdClient.java | 2 | 
2 files changed, 45 insertions, 3 deletions
| diff --git a/map-server/altos-mapd/AltosMapd.java b/map-server/altos-mapd/AltosMapd.java index b4105861..1be1655d 100644 --- a/map-server/altos-mapd/AltosMapd.java +++ b/map-server/altos-mapd/AltosMapd.java @@ -57,7 +57,23 @@ public class AltosMapd implements AltosLaunchSiteListener {  		}  	} -	public static boolean check_lat_lon(double lat, double lon) { +	private static boolean west_of(double a, double b) { +		double	diff = b - a; + +		while (diff >= 360.0) +			diff -= 360.0; +		while (diff <= -360.0) +			diff += 360.0; + +		return diff >= 0; +	} + +	public static boolean check_lat_lon(double lat, double lon, int zoom) { +		AltosMapTransform	transform = new AltosMapTransform(px_size, px_size, zoom, new AltosLatLon(lat, lon)); + +		AltosLatLon		upper_left = transform.screen_lat_lon(new AltosPointInt(0, 0)); +		AltosLatLon		lower_right = transform.screen_lat_lon(new AltosPointInt(px_size, px_size)); +  		synchronized (launch_sites_ready) {  			if (launch_sites == null) {  				try { @@ -73,8 +89,34 @@ public class AltosMapd implements AltosLaunchSiteListener {  		}  		for (AltosLaunchSite site : launch_sites) { + +			/* Figure out which point in the tile to +			 * measure to the site That's one of the edges +			 * or the site location depend on where the +			 * site is in relation to the tile +			 */ + +			double		check_lon; + +			if (west_of(site.longitude, upper_left.lon)) +				check_lon = upper_left.lon; +			else if (west_of(lower_right.lon, site.longitude)) +				check_lon = lower_right.lon; +			else +				check_lon = site.longitude; + +			double		check_lat; + +			if (site.latitude < lower_right.lat) +				check_lat = lower_right.lat; +			else if (upper_left.lat < site.latitude) +				check_lat = upper_left.lat; +			else +				check_lat = site.latitude; +  			AltosGreatCircle gc = new AltosGreatCircle(site.latitude, site.longitude, -								   lat, lon); +								   check_lat, check_lon); +  			if (gc.distance <= valid_radius)  				return true;  		} diff --git a/map-server/altos-mapd/AltosMapdClient.java b/map-server/altos-mapd/AltosMapdClient.java index 19174088..6c95da8f 100644 --- a/map-server/altos-mapd/AltosMapdClient.java +++ b/map-server/altos-mapd/AltosMapdClient.java @@ -85,7 +85,7 @@ public class AltosMapdClient extends Thread implements AltosMapStoreListener {  				    addr == null)  				{  					set_status(400); -				} else if (!AltosMapd.check_lat_lon(lat, lon)) { +				} else if (!AltosMapd.check_lat_lon(lat, lon, zoom)) {  					set_status(403);	/* Forbidden */  				} else { | 
