mel
mel

Reputation: 21

Polygons with GeoJson & Polymaps

I'm a beginner at mapping and decided to use Polymaps for a project I'm working on. I have a dataset I want to serve to the map by zip code. We're testing with counties right now and all I'm trying to do is get the county shapes to show on the map.

I added the geoJson to the map, pulling in my .json file. After some research I think I need to parse the json but I'm not sure how to go about that and I couldn't glean much from the Polymaps documentation.

Any insight or beginner tutorials would be great. Thank you!

var po = org.polymaps;

var map = po.map()
    .container(document.getElementById("map").appendChild(po.svg("svg")))
    .center({lat: 38.89859, lon: -77.035971})
    .zoom(7)
    .zoomRange([4, 7])
    .add(po.interact());

map.add(po.image()
    .url(po.url("http://{S}tile.cloudmade.com"
    + "/1a1b06b230af4efdbb989ea99e9841af" // http://cloudmade.com/register
    + "/20760/256/{Z}/{X}/{Y}.png")
    .hosts(["a.", "b.", "c.", ""])));

map.add(po.geoJson()
    .features([{"geometry":{"coordinates":paths, "type": "Polygon"}}])
    .url("testCounties.json"));

Upvotes: 2

Views: 3460

Answers (1)

Drew Dara-Abrams
Drew Dara-Abrams

Reputation: 8054

I think you need to change this:

map.add(po.geoJson() .features([{"geometry":{"coordinates":paths, "type": "Polygon"}}]) .url("testCounties.json"));

to this:

map.add(po.geoJson().url("testCounties.json"));

Note that there is no space after geoJson(). And more importantly, you should use geoJson.features OR geoJson.url, not both. You would use geoJson.features if you had your geojson data stored locally in JavaScript, but because you are pointing to an external json file, you should just use geojson.url.

Perhaps this example is like what you're trying to do: http://polymaps.org/ex/population.html

Upvotes: 1

Related Questions