Extend line range to antipode (20k km), increase city limit to 100, and fix info panel layout
This commit is contained in:
@@ -6,7 +6,7 @@ const DATA_URL = 'https://raw.githubusercontent.com/nvkelso/natural-earth-vector
|
||||
|
||||
async function importCities() {
|
||||
const client = new Client({
|
||||
connectionString: process.env.DATABASE_URL || 'postgresql://line_of_sight:line_of_sight_pass@localhost:5432/line_of_sight'
|
||||
connectionString: process.env.DATABASE_URL || 'postgresql://line_of_sight:line_of_sight_pass@postgres:5432/line_of_sight'
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -19,6 +19,11 @@ async function importCities() {
|
||||
|
||||
console.log(`Downloaded ${data.features.length} features. Preparing database...`);
|
||||
|
||||
// Sample properties to verify structure
|
||||
if (data.features.length > 0) {
|
||||
console.log('Sample properties:', data.features[0].properties);
|
||||
}
|
||||
|
||||
// Ensure table exists and is clean
|
||||
await client.query('TRUNCATE TABLE cities');
|
||||
|
||||
@@ -28,40 +33,28 @@ async function importCities() {
|
||||
for (let i = 0; i < data.features.length; i += batchSize) {
|
||||
const batch = data.features.slice(i, i + batchSize);
|
||||
|
||||
const values = [];
|
||||
const queryParts = [];
|
||||
|
||||
batch.forEach((feature, index) => {
|
||||
const props = feature.properties;
|
||||
const coords = feature.geometry.coordinates; // [lon, lat]
|
||||
|
||||
const name = props.NAME || 'Unknown';
|
||||
const population = props.POP_MAX || 0;
|
||||
const country = props.ADM0NAME || 'Unknown';
|
||||
const lon = coords[0];
|
||||
const lat = coords[1];
|
||||
|
||||
const baseIndex = index * 4;
|
||||
queryParts.push(`($${baseIndex + 1}, $${baseIndex + 2}, $${baseIndex + 3}, ST_SetSRID(ST_MakePoint($${baseIndex + 4}, $${baseIndex + 1}), 4326)::geography)`);
|
||||
values.push(lat, name, population, country, lon); // Note: ST_MakePoint takes lon, lat
|
||||
});
|
||||
|
||||
// Simple positional mapping for query (lat, name, pop, country, lon)
|
||||
// Actually let's refine the query to be clearer
|
||||
const refinedQueryParts = [];
|
||||
const refinedValues = [];
|
||||
const values = [];
|
||||
|
||||
batch.forEach((feature, index) => {
|
||||
const p = feature.properties;
|
||||
const c = feature.geometry.coordinates;
|
||||
|
||||
// Map properties - Natural Earth simple GeoJSON usually has name, pop_max, adm0name
|
||||
const name = p.name || p.NAME || 'Unknown';
|
||||
const pop = p.pop_max || p.POP_MAX || 0;
|
||||
const country = p.adm0name || p.ADM0NAME || 'Unknown';
|
||||
const lon = c[0];
|
||||
const lat = c[1];
|
||||
|
||||
const base = index * 5;
|
||||
refinedQueryParts.push(`($${base + 1}, $${base + 2}, $${base + 3}, ST_SetSRID(ST_MakePoint($${base + 4}, $${base + 5}), 4326)::geography)`);
|
||||
refinedValues.push(p.NAME || 'Unknown', p.POP_MAX || 0, p.ADM0NAME || 'Unknown', c[0], c[1]);
|
||||
queryParts.push(`($${base + 1}, $${base + 2}, $${base + 3}, ST_SetSRID(ST_MakePoint($${base + 4}, $${base + 5}), 4326)::geography)`);
|
||||
values.push(name, pop, country, lon, lat);
|
||||
});
|
||||
|
||||
await client.query(
|
||||
`INSERT INTO cities (name, population, country, geom) VALUES ${refinedQueryParts.join(',')}`,
|
||||
refinedValues
|
||||
`INSERT INTO cities (name, population, country, geom) VALUES ${queryParts.join(',')}`,
|
||||
values
|
||||
);
|
||||
|
||||
count += batch.length;
|
||||
|
||||
Reference in New Issue
Block a user