+ public static int max_zoom = 17;
+
+ public static double valid_radius = 17000; /* 17km */
+
+ public String map_dir = null;
+ public String launch_sites_file = null;
+ public String key_file = null;
+
+ public void usage() {
+ System.out.printf("usage: altos-mapd [--mapdir <map-directory] [--launch-sites <launch-sites-file>]\n" +
+ " [--radius <valid-radius-m> [--port <port>] [--key <key-file>]\n" +
+ " [--max-zoom <max-zoom-level>\n");
+ System.exit(1);
+ }
+
+ private static Semaphore launch_sites_ready;
+
+ private static List<AltosLaunchSite> launch_sites;
+
+ public void notify_launch_sites(List<AltosLaunchSite> sites) {
+ synchronized (launch_sites_ready) {
+ if (sites != null) {
+ launch_sites = sites;
+ launch_sites_ready.release();
+ }
+ }
+ }
+
+ 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) {
+
+ if (zoom > max_zoom)
+ return false;
+
+ 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 {
+ launch_sites_ready.acquire();
+ } catch (InterruptedException ie) {
+ return false;
+ }
+ }
+ }
+ if (launch_sites == null) {
+ System.out.printf("No launch site data available, refusing all requests\n");
+ return false;
+ }
+
+ 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;