]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
osm: optimization: do not create duplicate styles
authorAntoine Beaupré <anarcat@koumbit.org>
Thu, 9 Aug 2012 06:03:02 +0000 (02:03 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 25 Aug 2012 14:45:16 +0000 (10:45 -0400)
(cherry picked from commit 9d550817ca546d1dd30a21cebad6093d1f3bacad)

IkiWiki/Plugin/osm.pm

index f570f4032e00150ad7d57235f366925e8e47758e..466006cbfb9463abd0bc7df481bbec064904d895 100644 (file)
@@ -365,17 +365,23 @@ sub writekml($;$) {
                $writer->startTag("Document");
 
                # first pass: get the icons
+               my %tags_map = (); # keep track of tags seen
                foreach my $name (keys %{$waypoints{$map}}) {
                        my %options = %{$waypoints{$map}{$name}};
-                       $writer->startTag("Style", id => $options{tag});
-                       $writer->startTag("IconStyle");
-                       $writer->startTag("Icon");
-                       $writer->startTag("href");
-                       $writer->characters($options{icon});
-                       $writer->endTag();
-                       $writer->endTag();
-                       $writer->endTag();
-                       $writer->endTag();
+                       if (!$tags_map{$options{tag}}) {
+                           debug("found new style " . $options{tag});
+                           $tags_map{$options{tag}} = ();
+                           $writer->startTag("Style", id => $options{tag});
+                           $writer->startTag("IconStyle");
+                           $writer->startTag("Icon");
+                           $writer->startTag("href");
+                           $writer->characters($options{icon});
+                           $writer->endTag();
+                           $writer->endTag();
+                           $writer->endTag();
+                           $writer->endTag();
+                       }
+                       $tags_map{$options{tag}}{$name} = \%options;
                }
        
                foreach my $name (keys %{$waypoints{$map}}) {