Skip to content

Commit

Permalink
doc: Fix remaining reference to mapbox.js
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Jan 18, 2019
1 parent 3d188a3 commit 46d7973
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 33 deletions.
17 changes: 9 additions & 8 deletions README.md
Expand Up @@ -24,7 +24,7 @@ holding an XML DOM.

The output is a JavaScript object of GeoJSON data. You can convert it to a string
with [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
or use it directly in libraries.js](http://www.mapbox.com/mapbox.js/).
or use it directly in libraries.

### `toGeoJSON.gpx(doc)`

Expand All @@ -50,23 +50,24 @@ Install it into your project with `npm install --save @tmcw/togeojson`.
```javascript
// using togeojson in nodejs

var tj = require('@tmcw/togeojson'),
fs = require('fs'),
// node doesn't have xml parsing or a dom. use xmldom
DOMParser = require('xmldom').DOMParser;
const tj = require('@tmcw/togeojson');
const fs = require('fs');
// node doesn't have xml parsing or a dom. use xmldom
const DOMParser = require('xmldom').DOMParser;

var kml = new DOMParser().parseFromString(fs.readFileSync('foo.kml', 'utf8'));
const kml = new DOMParser().parseFromString(fs.readFileSync('foo.kml', 'utf8'));

var converted = tj.kml(kml);
const converted = tj.kml(kml);

var convertedWithStyles = tj.kml(kml, { styles: true });
const convertedWithStyles = tj.kml(kml, { styles: true });
```

## Browser

```html
<script type=module>
import {kml} from "https://unpkg.com/@tmcw/togeojson?module";
fetch('test/data/linestring.kml').then(function(response) {
return response.xml();
}).then(function(xml) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@tmcw/togeojson",
"version": "1.0.0",
"version": "1.0.0-beta.1",
"description": "convert KML and GPX to GeoJSON",
"source": "index.js",
"umd:main": "dist/togeojson.umd.js",
Expand Down
40 changes: 16 additions & 24 deletions togeojson
@@ -1,41 +1,33 @@
#!/usr/bin/env node

const tj = require("./"),
const tj = require("./");
const argv = require("minimist")(process.argv.slice(2));
const getStdin = require("get-stdin");
const fs = require("fs");
const xmldom = new (require("xmldom")).DOMParser();

var filename = argv._[0] || "",
filetype = argv.f || "kml";

if (filename.match(/\.kml$/i)) filetype = "kml";
if (filename.match(/\.gpx$/i)) filetype = "gpx";

if (!tj[filetype] || (process.stdin.isTTY && !argv._[0])) {
help();
process.exit(0);
}

if (argv._.length) {
convert(fs.readFileSync(argv._[0], "utf8"));
} else {
getStdin().then(convert);
}
const filename = argv._[0] || "";
const filetype = argv.f
? argv.f
: filename.match(/\.kml$/i)
? "kml"
: filename.match(/\.gpx$/i)
? "gpx"
: "kml";

function convert(data) {
process.stdout.write(
JSON.stringify(
tj[filetype](xmldom.parseFromString(data.toString())),
null,
4
)
JSON.stringify(tj[filetype](xmldom.parseFromString(data)), null, 4)
);
}

function help() {
if (!tj[filetype] || (process.stdin.isTTY && !argv._.length)) {
console.error(
"Usage: togeojson [-f format] FILE\n" +
"-f file format. if not given, will be detected by filename"
"-f file format. if not given, will be detected by filename (kml or gpx)"
);
} else if (argv._.length) {
convert(fs.readFileSync(argv._[0], "utf8"));
} else {
getStdin().then(convert);
}

0 comments on commit 46d7973

Please sign in to comment.