Dynamic Google Maps Markers i.e. with Labels

Yesterday I had a little experience that pretty much looked like this

The main challenge was that I had implemented Google Maps, integrated MarkerCluster and got it to look like this.

Client liked the cluster but wanted it to be clickable (for popups). Unfortunately,  MarkerCluster doesn’t support clicks, and Google’s Marker doesn’t support those little numbers on top of the Markers. So I created a little hack that solves the problem as shown below.

The solution is pretty simple as the code below shows. Basically I created a blank marker and used PHP GD to write the appropriate count on the marker. Pretty simple right? Fortunately it works! 😀

One issue though, caching is important if you wanna go live with this solution. No point creating the same markers over and over again.

$im = imagecreatefrompng($this->Html->url('/img/marker_blank.png', true)); # Set Full URL of marker image (cakephp helper)
imagealphablending($im, false);
imagesavealpha($im, true);
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($count)) / 2;
imagestring($im, 3, $px+1, 9, $count, $orange);
header("Content-type: image/png");

PHPExcel – Simply fantastic!!!

Thanks to David Umoh I’m encouraged to write again. Nothing beats others finding your writings useful and that made me really glad, after all that’s the reason I write.

I recently decided to implement an invoice generator (a personal project) and  first thing that came to my mind is PHPExcel and I thought this is an excellent topic to write on.

PHPExcel is an excellent PHP library that can generate Excel 2003, Excel 2007, CSV, PDF, and HTML documents. As its name implies the main purpose is for the generation of Excel documents. PHPExcel not only generates excel documents but it can read excel documents. It is feature-rich, supports cell styling, adding data and formulas, pictures, and much more.

One thing I really love about it is that to switch between formats. For example, I once created a report generator with it and I could easy output PDF, CSV, Html, Excel formats by just changing a few parameters.

Here is an example of a document generated using PHPExcel.

PHP Excel Example from phpexcel.codeplex.com

PHP Excel Example from phpexcel.codeplex.com