Skip to content

Instantly share code, notes, and snippets.

@SciutoAlex
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save SciutoAlex/c04c7db9c26dac13b436 to your computer and use it in GitHub Desktop.

Select an option

Save SciutoAlex/c04c7db9c26dac13b436 to your computer and use it in GitHub Desktop.
Dynamically adding geographic elements to a map

Sometimes you want to allow users or your program to dynamically add geographic features to a map graphic. In order to achieve this with D3, you can create geoJSON objects and then use D3 to project and draw the elements.

GeoJSON objects are specifically formatted JSON objects (see the full specification). When making even small maps, geoJSON objects become huge with featureCollections and geometryCollections, but in their simplest form, they look like:

var geoFeature = {
    "type":"Feature",
    "properties" : null,
    "geometry": {
        "type":"LineString",
        "coordinates": [
          [ pointaLat, pointaLon ], 
          [ pointbLat, pointbLon ]
        ]
    }
}

Without using OGR2OGR or topoJson command line interface or your choice GIS software, you can create your own simple geographic elements directly in your application. Elements can include lines, multilines, polygons--just change the "type" property.

Some useful links:

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment