[Geomoose-users] Legends in printable maps

Dan Little theduckylittle at gmail.com
Mon Dec 21 15:58:31 PST 2015


For those playing the home game:

- https://github.com/geomoose/geomoose/issues/99

On Tue, Jul 28, 2015 at 10:29 AM, Bistrais, Bob <Bob.Bistrais at maine.gov> wrote:
> I have been playing around with this and I have come up with something that
> works.  A bit crude and could probably be improved, but the bottom line is
> that you get a dynamic legend on the PDF maps.
>
>
>
> Most of the coding is done by modifying the existing print.php.  But first
> there’s a bit of setup work with the templates.  Modify your map templates
> so that you have an area to place the legend.
>
>
>
> Next, you need to create images of each legend item.  I simply took a
> screenshot of my GM application with all layers turned on, then in
> Paint.net, I created an image for each layer’s legend.  Save these to the
> application’s htdocs/images folder.
>
>
>
> Now for the code, again in the existing print.php file.  Insert this after
> the following line, around line 225:
>
>                 $pdf->Image($tempDir.$uniqueId.'_pdf.jpg', $imageX, $imageY,
> $imageW, $imageH);
>
>
>
> -Insert this:
>
>                 //-------------------------------- Add images to form legend
> elements
>
>                 //--------------------------------extract the list of layer
> names so that we can use them in the map legend
>
>                 // We will create a new array with layer names to put in
> legend.  We do this because I want to not include
>
>                 // certain layers (such as background layers), and I want to
> reverse the order, so the print map legend
>
>                 // will appear in the same order as on the web application.
>
>                 // If that doesn't matter to you, you can leave out the
> string comparison and array reversal code...
>
>
>
>                 //create new, empty array
>
>                 $legendLayers = array();
>
>
>
>                 //Iterate through print_info to get the actual layer names
>
>                 for($i=0;$i < sizeof($print_info); $i++){
>
>                                 for ($j=0;$j <
> sizeof($print_info[$i][layers]); $j++){
>
>                                                 $layName =
> $print_info[$i][layers][$j];
>
>                                                 //String comparison so we
> only select the layers we want in the legend...
>
>                                                 if((strcmp($layName,
> "Roads")) == 0 || (strcmp($layName, "Blks00")) == 0 || (strcmp($layName,
> "wicp")) == 0 || (strcmp($layName, "farmers_markets")) == 0 ||
> (strcmp($layName, "wic_vendors_large")) == 0 || (strcmp($layName,
> "wic_vendors_small")) == 0 || (strcmp($layName, "wic_clinics")) == 0) {
>
>                                                                 //add it to
> the array
>
>
> array_push($legendLayers, $layName);
>
>                                                 }
>
>                                 }
>
>                 }
>
>
>
>                 //reverse the array order
>
>                 $legendLayers = array_reverse($legendLayers);
>
>
>
>                 //Compose the legend onto the page
>
>                 //Set a few variables for legend element image size and
> position:
>
>                 $lx = 36; //Legend element, position from page left, pixels
>
>                 $ly = 110; //Legend element, position from page top, pixels.
> Will vary as elements are added, this is the position of first element.
>
>                 $lWidth = 100; //Legend element, image width, pixels
>
>                 $lHeight = 0; //Legend element, height, pixels, initializing
> at 0 but will change
>
>
>
>                 //Iterate through the new array ($legendLayers), place the
> legend elements on the map page
>
>                 for($i=0; $i<sizeof($legendLayers); $i++){
>
>                                 $imageName =
> '../images/'.$legendLayers[$i].'.png';
>
>                                 $lHeight = (getimagesize($imageName)[1] *
> 0.80); //Scaling down image height to 80% of actual image size, so it fits
>
>
> $pdf->Image($imageName,$lx,$ly,$lWidth,$lHeight);
>
>                                 $ly += ($lHeight + 5);
>
>                 }
>
>
>
>
>
> --- I added some if-then code that varies the placement of items depending
> on page size and orientation, but the above is the code used for 8-1/2X11,
> Landscape.
>
>
>
> So this is a fairly simple way of adding the legend to PDF maps, nothing
> fancy, but it works.  I hope this might help other GeoMoose users.
>
>
>
> -Bob
>
>
>
>
>
> From: Basques, Bob (CI-StPaul) [mailto:bob.basques at ci.stpaul.mn.us]
> Sent: Thursday, July 23, 2015 6:13 PM
> To: TC Haddad
> Cc: Bistrais, Bob; geomoose-users at lists.osgeo.org
> Subject: Re: [Geomoose-users] Legends in printable maps
>
>
>
> All,
>
>
>
> We’ve talked about this for years in my shop, all sorts of ways to approach
> this . . .
>
>
>
> Something else to think about on this, might be a method to set up a extra
> layer on the fly for each layer turned on and add that on top pf the map.
>
>
>
> bobb
>
>
>
>
>
> On Jul 23, 2015, at 4:41 PM, TC Haddad <tchaddad at gmail.com> wrote:
>
>
>
>
>
> I never filed anything in GitHub about it, but I did dig around a bit for
> some old code that would embed a legend in the PDF. I think with some
> modifications, it can be made to work. Beyond that I got busy, and never
> came back around to it.
>
> I still think it's a good idea, and also have folks who would like to use
> it. I'll open an enhancement issue, and start adding what little items I
> have dug up...
>
> Tanya
>
>
>
>
>
>
>
> On Thu, Jul 23, 2015 at 2:13 PM, Bistrais, Bob <Bob.Bistrais at maine.gov>
> wrote:
>
> I saw this topic came up pretty recently:
> http://lists.osgeo.org/pipermail/geomoose-users/2015-April/005601.html
>
>
>
> Has there been any progress on that?  I have a project where the client is
> interested in a printed legend.
>
>
> _______________________________________________
> Geomoose-users mailing list
> Geomoose-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geomoose-users
>
>
>
> _______________________________________________
> Geomoose-users mailing list
> Geomoose-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geomoose-users
>
>
>
>
> _______________________________________________
> Geomoose-users mailing list
> Geomoose-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geomoose-users


More information about the Geomoose-users mailing list