write a javascript function that takes in a longitude and latitude and returns the…
- User
write a javascript function that takes in a longitude and latitude and returns the features from those coordinates from a .pmtiles file
Assistant
Here is a function that takes in longitude and latitude coordinates and returns the features from those coordinates from a .pmtiles file:
function getFeaturesFromCoordinates(lon, lat) { // Open pmtiles file const pmtiles = require('./path/to/pmtiles.json'); // Find tile containing coordinates const tileZoom = 14; // Tile zoom level const x = Math.floor(lon/360 + 0.5) * Math.pow(2, tileZoom); const y = Math.floor((1 - Math.log(Math.tan(lat * Math.PI/180) + 1 / Math.cos(lat * Math.PI/180))/Math.PI) / 2 * Math.pow(2, tileZoom)); // Get features from tile const tile = pmtiles.tiles[y][x]; return tile.features; } // Example usage const lon = -73.5; const lat = 40.7; const features = getFeaturesFromCoordinates(lon, lat);This function:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.