[GIS] How to create multiple polylines using an external geoJSON file using Leaflet

geojsonleafletline

I'm starting with Leaflet and I'm using some georeferenced information collected from twitter. I already manage to load an external geoJSON with some points. But now I want to draw some connections between the points to show some relationships.

I have a list with users and each user has a list of points.
Here's a sample with two lines:

  {
      "type": "FeatureCollection",
      "features": [
              {
              "type": "LineString",
              "coordinates": [
              [
              -43.48283,
              -23.02487
              ],
              [
              -43.48391,
              -23.02475
              ],
              [
              -43.48233,
              -23.02486
              ],
              [
              -43.48212,
              -23.02443
              ],
              [
              -43.48243,
              -23.02429
              ],
              [
              -43.48245,
              -23.02477
              ]
      ]
      },
              {
              "type": "LineString",
              "coordinates": [
              [
              -46.65953,
              -23.55865
              ],
              [
              -46.65953,
              -23.55790
              ],
              [
              -46.65972,
              -23.55809
              ],
              [
              -46.65941,
              -23.55878
              ],
              [
              -46.65953,
              -23.55896
              ],
              [
              -46.65903,
              -23.55888
              ]
              ]
              }
      ]
 }

I don't know if this is the best structure to create multiple polylines, but that is easy to fix, my major problem is how to use this data with Leaflet.

Need some help.

Best Answer

A feature collection object contains an array of features, you gave it an array of geometries try

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "id": 1
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            -43.48283,
            -23.02487
          ],
          [
            -43.48391,
            -23.02475
          ],
          [
            -43.48233,
            -23.02486
          ],
          [
            -43.48212,
            -23.02443
          ],
          [
            -43.48243,
            -23.02429
          ],
          [
            -43.48245,
            -23.02477
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "id": 2
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            -46.65953,
            -23.55865
          ],
          [
            -46.65953,
            -23.5579
          ],
          [
            -46.65972,
            -23.55809
          ],
          [
            -46.65941,
            -23.55878
          ],
          [
            -46.65953,
            -23.55896
          ],
          [
            -46.65903,
            -23.55888
          ]
        ]
      }
    }
  ]
}