Skip to content

Commit 529583d

Browse files
author
Casey Thomas
authored
Merge pull request #26 from caseypt/feature/cpt/new-tests-update-readme
Add test, update README, push v0.4.0
2 parents 22fb0e5 + 83ef67a commit 529583d

5 files changed

Lines changed: 42 additions & 33 deletions

File tree

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ In the browser, the library is available at `GeoJSON`.
1717

1818
## Example Usage
1919

20-
The library has one method, `parse`, which takes an array of objects with geometry data as the first parameter, an object consisting of settings for the second parameter, and an optional callback function as the third parameter. If a callback is not specified, the `parse` function returns the GeoJSON output.
20+
The library has one method, `parse`, which takes an array of objects (or a single object) with geometry data as the first parameter, an object consisting of settings for the second parameter, and an optional callback function as the third parameter. If a callback is not specified, the `parse` function returns the GeoJSON output.
2121

2222
Take the example data below:
23-
23+
2424
```javascript
2525
var data = [
2626
{ name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
@@ -30,30 +30,30 @@ var data = [
3030
```
3131

3232
Convert it to GeoJSON:
33-
33+
3434
```javascript
3535
GeoJSON.parse(data, {Point: ['lat', 'lng']});
3636

37-
{
37+
{
3838
"type": "FeatureCollection",
3939
"features": [
4040
{ "type": "Feature",
4141
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
42-
"properties": {
42+
"properties": {
4343
"name": "Location A",
4444
"category": "Store"
4545
}
4646
},
4747
{ "type": "Feature",
4848
"geometry": {"type": "Point", "coordinates": [-75.833, 39.284]},
49-
"properties": {
49+
"properties": {
5050
"name": "Location B",
5151
"category": "House"
5252
}
5353
},
5454
{ "type": "Feature",
5555
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
56-
"properties": {
56+
"properties": {
5757
"name": "Location C",
5858
"category": "Office"
5959
}
@@ -63,23 +63,23 @@ GeoJSON.parse(data, {Point: ['lat', 'lng']});
6363
```
6464

6565
Convert the example data to GeoJSON, and only include the `name` attribute in `properties` for each feature.
66-
66+
6767
```javascript
6868
GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']});
6969

70-
{
70+
{
7171
"type": "FeatureCollection",
7272
"features": [
7373
{ "type": "Feature",
7474
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
75-
"properties": {
75+
"properties": {
7676
"name": "Location A"
7777
}
7878
},
7979
...
8080
{ "type": "Feature",
8181
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
82-
"properties": {
82+
"properties": {
8383
"name": "Location C"
8484
}
8585
}
@@ -88,27 +88,27 @@ GeoJSON.parse(data, {Point: ['lat', 'lng'], include: ['name']});
8888
```
8989

9090
You can also convert a single object to a GeoJSON feature:
91-
91+
9292
```javascript
9393
var singleobject = { name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 }
9494

9595
GeoJSON.parse(singleobject, {Point: ['lat', 'lng']});
9696

97-
{
97+
{
9898
"type": "Feature",
9999
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
100-
"properties": {
100+
"properties": {
101101
"name": "Location A",
102102
"category": "Store"
103103
}
104104
}
105105
```
106-
106+
107107
The `parse` method can handle data with different geometry types. Consider the following sample data:
108108

109109
```javascript
110110
var data2 = [
111-
{
111+
{
112112
x: 0.5,
113113
y: 102.0,
114114
prop0: 'value0'
@@ -255,9 +255,9 @@ or
255255

256256
GeoJSON.parse(data, {Point: 'coords'});
257257

258-
The valid geometry types are
258+
The valid geometry types are
259259

260-
- `Point`
260+
- `Point`
261261
- `MultiPoint`
262262
- `LineString`
263263
- `MultiLineString`
@@ -307,12 +307,12 @@ You can add arbitrary properties to features using the `extra` param. The value
307307
}
308308
});
309309

310-
{
310+
{
311311
"type": "FeatureCollection",
312312
"features": [
313313
{ "type": "Feature",
314314
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
315-
"properties": {
315+
"properties": {
316316
"name": "Location A",
317317
"category": "Store",
318318
"style": {
@@ -330,27 +330,27 @@ You can add arbitrary properties to features using the `extra` param. The value
330330
You can also add dataset properties using the `extraGlobal` param. The value for `extraGlobal` must be an object.
331331

332332
GeoJSON.parse(data, {
333-
Point: ['lat', 'lng'],
333+
Point: ['lat', 'lng'],
334334
extraGlobal: {
335-
'Creator': 'Mr. Example',
336-
'records': data.length,
335+
'Creator': 'Mr. Example',
336+
'records': data.length,
337337
'summary': 'A few example points'
338338
}
339339
});
340340

341-
{
341+
{
342342
"type": "FeatureCollection",
343343
"features": [
344344
{ "type": "Feature",
345345
"geometry": {"type": "Point", "coordinates": [-75.343, 39.984]},
346-
"properties": {
346+
"properties": {
347347
"name": "Location A"
348348
}
349349
},
350350
...
351351
{ "type": "Feature",
352352
"geometry": {"type": "Point", "coordinates": [ -75.534, 39.123]},
353-
"properties": {
353+
"properties": {
354354
"name": "Location C"
355355
}
356356
}

geojson.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(function(GeoJSON) {
2-
GeoJSON.version = '0.3.1';
2+
GeoJSON.version = '0.4.0';
33

44
// Allow user to specify default parameters
55
GeoJSON.defaults = {};
@@ -145,7 +145,7 @@
145145
// Geometry parameter specified as: {Point: 'coords'}
146146
if(typeof val === 'string' && item.hasOwnProperty(val)) {
147147
if(gtype === 'GeoJSON') {
148-
geom = item[val]
148+
geom = item[val];
149149
} else {
150150
geom.type = gtype;
151151
geom.coordinates = item[val];

geojson.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "geojson",
3-
"description": "Convert an array of geographic objects to GeoJSON",
3+
"description": "Turn your geo data into GeoJSON",
44
"author": "Casey Thomas <caseypthomas@gmail.com>",
55
"license": "MIT",
66
"keywords": "geojson",
7-
"version": "0.3.1",
7+
"version": "0.4.0",
88
"main": "./geojson",
99
"repository": {
1010
"type": "git",

test/test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,16 @@ describe('GeoJSON', function() {
395395
expect(output.features[0].geometry.coordinates[1]).to.equal(10.1);
396396
expect(output.features[0].geometry.type).to.equal('Point');
397397
expect(output.features[0].properties.name).to.equal('Location A');
398+
});
399+
400+
it("converts string coordinates into numbers", function() {
401+
var data = [{ lat: '39.343', lng: '-74.454'}];
402+
var output = GeoJSON.parse(data, {Point: ['lat', 'lng']});
398403

404+
output.features.forEach(function(feature) {
405+
expect(feature.geometry.coordinates[0]).to.be.a('number');
406+
expect(feature.geometry.coordinates[1]).to.be.a('number');
407+
});
399408
});
400409
});
401410
});

0 commit comments

Comments
 (0)