mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(map): keep places and routes on one world, and start new installs with Journey and Collections
A right-click, click or drag on a repeated world copy reported the longitude it has on that copy (274.9 for -85.1). The place was saved there, the geocoder found nothing, and a route to a place on the real world ran across the whole map (#2976). Longitudes are now brought back onto [-180, 180] where the map hands them out (Leaflet and GL), where they are stored (places, booking endpoints, collection places, so REST, MCP, plugin RPC and importers alike) and before reverse geocoding. A migration moves the ones already stored. Leaflet draws a layer at its literal longitude only, so a trip from Los Angeles to Auckland had its pins at opposite ends of the world while the flight ran off the edge to the next copy (#2975). A trip that crosses the antimeridian is now drawn in one longitude frame, seamed in the widest stretch it leaves empty, so pins, routes, flights and every overlay lie on one copy and the map opens across the Pacific. Every other trip has no frame and draws exactly as before. The GL day fit also takes the short way. A new install now starts with Journey and Collections switched on, next to the trip addons (all but Road trip), Atlas, Vacay and the Naver import that already were. Existing installs keep their addons as they are. Closes #2975 Closes #2976
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* The tables whose `lng` a click on a repeated world copy could have written, and
|
||||
* the outbox that would still hand such a place on to the shared places index.
|
||||
*/
|
||||
const TABLES = ['places', 'reservation_endpoints', 'collection_places', 'place_contrib_outbox'] as const;
|
||||
|
||||
interface LngRow {
|
||||
id: number;
|
||||
lng: number;
|
||||
}
|
||||
|
||||
/** Into [-180, 180], the same arithmetic as wrapLongitude in @trek/shared, kept here so this body never changes. */
|
||||
function onTheRealWorld(lng: number): number {
|
||||
const wrapped = ((((lng + 180) % 360) + 360) % 360) - 180;
|
||||
return wrapped === 0 ? 0 : wrapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Brings every stored longitude back onto the real world.
|
||||
*
|
||||
* The map repeats the world sideways, and a right-click or a drag on one of the
|
||||
* copies reported its longitude as it is on that copy: 274.9 instead of -85.1.
|
||||
* Saved like that, a place sat on its copy for good, out of reach of the
|
||||
* geocoder, and a day route to it ran across the whole map (#2976). New writes
|
||||
* are wrapped on the way in; this moves the ones already stored to the same
|
||||
* point on the real world. Only rows outside [-180, 180] are touched.
|
||||
*/
|
||||
export class Migration20200101046350_a_place_lies_on_the_real_world extends Migration {
|
||||
override name = 'Migration20200101046350_a_place_lies_on_the_real_world';
|
||||
|
||||
override async up(): Promise<void> {
|
||||
for (const table of TABLES) {
|
||||
const rows = (await this.execute(
|
||||
`SELECT id, lng FROM ${table} WHERE lng IS NOT NULL AND (lng < -180 OR lng > 180)`,
|
||||
)) as LngRow[];
|
||||
for (const row of rows) {
|
||||
await this.execute(`UPDATE ${table} SET lng = ? WHERE id = ?`, [onTheRealWorld(row.lng), row.id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
/**
|
||||
* A new install starts with Journey and Collections switched on; an existing
|
||||
* install keeps every addon exactly as its admin left it.
|
||||
*
|
||||
* Both rows are written off by older migrations (journey_addon, collections_addon)
|
||||
* that every install runs, and the addon seeder never overwrites a row that is
|
||||
* already there, so the seeder alone cannot change their start value. A database
|
||||
* whose `users` table is still empty here is being set up for the first time:
|
||||
* migrations run before the seeders, and the admin seeder writes the first
|
||||
* account only afterwards.
|
||||
*/
|
||||
export class Migration20200101046360_a_new_install_starts_with_more_addons_on extends Migration {
|
||||
override name = 'Migration20200101046360_a_new_install_starts_with_more_addons_on';
|
||||
|
||||
override up(): void {
|
||||
this.addSql(
|
||||
"UPDATE addons SET enabled = 1 WHERE id IN ('journey', 'collections') AND NOT EXISTS (SELECT 1 FROM users)",
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { CollectionPlaces } from '../entities/CollectionPlaces.entity';
|
||||
import type { DB } from '../kysely/db';
|
||||
import type { CollectionPlaceRow } from './Collections.repository';
|
||||
import { TrekRepository } from './_shared/trek-repository';
|
||||
import { wrapOptionalLongitude } from '@trek/shared';
|
||||
|
||||
/**
|
||||
* `collection_places` (Plan 3h Task 2, part B — saved places CRUD, dedup,
|
||||
@@ -115,7 +116,7 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
lat: row.lat,
|
||||
lng: row.lng,
|
||||
lng: wrapOptionalLongitude(row.lng),
|
||||
address: row.address,
|
||||
category: row.category_id,
|
||||
price: row.price,
|
||||
@@ -181,6 +182,7 @@ export class CollectionPlacesRepository extends TrekRepository<CollectionPlaces>
|
||||
{ id },
|
||||
{
|
||||
...rest,
|
||||
...(rest.lng !== undefined ? { lng: wrapOptionalLongitude(rest.lng) } : {}),
|
||||
...(category_id !== undefined ? { category: category_id } : {}),
|
||||
...(collection_id !== undefined ? { collection: collection_id } : {}),
|
||||
...(owner_id !== undefined ? { owner: owner_id } : {}),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Places } from '../entities/Places.entity';
|
||||
import { wrapOptionalLongitude } from '@trek/shared';
|
||||
import { absDifference, coalesceParam, columnRef, currentTimestamp, lowerTrim } from '../dialect/sql-functions';
|
||||
import { type AssertRowKeys } from './_shared/rows';
|
||||
import { TrekRepository } from './_shared/trek-repository';
|
||||
@@ -386,7 +387,7 @@ export class PlacesRepository extends TrekRepository<Places> {
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
lat: input.lat,
|
||||
lng: input.lng,
|
||||
lng: wrapOptionalLongitude(input.lng),
|
||||
address: input.address,
|
||||
category: input.category_id,
|
||||
price: input.price,
|
||||
@@ -466,7 +467,7 @@ export class PlacesRepository extends TrekRepository<Places> {
|
||||
name: write.name,
|
||||
description: write.description,
|
||||
lat: write.lat,
|
||||
lng: write.lng,
|
||||
lng: wrapOptionalLongitude(write.lng),
|
||||
address: write.address,
|
||||
category: write.category_id,
|
||||
price: write.price,
|
||||
@@ -963,7 +964,7 @@ export class PlacesRepository extends TrekRepository<Places> {
|
||||
name: input.name,
|
||||
description: input.description,
|
||||
lat: input.lat,
|
||||
lng: input.lng,
|
||||
lng: wrapOptionalLongitude(input.lng),
|
||||
address: input.address,
|
||||
category: input.category_id,
|
||||
price: input.price,
|
||||
@@ -1338,7 +1339,7 @@ export class PlacesRepository extends TrekRepository<Places> {
|
||||
trip: input.trip_id,
|
||||
name: input.name,
|
||||
lat: input.lat,
|
||||
lng: input.lng,
|
||||
lng: wrapOptionalLongitude(input.lng),
|
||||
transport_mode: 'walking',
|
||||
route_geometry: input.route_geometry,
|
||||
description: input.description ?? null,
|
||||
@@ -1360,7 +1361,7 @@ export class PlacesRepository extends TrekRepository<Places> {
|
||||
{
|
||||
name: input.name,
|
||||
lat: input.lat,
|
||||
lng: input.lng,
|
||||
lng: wrapOptionalLongitude(input.lng),
|
||||
transport_mode: 'walking',
|
||||
route_geometry: input.route_geometry,
|
||||
...tourPlaceTextPatch(input),
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { DB } from '../kysely/db';
|
||||
import { travelerOwnsExpr, type ReservationTravelersOwnsKyselyDB } from './_shared/reservation-travelers-owns';
|
||||
import { type AssertRowKeys } from './_shared/rows';
|
||||
import { TrekRepository } from './_shared/trek-repository';
|
||||
import { wrapLongitude } from '@trek/shared';
|
||||
|
||||
/** A `reservation_endpoints` row exactly as `r.*`/`SELECT *` read it (every scalar column). */
|
||||
export interface ReservationEndpointRow {
|
||||
@@ -82,7 +83,7 @@ export class ReservationEndpointsRepository extends TrekRepository<ReservationEn
|
||||
name: input.name,
|
||||
code: input.code,
|
||||
lat: input.lat,
|
||||
lng: input.lng,
|
||||
lng: wrapLongitude(input.lng),
|
||||
timezone: input.timezone,
|
||||
local_time: input.local_time,
|
||||
local_date: input.local_date,
|
||||
|
||||
@@ -110,7 +110,7 @@ export const DEFAULT_ADDONS: AddonRow[] = [
|
||||
description: 'Trip tracking & travel journal — check-ins, photos, daily stories',
|
||||
type: 'global',
|
||||
icon: 'Compass',
|
||||
enabled: 0,
|
||||
enabled: 1,
|
||||
sort_order: 35,
|
||||
},
|
||||
{
|
||||
@@ -157,7 +157,7 @@ export const DEFAULT_ADDONS: AddonRow[] = [
|
||||
'Personal place library — save places across trips into named lists, copy into any trip, share with others',
|
||||
type: 'global',
|
||||
icon: 'Bookmark',
|
||||
enabled: 0,
|
||||
enabled: 1,
|
||||
sort_order: 16,
|
||||
},
|
||||
];
|
||||
@@ -169,6 +169,12 @@ export const DEFAULT_ADDONS: AddonRow[] = [
|
||||
* table-level emptiness check: an operator who has toggled an addon keeps their
|
||||
* choice, and a release that adds a new addon still gets its tile on an
|
||||
* existing install.
|
||||
*
|
||||
* `enabled` is the start value on a new install: every trip addon but Road trip,
|
||||
* plus Journey, Collections, Atlas, Vacay and the Naver import. The Journey and
|
||||
* Collections rows are written by older migrations before this runs, so a new
|
||||
* install has them switched on by Migration20200101046360; on an existing install
|
||||
* nothing here changes.
|
||||
*/
|
||||
export class AddonSeeder extends Seeder {
|
||||
async run(em: EntityManager): Promise<void> {
|
||||
|
||||
@@ -39,7 +39,7 @@ import {
|
||||
} from './trek-places.client';
|
||||
import { InjectRepository } from '@mikro-orm/nestjs';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { isOutsideChina } from '@trek/shared';
|
||||
import { isOutsideChina, wrapLongitude } from '@trek/shared';
|
||||
import type { MapsSearchResult, MapsAutocompleteResult, MapsPlaceDetailsResult } from '@trek/shared';
|
||||
import type { MapsPlacePhotoResult, MapsReverseResult, MapsResolveUrlResult } from '@trek/shared';
|
||||
|
||||
@@ -57,6 +57,17 @@ const NEARBY_CACHE = new Map<string, { at: number; value: { places: Record<strin
|
||||
const NEARBY_CACHE_TTL_MS = 30 * 60 * 1000;
|
||||
const NEARBY_CACHE_MAX = 500;
|
||||
|
||||
/**
|
||||
* The reverse-geocode longitude, as text, moved back onto the real world when a
|
||||
* right-click on a repeated world copy sent it past 180 (#2976): the geocoders
|
||||
* answer nothing out there. A value already in range is passed on exactly as it came.
|
||||
*/
|
||||
function onTheRealWorld(lng: string): string {
|
||||
const value = Number.parseFloat(lng);
|
||||
if (!Number.isFinite(value) || (value >= -180 && value <= 180)) return lng;
|
||||
return String(wrapLongitude(value));
|
||||
}
|
||||
|
||||
type LocationBias = { low: { lat: number; lng: number }; high: { lat: number; lng: number } };
|
||||
|
||||
/**
|
||||
@@ -649,6 +660,7 @@ export class MapsService {
|
||||
lang?: string,
|
||||
opts?: { lane?: GeoLane; timeoutMs?: number; locality?: boolean },
|
||||
): Promise<{ name: string | null; address: string | null }> {
|
||||
lng = onTheRealWorld(lng);
|
||||
// Amap answers first when it holds the keyed slot, and only for a point it
|
||||
// can possibly know: outside its box the call would cost a round trip to
|
||||
// come back empty before Nominatim is asked anyway. Resolved at userId 0,
|
||||
|
||||
Reference in New Issue
Block a user