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:
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:
- More reporting styles – like inflating circles or red/blue states.
- More maps (currently only U.S.).
- More loaders (currently only CSV/PHP object calls).
- Making it a PEAR library for easy installation.
- Latitude/longitude importer for raw coordinate loading.
The project is released under the BSD license. Use it however and wherever you like. Enjoy :)

