County Polygons

If you’re interested in Polygons, click the image below, then click anywhere on the Bing Map and select the Counties option. Click on a county name to explore it…

Update: Microsoft’s new Bing Maps Version 8 has no way of naming a polygon when it’s created, so that I know what to do with it when it’s clicked, like the name of the County in my case. So I invented my own technique. The API lets you set the RGB color value fillColor: rgba(255, 255, 255, 1.0) for each Polygon, and detect it on a click, so I set the blue value to a sequentially incrementing number from 0-255 and the opacity value to 0.0 so you don’t see the color change, and then use the blue value as an index into an array of county names. Pretty cool huh! Fortunately, Texas only has 254 counties, otherwise, it wouldn’t work…

Update 2: (5/19/16) Map god Ricky from Microsoft showed me today how to do it, via the Forum:

You can add custom information to any shape in Bing Maps. Pushpins, Polylines, and Polygons all derive from a common interface called IPrimitive. You can add custom data to any IPrimitive classes using the metadata property. For example:

var polygon = ... (Jim here, won't bore you with this stuff :-)

polygon.metadata = {customProperty: "custom value"};

map.entities.push(polygon);

Aha! How come my faithful readers (who have probably bailed on me by now) didn’t know this? Anyway, I implemented it and it works great!

Except perhaps Alaska, Hawaii, and California, the polygons are a bit messed up.

Hey, if you’re interested in exploring the home pages of Cities and Counties in the United States, click below. Otherwise, wait until I get my ass in gear and create a more fluffy post with pictures from the bus, or family shit, or whatever…

Published
Categorized as Site Stuff

Leave a comment