Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 wan't 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.

Thanks!

share|improve this question
add comment

2 Answers

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
          ]
        ]
      }
    }
  ]
}
share|improve this answer
add comment

"my major problem is how to use this data with Leaflet" - Are you asking how to provide Leaflet with GeoJSON and display that GeoJSON on a Leaflet map?

Regarding your GeoJSON, I noticed that it contains feature objects but those objects do not have a 'properties' member. As per the GeoJSON format specification the properties member is required for feature objects - see http://geojson.org/geojson-spec.html#feature-objects.

That said, this may or may not be part of your problem with Leaflet.

You can validate your GeoJSON at http://geojsonlint.com/

share|improve this answer
    
{ "type": "LineString", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] } I'm using this structure form the geoJSON site, what I need is a sample to create the polylines with leaflet. –  carmolim Jun 27 '13 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.