Guest User

Untitled

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. const GeoJSON = require('./geojson');
  2.  
  3. const data = [
  4. { name: 'Location A', category: 'Store', street: 'Market', lat: 39.984, lng: -75.343 },
  5. { name: 'Location B', category: 'House', street: 'Broad', lat: 39.284, lng: -75.833 },
  6. { name: 'Location C', category: 'Office', street: 'South', lat: 39.123, lng: -74.534 }
  7. ];
  8.  
  9. console.log(GeoJSON.parse(data, {Point: ['lat', 'lng']}));
  10.  
  11. /*
  12. {
  13. "type": "FeatureCollection",
  14. "features": [{
  15. "type": "Feature",
  16. "geometry": {
  17. "type": "Point",
  18. "coordinates": [-75.343, 39.984]
  19. },
  20. "properties": {
  21. "name": "Location A",
  22. "category": "Store",
  23. "street": "Market"
  24. }
  25. }, {
  26. "type": "Feature",
  27. "geometry": {
  28. "type": "Point",
  29. "coordinates": [-75.833, 39.284]
  30. },
  31. "properties": {
  32. "name": "Location B",
  33. "category": "House",
  34. "street": "Broad"
  35. }
  36. }, {
  37. "type": "Feature",
  38. "geometry": {
  39. "type": "Point",
  40. "coordinates": [-74.534, 39.123]
  41. },
  42. "properties": {
  43. "name": "Location C",
  44. "category": "Office",
  45. "street": "South"
  46. }
  47. }]
  48. }
  49. */
  50.  
  51. const data2 = [
  52. {
  53. x: 0.5,
  54. y: 102.0,
  55. prop0: 'value0'
  56. },
  57. {
  58. line: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]],
  59. prop0: 'value0',
  60. prop1: 0.0
  61. },
  62. {
  63. polygon: [
  64. [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
  65. ],
  66. prop0: 'value0',
  67. prop1: {"this": "that"}
  68. }
  69. ];
  70.  
  71. console.log(GeoJSON.parse(data2, {'Point': ['x', 'y'], 'LineString': 'line', 'Polygon': 'polygon'}));
  72.  
  73. /*
  74. {
  75. "type": "FeatureCollection",
  76. "features": [{
  77. "type": "Feature",
  78. "geometry": {
  79. "type": "Point",
  80. "coordinates": [102, 0.5]
  81. },
  82. "properties": {
  83. "prop0": "value0"
  84. }
  85. }, {
  86. "type": "Feature",
  87. "geometry": {
  88. "type": "LineString",
  89. "coordinates": [
  90. [102, 0],
  91. [103, 1],
  92. [104, 0],
  93. [105, 1]
  94. ]
  95. },
  96. "properties": {
  97. "prop0": "value0",
  98. "prop1": 0
  99. }
  100. }, {
  101. "type": "Feature",
  102. "geometry": {
  103. "type": "Polygon",
  104. "coordinates": [
  105. [
  106. [100, 0],
  107. [101, 0],
  108. [101, 1],
  109. [100, 1],
  110. [100, 0]
  111. ]
  112. ]
  113. },
  114. "properties": {
  115. "prop0": "value0",
  116. "prop1": {
  117. "this": "that"
  118. }
  119. }
  120. }]
  121. }
  122. */
Add Comment
Please, Sign In to add comment