Badge 2

Shade in Areas of a Map and Export to a PNG with the PHPStateMapper Library

PHPStateMapper is an open source PHP library for drawing a map with areas shaded by varying degrees of intensity based on data given as a simple list (e.g.: MN: 5, WI: 12, MI: 23). It exports a PNG image in a configurable size and color.

I’ve wanted this for awhile. I had a table with states and the number of users from that state in a CSV file (a report I exported). I wanted to show this on a map. I didn’t want a huge hassle with a big charting package and I didn’t need all the bells and whistles — just make the states shade darker to represent usage trends on a report:

Preview

And so I wrote PHPStateMapper. The first version of my PHPStateMapper script is now available for download at the project page here. It’s features include:

  • Easy to deploy – Only an include and a few lines of code.
  • Custom size – Anywhere between 100 and 2,000 pixels wide for web or printing.
  • Custom color – Just give it a hex color when you instantiate the object.
  • Extendible – Just about any map can be added.
  • Clean code – Object oriented, PHP 5+ well documented source code.
  • Easy to seed – Use the CSV importer object or just pass the data into the object.

In the near future, I plan on adding a few more features, such as:

  1. More reporting styles – like inflating circles or red/blue states.
  2. More maps (currently only U.S.).
  3. More loaders (currently only CSV/PHP object calls).
  4. Making it a PEAR library for easy installation.
  5. Latitude/longitude importer for raw coordinate loading.

The project is released under the BSD license. Use it however and wherever you like. Enjoy :)

  • Facebook
  • Twitter

Both comments and pings are currently closed.

Comments are closed.