kml.pl: don't add duplicate places

pull/2/head
Daniel Asher Resnick 4 years ago
parent 8ef2546678
commit d652656be6
  1. 13
      kml.pl

@ -17,6 +17,7 @@ unless(defined($mode))
{ {
USAGE(); USAGE();
} }
if ($mode eq 'add') if ($mode eq 'add')
{ {
my ($name, $coordinates) = @ARGV; my ($name, $coordinates) = @ARGV;
@ -25,12 +26,19 @@ if ($mode eq 'add')
say "Not enough args for add operation"; say "Not enough args for add operation";
USAGE(1); USAGE(1);
} }
my $name_id = to_id($name);
my ($placemark) = $xpc->findnodes("//k:Placemark[\@id=\"$name_id\"]");
if(defined($placemark))
{
say "$name already exists in $filename";
exit(1);
}
append_placemark($name, $coordinates, uri_escape($name)); append_placemark($name, $coordinates, uri_escape($name));
print $dom->toString(1); print $dom->toString(1);
} }
elsif ($mode eq 'remove') elsif ($mode eq 'remove')
{ {
# say "Remove mode";
my ($name) = @ARGV; my ($name) = @ARGV;
unless (defined($name)) unless (defined($name))
{ {
@ -49,12 +57,13 @@ elsif ($mode eq 'remove')
say "$name was not found in $filename"; say "$name was not found in $filename";
exit(1); exit(1);
} }
# say $placemark->toString(1);
} }
elsif ($mode eq 'set') elsif ($mode eq 'set')
{ {
say "Set mode"; say "Set mode";
} }
else else
{ {
say "Invalid operation"; say "Invalid operation";

Loading…
Cancel
Save