mapbox / tile-cover

Generate the minimum number of tiles to cover a geojson geometry
MIT License
189 stars 40 forks source link

geom vs. geometry in index.js #85

Closed IReese closed 4 years ago

IReese commented 4 years ago

The syntax standard for geoJSON for defining geometry tag is geometry .

The index.js uses geom for this tag.

The current work-around is to go back and change the geometry tag to geom in the geoJSON, then process using tile-cover.

Is it safe to update the index.js to use geometry instead? I could produce a PR if this is a worthy upgrade?

Example of failing test:

const fs = require('fs');
const cover = require('@mapbox/tile-cover');

var inTile = {"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[177.4832659,-37.617147],[177.5549797,-38.7750707],[178.4877353,-38.7348969],[178.4014969,-37.5785987],[177.4832659,-37.617147]]]},"properties":{"name":"test"}}

var limits = {
    min_zoom: 10,
    max_zoom: 12
};

var tilesOut = cover.geojson(inTile.geom, limits)
console.log(JSON.stringify(tilesOut))

Fails with error:

~/node_modules/@mapbox/tile-cover/index.js:58
        coords = geom.coordinates,
                      ^

TypeError: Cannot read property 'coordinates' of undefined
mourner commented 4 years ago

You seem to have misread the source — it doesn't use the geom property anywhere in the source. The issue is in the code of your "failing test".

IReese commented 4 years ago

Thank you for the response :) I see the issue now