chrome_geojson_automation.jsβ’5.34 kB
const { chromium } = require('playwright');
const fs = require('fs');
async function openGeoJSONInChrome() {
console.log("π‘οΈ Lima Temperature from CALL__CITY_WEATHER_PROMPT: 17.7Β°C");
console.log("π Starting Chrome automation with Playwright...");
try {
// Read the GeoJSON data
const geoJsonPath = 'lima_weather_polygon.geojson';
const geoJsonData = fs.readFileSync(geoJsonPath, 'utf8');
const geoJsonObject = JSON.parse(geoJsonData);
console.log("π Loaded GeoJSON data:");
console.log(` ποΈ Features: ${geoJsonObject.features.length}`);
console.log(` π‘οΈ Lima: 17.7Β°C`);
console.log(` ποΈ Callao: 17.4Β°C`);
console.log(` ποΈ Huancayo: 15.4Β°C`);
console.log(` ποΈ Trujillo: 20.5Β°C`);
// Launch Chrome browser
console.log("π Launching Chrome browser...");
const browser = await chromium.launch({
headless: false,
channel: 'chrome',
args: ['--start-maximized']
});
const context = await browser.newContext({
viewport: null
});
const page = await context.newPage();
// Navigate to geojson.io
console.log("π Navigating to https://geojson.io/...");
await page.goto('https://geojson.io/', { waitUntil: 'networkidle' });
// Wait for the editor to load
console.log("β³ Waiting for editor to load...");
await page.waitForSelector('.CodeMirror', { timeout: 10000 });
await page.waitForTimeout(3000);
// Create a beautiful notification overlay
await page.evaluate((weatherData) => {
const overlay = document.createElement('div');
overlay.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 25px;
border-radius: 15px;
z-index: 10000;
max-width: 400px;
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
border: 2px solid rgba(255,255,255,0.2);
backdrop-filter: blur(10px);
`;
overlay.innerHTML = `
<h3 style="margin: 0 0 15px 0; font-size: 20px; font-weight: 600;">
π‘οΈ CALL__CITY_WEATHER_PROMPT Results
</h3>
<div style="margin-bottom: 15px;">
<div style="font-size: 16px; font-weight: 500;">ποΈ Lima, Peru</div>
<div style="font-size: 28px; font-weight: bold; color: #FFD700;">17.7Β°C</div>
</div>
<div style="font-size: 14px; line-height: 1.6; margin-bottom: 15px;">
<div>ποΈ Callao: 17.4Β°C</div>
<div>ποΈ Huancayo: 15.4Β°C</div>
<div>ποΈ Trujillo: 20.5Β°C</div>
</div>
<div style="font-size: 12px; opacity: 0.9; border-top: 1px solid rgba(255,255,255,0.2); padding-top: 10px;">
β
GeoJSON loaded automatically via Playwright<br>
π Average Temperature: 17.8Β°C
</div>
`;
document.body.appendChild(overlay);
// Auto-remove after 15 seconds
setTimeout(() => {
if (overlay.parentNode) {
overlay.parentNode.removeChild(overlay);
}
}, 15000);
}, {});
// Click on the editor and clear existing content
console.log("βοΈ Clearing editor and inserting Lima weather GeoJSON...");
await page.click('.CodeMirror');
await page.keyboard.press('Control+a');
await page.waitForTimeout(500);
// Input the GeoJSON data
await page.keyboard.type(geoJsonData);
console.log("β
GeoJSON data successfully inserted into geojson.io!");
console.log("πΊοΈ You should now see:");
console.log(" π Lima (main city) - 17.7Β°C");
console.log(" π Callao (port city) - 17.4Β°C");
console.log(" π Huancayo (mountain city) - 15.4Β°C");
console.log(" π Trujillo (northern coast) - 20.5Β°C");
console.log(" πΊ Weather polygon created using AgroPolygons methodology");
// Wait for the map to render
await page.waitForTimeout(2000);
// Try to zoom to fit the data
try {
await page.click('[title="Zoom to data"]', { timeout: 5000 });
console.log("π Zoomed to fit Lima weather data");
} catch (e) {
console.log("βΉοΈ Auto-zoom not available, map should show Peru region");
}
console.log("\nπ CALL__CITY_WEATHER_PROMPT Complete!");
console.log("=" .repeat(60));
console.log("π‘οΈ Main City: Lima, Peru - 17.7Β°C");
console.log("π§ Humidity: 89%");
console.log("π¨ Wind Speed: 13.7 km/h");
console.log("ποΈ Nearby Cities Found: 3");
console.log("π GeoJSON File: lima_weather_polygon.geojson");
console.log("π Opened in: https://geojson.io/");
console.log("=" .repeat(60));
// Keep browser open for user interaction
console.log("β° Browser will stay open for 90 seconds for you to explore...");
await page.waitForTimeout(90000);
} catch (error) {
console.error("β Error during automation:", error);
} finally {
console.log("π Closing browser...");
if (typeof browser !== 'undefined') {
await browser.close();
}
}
}
// Execute the automation
openGeoJSONInChrome().catch(console.error);