• Oct
  • 30
  • 2010

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

by Andrew Kandels

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 didnt want a huge hassle with a big charting package and I didnt need all the bells and whistles — just make the states shade darker to represent usage trends on a report:

Preview

Download

PHPStateMapper is now available for download at the project's GitHub page. 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.

Future Plans

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

  1. More reporting styles
  2. More maps
  3. More loaders
  4. Making it a PEAR library for easy installation
  5. Latitude/longitude importer for raw coordinate loading

License

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