NAME

Imager::Bing::MapLayer - create a map layer for Bing Maps

SYNOPSIS

my $layer = Imager::Bing::MapLayer->new(
  base_dir           => $dir,     # base directory (default '.')
  overwrite          => 1,        # overwrite existing (default)
  autosave           => 1,        # save on exit (default)
  in_memory          => 0,        # keep tiles in memory (default false)
  min_level          => 1,        # min zoom level (default)
  max_level          => 19,       # max zoom level (default)
  combine            => 'darken', # tile composition method (default)
);

# Plot polygons (e.g. geographic boundaries)

$layer->polygon(
   points => $points,                  # listref to [ lat, lon ] points
   fill   => Imager::Fill->new( ... ), #
);

# Plot greyscale gradient circles for heatmaps

$layer->radial_circle(
    r      => 100,              # radius in meters
    -min_r => 1,                # minimum pixel radius for any zoom level
    x      => $longitude,       # longitude (x = east-west)
    y      => $latitude,        # latitude  (y = north-south)
);

# Blur filter

$layer->filter( type => 'gaussian', stddev => 1 );

# Colourise greyscale heatmaps

$layer->colourise();

DESCRIPTION

This module is a wrapper around the Imager::Draw module, which allows you to create Bing map layers using longitude and latitude coordinates.

The module will automatically map them to the appropriate points on tile files.

It adds the following options to drawing methods:

-min_level

The minimum zoom level to draw on.

-max_level

The maximum zoom level to draw on.

ATTRIBUTES

in_memory

The timeout for how many seconds a tile is kept in memory. The default is 0.

When a tile is timed out, it is saved to disk after each Imager drawing operation, and reloaded if it is later needed.

Setting this to a non-zero value keeps tiles in memory, but increases the memory requirements.

centroid_latitude

centroid_longitude

This is the centroid latitude and longitude for translating points to pixels. It defaults to a point in London.

You can probably get away with ignoring this, but if you are generating maps for different regions of the world, then you may consider changing this, or even maininging different map sets with different centroids.

overwrite

When true (default), existing tiles will be overwritten rather than edited.

Be wary of editing existing tiles, since antialiased lines and opaque fills will darken existing points rather than drawing over them.

autosave

When true (default), tiles will be automatically saved.

Alternatively, you can use the "save" method to manually save tiles.

Note that any times in memory when a script is interrupted may be lost. An alternative to add something to trap interruptions:

local $SIG{INT} = sub {
    state $int = 0;
    unless ($int) {
        $int=1;
        $image->save();
    }
    exit 1;
};

combine

The tile combination method. It defaults to darken.

tile_class

The base class used for tiles.

This can be used to subclass the tiles, for instance, to save tiles with a different filename to use with something other than Bing maps, e.g. Google Maps.

You might use something like:

  package MyTile;

  use Moose;
  extends 'Imager::Bing::MapLayer::Tile';

  use Path::Class;

  override 'build_filename' => sub {
    my ($self) = @_;
    my $file = file($self->base_dir, $self->level,
	            join(',', @{ $self->tile_coords }) . '.png');
    return $file->stringify;
  };

METHODS

levels

my @levels = @{ $layer->levels };

This returns a reference to a list of Imager::Bing::MapLayer::Level objects.

min_level

The minimum zoom level to generate.

max_level

The maximum zoom level to generate.

radial_circle

$layer->radial_circle(
    r      => $radius_in_meters,
    -min_r => $min_radius_in_pixels,
    x      => $longitude,
    y      => $latitude,
);

This method plots "fuzzy" greyscale circles, which are intended to be used for heatmaps. The radius is scaled appropriately for each zoom level in the layer.

If -min_r is specified, then a circle will always be drawn with that minimum radius: this ensures that lower zoom levels will always have a point plotted.

colourise

colorize

$layer->colourise();

The method colourises greyscale layers. It is intended to be used for heatmaps generated using the "radial_circle" method.

filter

$layer->filter( type => 'gaussian', stddev => 1 );

This applies Imager::Filters to every tile on every zoom level of the layer.

Be aware that some filter effects may enhance the edges of tiles in each zoom level.

setpixel

Draw a pixel at a specific latitude and longitude coordinate.

See the corresponding method in Imager::Draw for more information.

line

Draw a line between two coordinates.

See the corresponding method in Imager::Draw for more information.

box

Draw a box bounded by northwest and southeast coordinates.

See the corresponding method in Imager::Draw for more information.

polyline

Draw a polyline for a set of coordinates.

Note that a polyline is not closed. To draw a closed area, use the "polygon" method.

See the corresponding method in Imager::Draw for more information.

polygon

Draw a closed polygon for a set of coordinates.

See the corresponding method in Imager::Draw for more information.

arc

Draw an arc.

See the corresponding method in Imager::Draw for more information.

circle

Draw a circle.

See the corresponding method in Imager::Draw for more information.

string

Draw a text string.

TODO - the size is not scaled.

See the corresponding method in Imager::Draw for more information.

align_string

Draw an aligned text string.

TODO - the size is not scaled.

See the corresponding method in Imager::Draw for more information.

save

Save the tiles.

VIEWING MAP LAYERS

Bing Maps

You can view tiles using the following web page, replacing the credentials option with your Bing Maps Key:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
      xml:lang="en" lang="en">
  <head>
    <title>Tiles Test</title>
    <script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=en-gb"></script>
    <script>
     //<![CDATA[
     var map;
     function init(){
       var map_options = {
         credentials         : "YOUR BING MAPS KEY HERE",
         center              : new Microsoft.Maps.Location(51.5171, 0.1062),
         zoom 	       : 10,
         showMapTypeSelector : false,
         useInertia          : true,
         inertiaIntensity    : 0,
         tileBuffer          : 1,
         enableSearchLogo    : false,
         enableClickableLogo : false,
         showScalebar        : false
       }
       map = new Microsoft.Maps.Map(document.getElementById('mapviewer'), map_options);
       addDefaultTileLayer();
     }

     function addDefaultTileLayer(){
       var options = { uriConstructor: 'tiles/{quadkey}.png' };
       var tileSource = new Microsoft.Maps.TileSource(options);
       var tilelayer= new Microsoft.Maps.TileLayer({ mercator: tileSource });
       map.entities.push(tilelayer);
     }
    // ]]>
    </script>
  </head>
  <body onload="init();">
    <div id="mapviewer" style="position:relative;width:100%;height:700px;"></div>
  </body>
</html>

You can apply for a Bing Maps Key at https://www.bingmapsportal.com.

SEE ALSO

AUTHOR

Robert Rothenberg, <rrwo at cpan.org>

BUGS

Please report any bugs or feature requests to the author, or through the web interface at https://github.com/robrwo/Imager-Bing-MapLayer/issues.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Imager::Bing::MapLayer

You can also look for information at:

ACKNOWLEDGEMENTS

  • Foxtons, Ltd.

LICENSE AND COPYRIGHT

Copyright 2013-2014 Robert Rothenberg.

This program is released under the following license: atistic2