Skip to content

Commit

Permalink
Spun off Geo::Google::PolylineEncoder
Browse files Browse the repository at this point in the history
  • Loading branch information
spurkis committed Apr 24, 2008
0 parents commit d4d7f54
Show file tree
Hide file tree
Showing 12 changed files with 2,689 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Build.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/perl

=head1 NAME
Build.PL - Build script generator for C<Geo::Google::PolylineEncoder> module
=head1 SYNOPSIS
perl Build.PL
./Build
./Build test
./Build install
=cut

use strict;
use warnings;
use File::Spec;
use Module::Build;

my $build = Module::Build->new
(
module_name => 'Geo::Google::PolylineEncoder',
dist_version_from => 'lib/Geo/Google/PolylineEncoder.pm',
create_makefile_pl => 'passthrough',
create_readme => 1,
license => 'perl',
requires => {
'perl' => '5.6.0',
'Geo::Gpx' => '0.01',
},
build_requires => {
'Test::More' => '0.01',
'Module::Build' => '0.20',
'IO::File' => '0.01',
},
build_reccomends => {
'Test::Approx' => '0.01',
},

);

$build->create_build_script;


__END__
=head1 AUTHOR
Steve Purkis <[email protected]>
=cut
7 changes: 7 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Revision history for 'Test-Approx' Perl module
----------------------------------------------

All changes by Steve Purkis, unless otherwise noted.

0.01
+ created Thurs Apr 24 2008
12 changes: 12 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Build.PL
Changes
lib/Geo/Google/PolylineEncoder.pm
Makefile.PL
MANIFEST This list of files
META.yml
README
t/01_basic.t
t/data/20061226.gpx
t/data/20061227.gpx
t/data/20061228.gpx
t/data/MtMitchell.gpx
39 changes: 39 additions & 0 deletions MANIFEST.SKIP
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Avoid version control files.
\bRCS\b
\bCVS\b
,v$
\B\.svn\b
\B\.cvsignore$

# Avoid Makemaker generated and utility files.
\bMakefile$
\bblib
\bMakeMaker-\d
\bpm_to_blib$
\bblibdirs$
^MANIFEST\.SKIP$

# Avoid Module::Build generated and utility files.
\bBuild$
\bBuild.bat$
\b_build

# Avoid Devel::Cover generated files
\bcover_db

# Avoid temp and backup files.
~$
\.tmp$
\.old$
\.bak$
\#$
\.#
\.rej$

# Avoid OS-specific files/dirs
# Mac OSX metadata
\B\.DS_Store
# Mac OSX SMB mount metadata files
\B\._
# Avoid archives of this distribution
\bTest-Approx-[\d\.\_]+
24 changes: 24 additions & 0 deletions META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Geo-Google-PolylineEncoder
version: 0.02
author:
- 'Steve Purkis <[email protected]>'
abstract: encode lat/lngs to Google Maps Polylines
license: perl
resources:
license: http://dev.perl.org/licenses/
requires:
Geo::Gpx: 0.01
perl: 5.6.0
build_requires:
IO::File: 0.01
Module::Build: 0.20
Test::More: 0.01
provides:
Geo::Google::PolylineEncoder:
file: lib/Geo/Google/PolylineEncoder.pm
version: 0.02
generated_by: Module::Build version 0.2808
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.2.html
version: 1.2
31 changes: 31 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Note: this file was auto-generated by Module::Build::Compat version 0.03

unless (eval "use Module::Build::Compat 0.02; 1" ) {
print "This module requires Module::Build to install itself.\n";

require ExtUtils::MakeMaker;
my $yn = ExtUtils::MakeMaker::prompt
(' Install Module::Build now from CPAN?', 'y');

unless ($yn =~ /^y/i) {
die " *** Cannot install without Module::Build. Exiting ...\n";
}

require Cwd;
require File::Spec;
require CPAN;

# Save this 'cause CPAN will chdir all over the place.
my $cwd = Cwd::cwd();

CPAN::Shell->install('Module::Build::Compat');
CPAN::Shell->expand("Module", "Module::Build::Compat")->uptodate
or die "Couldn't install Module::Build, giving up.\n";

chdir $cwd or die "Cannot chdir() back to $cwd: $!";
}
eval "use Module::Build::Compat 0.02; 1" or die $@;

Module::Build::Compat->run_build_pl(args => \@ARGV);
require Module::Build;
Module::Build::Compat->write_makefile(build_class => 'Module::Build');
133 changes: 133 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
NAME
Geo::Google::PolylineEncoder - encode lat/lngs to Google Maps Polylines

SYNOPSIS
use Geo::Google::PolylineEncoder;

my $points = [
{ lat => 38.5, lon => -120.2 },
{ lat => 40.7, lon => -120.95 },
{ lat => 43.252, lon => -126.453 },
];
my $encoder = Geo::Google::PolylineEncoder->new;
my $eline = $encoder->encode( $points );
print $eline->{num_levels}; # 18
print $eline->{zoom_factor}; # 2
print $eline->{points}; # _p~iF~ps|U_ulLnnqC_mqNvxq`@
print $eline->{levels}; # POP

# in Javascript, assuming eline was encoded as JSON:
# ... load GMap2 ...
var opts = {
points: eline.points,
levels: eline.levels,
numLevels: eline.num_levels,
zoomFactor: eline.zoom_factor,
};
var line = GPolyline.fromEncoded( opts );

DESCRIPTION
This module encodes a list of lat/lon points representing a polyline
into a format for use with Google Maps. This format is described here:

<http://code.google.com/apis/maps/documentation/polylinealgorithm.html>

The module is a port of Mark McClure's "PolylineEncoder.js" with some
minor tweaks. The original can be found here:

<http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/>

CONSTRUCTOR & ACCESSORS
new( [%args] )
Create a new encoder. Arguments are optional and correspond to the
accessor with the same name: "num_levels", "zoom_factor",
"visible_threshold", "force_endpoints".

Note: there's nothing stopping you from setting these properties
each time you "encode" a polyline.

num_levels
How many different levels of magnification the polyline has.
Default: 18.

zoom_factor
The change in magnification between those levels (see "num_levels").
Default: 2.

visible_threshold
Indicates the length of a barely visible object at the highest zoom
level. Default: 0.00001.

force_endpoints
Indicates whether or not the endpoints should be visible at all zoom
levels. force_endpoints is. Probably should stay true regardless.
Default: 1=true.

escape_encoded_points
Indicates whether or not the encoded points should have escape
characters escaped, eg:

$points =~ s/\\/\\\\/g;

This is useful if you'll be evalling the resulting strings, or
copying them into a static document.

Warning: don't turn this on if you'll be passing the encoded points
straight on to your application, or you'll get unexpected results
(ie: lines that start out right, but end up horribly wrong). It may
even crash your browser.

Default: 0=false.

METHODS
encode( \@points );
Encode the points into a string for use with Google Maps
"GPolyline.fromEncoded" using a variant of the Douglas-Peucker
algorithm and the Polyline encoding algorithm defined by Google.

Expects a reference to a @points array ala:

[
{ lat => 38.5, lon => -120.2 },
{ lat => 40.7, lon => -120.95 },
{ lat => 43.252, lon => -126.453 },
];

Returns a hashref containing:

{
points => 'encoded points string',
levels => 'encoded levels string',
num_levels => int($num_levels),
zoom_factor => int($zoom_factor),
};

You can then use the JSON modules (or XML, or whatever) to pass the
encoded values to your Javascript application for use there.

TODO
Benchmarking, & maybe bring distance calcs in-line as Joel Rosenberg
did:
<http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/gmap_polyli
ne_encoder.rb.txt>

AUTHOR
Steve Purkis <[email protected]>

Ported from Mark McClure's "PolylineEncoder.js" which can be found here:
<http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/PolylineEnc
oder.html>

Some encoding ideas borrowed from Geo::Google.

COPYRIGHT
Copyright (c) 2008 Steve Purkis. Released under the same terms as Perl
itself.

SEE ALSO
<http://code.google.com/apis/maps/documentation/polylinealgorithm.html>,
<http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/PolylineEnc
oder.html> (JavaScript implementation),
<http://www.usnaviguide.com/google-encode.htm> (similar implementation
in perl), Geo::Google, JSON

Loading

0 comments on commit d4d7f54

Please sign in to comment.