mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-02 01:08:14 +00:00
78 lines
2.0 KiB
Plaintext
78 lines
2.0 KiB
Plaintext
|
#!/usr/bin/perl
|
||
|
|
||
|
use strict;
|
||
|
|
||
|
open(GEOJSON, ">feature-filter/in.json");
|
||
|
open(FILTER, ">feature-filter/filter");
|
||
|
|
||
|
sub calchash {
|
||
|
my $h = 0;
|
||
|
my $s = $_[0];
|
||
|
while ($s =~ s/^(.)//) {
|
||
|
$h = ($h * 37 + ord($1)) & ((1 << 32) - 1);
|
||
|
}
|
||
|
return $h;
|
||
|
}
|
||
|
|
||
|
my $filter = "";
|
||
|
my $hash = 0;
|
||
|
|
||
|
print FILTER "{\n";
|
||
|
my $first = 1;
|
||
|
|
||
|
open(IN, "../../mapbox-gl-js/test/unit/style-spec/feature_filter.test.js");
|
||
|
while (<IN>) {
|
||
|
if (/const f[0-9]* = filter\((.*)\);/) {
|
||
|
$filter = $1;
|
||
|
$filter =~ s/'/"/g;
|
||
|
$hash = "layer" . calchash($filter);
|
||
|
|
||
|
unless ($filter =~ /apply/) {
|
||
|
if ($first) {
|
||
|
$first = 0;
|
||
|
} else {
|
||
|
print FILTER ",\n";
|
||
|
}
|
||
|
|
||
|
print FILTER "\"$hash\": $filter,\n";
|
||
|
print FILTER "\"not$hash\": [ \"none\", $filter ]\n";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (/t.equal\(f[0-9]*\({(.*)}\), ([a-z]+)\);/) {
|
||
|
unless ($filter =~ /apply/) {
|
||
|
my $prop = $1;
|
||
|
my $matched = $2;
|
||
|
|
||
|
if ($prop =~ /properties/) {
|
||
|
next if $prop =~ /undefined/;
|
||
|
|
||
|
$prop =~ s/properties/"properties"/g;
|
||
|
$prop =~ s/foo/"foo"/g;
|
||
|
$prop =~ s/id/"id"/g;
|
||
|
$prop =~ s/undefined/null/g;
|
||
|
$prop =~ s/'/"/g;
|
||
|
|
||
|
my $qprop = "$prop, $filter";
|
||
|
$qprop =~ s/"/\\"/g;
|
||
|
|
||
|
if ($matched eq "true") {
|
||
|
$prop =~ s/}/, \"rule\": \"$qprop\"}/;
|
||
|
$prop =~ s/^"properties": {,/"properties": {/;
|
||
|
|
||
|
print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
|
||
|
print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
|
||
|
} else {
|
||
|
$prop =~ s/}/, \"rule\": \"not $qprop\"}/;
|
||
|
$prop =~ s/^"properties": {,/"properties": {/;
|
||
|
|
||
|
print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"not$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 0, 0 ] } }\n";
|
||
|
print GEOJSON "{ \"type\": \"Feature\", \"tippecanoe\": { \"layer\": \"$hash\" }, $prop, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -100, 0 ] } }\n";
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
print FILTER "}\n";
|