Robert Rothenberg

NAME

Imager::Bing::MapLayer::Utils - utility functions for map layer modules

DESCRIPTION

This module contains utility functions for Imager::Bing::MapLayer.

EXPORTS

By default, none. Constants and functions must be included in the usage line explicitly.

CONSTANTS

$TILE_WIDTH

$TILE_HEIGHT

The width and height of individual tiles.

$MIN_ZOOM_LEVEL

$MIN_ZOOM_LEVEL

The minimum and maximum zoom levels supported by these modules.

Note that $MAX_ZOOM_LEVEL can actually be as high as 23, but that causes bit overflows for calculations on 32-bit integers. We also

don't want to generate tiles beyond level 18, since the amount of tiles required is so large that we run out of memory (and we also don't need it, since Bing switches to a street view mode).

When the tiles are not saved in memory, then we can generate higher resolutions. However, Bing doesn't seem to support zoom levels higher than 19 at this time.

FUNCTIONS

width_at_level

  my $width = width_at_level( $level );

Returns the width of a zoom level.

latlon_to_pixel

  my ($pixel_x, $pixel_y) = latlon_to_pixel( $level, $latitude, $longitude );

Converts latitude and longitude to pixel coodinates on a specific zoom level.

pixel_to_tile_coords

  my ($tile_x, $tile_y) = pixel_to_tile_coords( $pixel_x, $pixel_y );

Converts pixel coordinates to map tile coordinates.

tile_coords_to_pixel_origin

  my ($origin_x, $origin_y) = tile_coords_to_pixel_origin( $tile_x, $tile_y );

Returns the top-left pixel coordinates from tile coordinates.

tile_coords_to_quad_key

  my $quad_key = tile_coords_to_quad_key( $level, $tile_x, $tile_y );

Returns the quadrant key ("quad key") for a given tile at a given level.

quad_key_to_tile_coords

    my ($tile_x, $tile_y, $level) = quad_key_to_tile_coords( $quad_key );

Returns the tile coordinates and level from the quad key.

get_ground_resolution

    $meters_per_pixel = get_ground_resolution( $level, $latitude );

This returns the distance on the ground that's represented by a single pixel.

get_map_scale

TODO

bounding_box

    my ($left, $top, $right, $bottom) = bounding_box( %args );

This parses the arguments given to Imager::Draw methods to calculate a bounding box.

optimize_points

    my @points2 = @{ optimize_points( \@points ) };

This function takes a reference to a list of points and returns another reference to a list of points, without adjacent duplicate points. This reduces the number of points to plot for complex polylines on lower zoom levels.

SEE ALSO

A discussion of the Bing Maps Tile System

http://msdn.microsoft.com/en-us/library/bb259689.aspx