return $Y;
}
+# print that drops whitespace when not in verbose mode.
+sub printwows($) {
+ my $res = $_[0];
+ if ($verblev > 0) {
+ print($res); return;
+ }
+ $res =~ s/^\s+//g;
+ $res =~ s/"\s*:\s*/":/g;
+ $res =~ s/[\r\n]//g;
+ print($res);
+}
+
# ----------------------------------------------------------------------------
# main()
# ----------------------------------------------------------------------------
if (defined($ENV{'REQUEST_URI'})) {
$iscgi = 1;
- print("Content-type: application/json\n\n");
+ print("Content-type: application/json\n");
+ print("Access-Control-Allow-Origin: *\n");
+ print("Cache-Control: public, max-age=3600\n");
+ print("\n");
unless ($ENV{'REQUEST_URI'} =~ m!(\d+)/(\d+)/(\d+)\.json$!) {
print("{\n\"_comment\": \"Sorry, query parameters not understood.\"\n}\n");
exit(0);
my $cntr = 0;
if ($iscgi == 0) {
print("// Note: this file has been autogenerated by $0\n");
- print("var FAUGeoJSON = {\n");
+ printwows("var FAUGeoJSON = {\n");
} else {
- print("{\n");
+ printwows("{\n");
}
-print(" \"type\": \"FeatureCollection\",\n");
-print(" \"features\": [\n");
+printwows(" \"type\": \"FeatureCollection\",\n");
+printwows(" \"features\": [\n");
foreach $xtable ('planet_osm_polygon1', 'planet_osm_polygon2', 'planet_osm_line') { # 'planet_osm_polygon', 'planet_osm_line'
my $querypart1 = " ((tags->'building:part') is not null)";
my $table = 'planet_osm_polygon';
'roof:color', 'roof:colour', 'building:roof:color', 'building:roof:colour');
my $roofshape = fetchlastofhr(undef, $hstoredec, 'roof:shape', 'building:roof:shape');
my $roofheight = fetchlastofhr(undef, $hstoredec, 'roof:height', 'building:roof:height');
+ my $roofmaterial = fetchlastofhr(undef, $hstoredec, 'roof:material', 'building:roof:material');
if ($cntr != 0) {
- print(",\n");
+ printwows(",\n");
}
$cntr++;
- print(" {\n");
- print(" \"type\": \"Feature\",\n");
+ printwows(" {\n");
+ printwows(" \"type\": \"Feature\",\n");
if (defined($row->{'osm_id'})) {
- print(" \"id\": " . $row->{'osm_id'} . ",\n");
+ printwows(" \"id\": " . $row->{'osm_id'} . ",\n");
} else {
- print(" \"id\": $cntr,\n");
+ printwows(" \"id\": $cntr,\n");
}
if (defined($row->{'name'})) {
$row->{'name'} =~ s/"//g;
- print(" \"name\": \"" . $row->{'name'} . "\",\n");
+ printwows(" \"name\": \"" . $row->{'name'} . "\",\n");
}
- print(" \"geometry\": {\n");
- print(" \"type\": \"Polygon\",\n");
- print(" \"coordinates\": [[\n");
+ printwows(" \"geometry\": {\n");
+ printwows(" \"type\": \"Polygon\",\n");
+ printwows(" \"coordinates\": [[\n");
unless ($sth2->execute($row->{'way'})) {
print(STDERR "Sorry, decoding the way data exploded.\n");
exit(1);
if ($firstcoord == 1) {
$firstcoord = 0;
} else {
- print(",\n");
+ printwows(",\n");
}
- printf(" [ %.5f, %.5f ]", $onex, $oney);
+ printwows(sprintf(" [ %.5f, %.5f ]", $onex, $oney));
}
- print("\n");
- print(" ]]\n");
- print(" },\n");
- print(" \"properties\": {\n");
+ printwows("\n");
+ printwows(" ]]\n");
+ printwows(" },\n");
+ printwows(" \"properties\": {\n");
if (defined($height)) {
- print(" \"height\": $height,\n");
+ printwows(" \"height\": $height,\n");
}
- if (defined($min_height)) {
- print(" \"min_height\": $minheight,\n");
+ if (defined($minheight)) {
+ printwows(" \"minHeight\": $minheight,\n");
}
if (defined($levels)) {
- print(" \"levels\": $levels,\n");
+ printwows(" \"levels\": $levels,\n");
}
if (defined($minlevel)) {
- print(" \"minLevel\": $minlevel,\n");
+ printwows(" \"minLevel\": $minlevel,\n");
}
if (defined($wallcolor)) {
- print(" \"wallColor\": \"$wallcolor\",\n");
+ printwows(" \"wallColor\": \"$wallcolor\",\n");
}
if (defined($roofcolor)) {
$roofcolor =~ s/"//g;
- print(" \"roofColor\": \"$roofcolor\",\n");
+ printwows(" \"roofColor\": \"$roofcolor\",\n");
}
if (defined($roofshape)) {
$roofshape =~ s/"//g;
- print(" \"roofShape\": \"$roofshape\",\n");
+ if ($roofshape eq 'pyramidal') { $roofshape = 'pyramid'; }
+ printwows(" \"roofShape\": \"$roofshape\",\n");
+ }
+ if (defined($roofmaterial)) {
+ $roofshape =~ s/"//g;
+ printwows(" \"roofMaterial\": \"$roofmaterial\",\n");
}
if (defined($roofheight)) {
$roofheight = sprintf("%.1f", $roofheight);
- print(" \"roofHeight\": \"$roofheight\",\n");
+ printwows(" \"roofHeight\": \"$roofheight\",\n");
}
- print(" \"dummy\": \"void\"\n");
- print(" }\n");
- print(" }");
+ # this line is completely useless, but we need it to guarantee JSON has
+ # no trailing comma. osmbuildings will accept JSON with trailing commas
+ # just fine when you give it static, but NOT when requesting it dynamically.
+ printwows(" \"K9\": \"\"\n");
+ printwows(" }\n");
+ printwows(" }");
}
$sth2->finish();
undef($sth2);
$sth->finish();
undef($sth);
}
-print("\n ]\n");
+printwows("\n ]\n");
if ($iscgi == 0) {
print("};\n");
} else {