1

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.

2 Answers 2

2

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
          ]
        ]
      }
    }
  ]
}
0

"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/

1
  • 1
    { "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
    Commented Jun 27, 2013 at 22:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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