#
# Shapefile drawing functions
#

use warnings;
use strict;

sub CreateShapefileRules
  {
   my($global,$data)=(@_);

   my($n,$m);

   # Check the data

   foreach $n (0..$#{$data})
     {
      foreach $m ($n+1..$#{$data})
        {
         next if($data->[$n]{LAYER} ne $data->[$m]{LAYER});
         next if($data->[$n]{STYLE} ne $data->[$m]{STYLE});

         warn_overlapping_lines("Shapefile","",$data->[$n],$data->[$m]);
        }
     }

   # Create the layers, styles and rules

   my($zoom,$datum);

   foreach $zoom ($global->{MINZOOM}..$global->{MAXZOOM})
     {
      foreach $datum (@{$data})
        {
         next if($zoom < $datum->{'MIN-ZOOM'} ||
                 $zoom > $datum->{'MAX-ZOOM'});

         # Create the layer (may re-use earlier one if names match)

         add_layer($global,
                   name=>"shapefiles--$datum->{STYLE}--z$zoom",
                   description=>"shapefiles $datum->{STYLE}",
                   zoom=>$zoom,
                   srs=>$datum->{SRS},
                   'datasource-base'=>'shape',
                   datasource=>{file=>$datum->{FILE}});

         # Create the style (may re-use previous one if names match)

         add_style($global,
                   name=>"shapefiles--$datum->{STYLE}--z$zoom",
                   zoom=>$zoom);

         # Create the rules (simple with only one symboliser each)

         if($datum->{'POLYGON-STYLE'} ne "")
           {
            add_rule($global,
                     zoom=>$zoom,
                     filter=>$datum->{FILTER},
                     symbolisers=>[polygon_symboliser($datum->{'POLYGON-STYLE'})]);
           }

         if($datum->{'LINE-STYLE'} ne "")
           {
            add_rule($global,
                     zoom=>$zoom,
                     filter=>$datum->{FILTER},
                     symbolisers=>[line_symboliser($datum->{'LINE-STYLE'})]);
           }

         if($datum->{'LABEL-STYLE'} ne "")
           {
            add_rule($global,
                     zoom=>$zoom,
                     filter=>$datum->{FILTER},
                     symbolisers=>[text_symboliser($datum->{'LABEL-STYLE'},
                                                   $datum->{'LABEL'},
                                                   'halo-radius'=>1,
                                                   'wrap-width'=>20,
                                                   'text-ratio'=>0.8,
                                                   'fontset-name'=>'normal')]);
           }
        }
     }
  }

#

1;
