reindentation and style

no code changes
master
Joey Hess 2012-03-03 12:05:04 -04:00
parent 9f56a417a1
commit 8125cfa45b
1 changed files with 563 additions and 547 deletions

View File

@ -12,7 +12,7 @@ sub import {
add_underlay("javascript");
hook(type => "getsetup", id => "osm", call => \&getsetup);
hook(type => "format", id => "osm", call => \&format);
hook(type => "preprocess", id => "osm", call => \&preprocess); # backward compatibility
hook(type => "preprocess", id => "osm", call => \&preprocess);
hook(type => "preprocess", id => "waypoint", call => \&process_waypoint);
hook(type => "savestate", id => "waypoint", call => \&savestate);
hook(type => "cgi", id => "osm", call => \&cgi);
@ -28,14 +28,14 @@ sub getsetup () {
osm_default_zoom => {
type => "integer",
example => "15",
description => "the default zoon when you click on the map link",
description => "the default zoom when you click on the map link",
safe => 1,
rebuild => 1,
},
osm_default_icon => {
type => "string",
example => "img/osm.png",
description => "the icon showed on links and on the main map",
description => "the icon shon on links and on the main map",
safe => 0,
rebuild => 1,
},
@ -62,8 +62,10 @@ sub getsetup () {
},
osm_tag_icons => {
type => "string",
example => { 'test' => '/img/test.png',
'trailer' => '/img/trailer.png' ,},
example => {
'test' => '/img/test.png',
'trailer' => '/img/trailer.png'
},
description => "tag to icon mapping, leading slash is important!",
safe => 0,
rebuild => 1,
@ -85,7 +87,8 @@ sub preprocess {
$height = '100%';
$width = '100%';
$float = 0;
} else {
}
else {
$height = scrub($params{'height'} || "300px", $page, $dest); # sanitized here
$width = scrub($params{'width'} || "500px", $page, $dest); # sanitized here
$float = (defined($params{'right'}) && 'right') || (defined($params{'left'}) && 'left'); # sanitized here
@ -94,7 +97,8 @@ sub preprocess {
my $map;
if ($fullscreen) {
$map = $params{'map'} || $page;
} else {
}
else {
$map = $params{'map'} || 'map';
}
$map = scrub($map, $page, $dest); # sanitized here
@ -107,17 +111,16 @@ sub preprocess {
if ($zoom !~ /^\d\d?$/ || $zoom < 2 || $zoom > 18) {
error("Bad zoom");
}
$pagestate{$page}{'osm'}{$map}{'displays'}{$name} =
{
'height' => $height,
'width' => $width,
'float' => $float,
'zoom' => $zoom,
'fullscreen' => $fullscreen,
'editable' => defined($params{'editable'}),
'lat' => $lat,
'lon' => $lon,
'href' => $href,
$pagestate{$page}{'osm'}{$map}{'displays'}{$name} = {
height => $height,
width => $width,
float => $float,
zoom => $zoom,
fullscreen => $fullscreen,
editable => defined($params{'editable'}),
lat => $lat,
lon => $lon,
href => $href,
};
return "<div id=\"mapdiv-$name\"></div>";
}
@ -152,7 +155,8 @@ sub process_waypoint {
error("invalid tag specified, see osm_tag_icons configuration or don't specify any");
}
$icon = $config{'osm_tag_icons'}->{$tag};
} else {
}
else {
foreach my $t (keys %{$typedlinks{$page}{'tag'}}) {
if ($icon = get_tag_icon($t)) {
$tag = $t;
@ -181,21 +185,22 @@ sub process_waypoint {
if ($formats{'KML'}) {
will_render($page,$config{destdir} . "/$map/pois.kml");
}
}
my $href = "/ikiwiki.cgi?do=osm&map=$map&lat=$lat&lon=$lon&zoom=$zoom";
if (defined($destsources{htmlpage($map)})) {
$href = urlto($map,$page) . "?lat=$lat&lon=$lon&zoom=$zoom";
}
$pagestate{$page}{'osm'}{$map}{'waypoints'}{$name} =
{
'page' => $page,
'desc' => $desc,
'icon' => $icon,
'tag' => $tag,
'lat' => $lat,
'lon' => $lon,
'href' => urlto($page,$map), # how to link back to the page from the map, not to be confused with the URL of the map itself sent to the embeded map below
$pagestate{$page}{'osm'}{$map}{'waypoints'}{$name} = {
page => $page,
desc => $desc,
icon => $icon,
tag => $tag,
lat => $lat,
lon => $lon,
# how to link back to the page from the map, not to be
# confused with the URL of the map itself sent to the
# embeded map below
href => urlto($page,$map),
};
my $output = '';
if (defined($params{'embed'})) {
@ -220,7 +225,8 @@ sub get_tag_icon($) {
# look for the old way: mappings
if ($config{'osm_tag_icons'}->{$tag}) {
return $config{'osm_tag_icons'}->{$tag};
} else {
}
else {
return undef;
}
}
@ -231,7 +237,8 @@ sub scrub_lonlat($$$) {
if ($loc =~ /^\s*(\-?\d+(?:\.\d*°?|(?:°?|\s)\s*\d+(?:\.\d*\'?|(?:\'|\s)\s*\d+(?:\.\d*)?\"?|\'?)°?)[NS]?)\s*\,?\;?\s*(\-?\d+(?:\.\d*°?|(?:°?|\s)\s*\d+(?:\.\d*\'?|(?:\'|\s)\s*\d+(?:\.\d*)?\"?|\'?)°?)[EW]?)\s*$/) {
$lat = $1;
$lon = $2;
} else {
}
else {
error("Bad loc");
}
}
@ -241,7 +248,8 @@ sub scrub_lonlat($$$) {
if (($1 eq '-') || (($7//'') eq 'S')) {
$lat = - $lat;
}
} else {
}
else {
error("Bad lat");
}
}
@ -251,7 +259,8 @@ sub scrub_lonlat($$$) {
if (($1 eq '-') || (($7//'') eq 'W')) {
$lon = - $lon;
}
} else {
}
else {
error("Bad lon");
}
}
@ -264,6 +273,7 @@ sub scrub_lonlat($$$) {
sub savestate {
my %waypoints = ();
my %linestrings = ();
foreach my $page (keys %pagestate) {
if (exists $pagestate{$page}{'osm'}) {
foreach my $map (keys %{$pagestate{$page}{'osm'}}) {
@ -274,6 +284,7 @@ sub savestate {
}
}
}
foreach my $page (keys %pagestate) {
if (exists $pagestate{$page}{'osm'}) {
foreach my $map (keys %{$pagestate{$page}{'osm'}}) {
@ -282,8 +293,10 @@ sub savestate {
if (exists $links{$page}) {
foreach my $otherpage (@{$links{$page}}) {
if (exists $waypoints{$map}{$otherpage}) {
push(@{$linestrings{$map}}, [ [ $waypoints{$map}{$name}{'lon'}, $waypoints{$map}{$name}{'lat'} ],
[ $waypoints{$map}{$otherpage}{'lon'}, $waypoints{$map}{$otherpage}{'lat'} ] ]);
push(@{$linestrings{$map}}, [
[ $waypoints{$map}{$name}{'lon'}, $waypoints{$map}{$name}{'lat'} ],
[ $waypoints{$map}{$otherpage}{'lon'}, $waypoints{$map}{$otherpage}{'lat'} ]
]);
}
}
}
@ -294,6 +307,7 @@ sub savestate {
$pagestate{$page}{'osm'} = ();
}
}
if (!defined($config{'osm_format'}) || !$config{'osm_format'}) {
$config{'osm_format'} = 'KML';
}
@ -320,12 +334,12 @@ sub writejson($;$) {
my %marker = ( "type" => "Feature",
"geometry" => { "type" => "Point", "coordinates" => [ $waypoints{$map}{$name}{'lon'}, $waypoints{$map}{$name}{'lat'} ] },
"properties" => $waypoints{$map}{$name} );
push(@{$geojson{'features'}}, \%marker);
push @{$geojson{'features'}}, \%marker;
}
foreach my $linestring (@{$linestrings{$map}}) {
my %json = ( "type" => "Feature",
"geometry" => { "type" => "LineString", "coordinates" => $linestring });
push(@{$geojson{'features'}}, \%json);
push @{$geojson{'features'}}, \%json;
}
debug('writing pois file pois.json in ' . $config{destdir} . "/$map");
writefile("pois.json",$config{destdir} . "/$map",to_json(\%geojson));
@ -381,7 +395,6 @@ Sample style:
$writer->xmlDecl();
$writer->startTag("kml", "xmlns" => "http://www.opengis.net/kml/2.2");
# first pass: get the icons
foreach my $name (keys %{$waypoints{$map}}) {
my %options = %{$waypoints{$map}{$name}};
@ -406,7 +419,9 @@ Sample style:
$writer->characters('#' . $options{tag});
$writer->endTag();
#$writer->emptyTag('atom:link', href => $options{href});
$writer->startTag('href'); # to make it easier for us as the atom:link parameter is hard to access from javascript
# to make it easier for us as the atom:link parameter is
# hard to access from javascript
$writer->startTag('href');
$writer->characters($options{href});
$writer->endTag();
$writer->startTag("description");
@ -514,7 +529,8 @@ sub include_javascript ($) {
}
if ($loader) {
return embed_map_code() . "<script type=\"text/javascript\" charset=\"utf-8\">$loader</script>";
} else {
}
else {
return '';
}
}
@ -569,7 +585,8 @@ function mapsetup(divname, options) {
div.style.position = 'absolute';
div.style.width = '100%';
div.style.height = '100%';
} else {
}
else {
div.style.height = options.height;
div.style.width = options.width;
div.style.float = options.float;
@ -665,8 +682,7 @@ function mapsetup(divname, options) {
var lat = options.lat;
var lon = options.lon;
var zoom= options.zoom || 10;
center = new OpenLayers.LonLat( lon, lat )
.transform(
center = new OpenLayers.LonLat( lon, lat ).transform(
new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);