#
# Point drawing functions
#

use warnings;
use strict;

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

   my($n,$m);

   # Check the data

   foreach $n (0..$#{$data})
     {
      warn_missing_information("Point","SYMBOL","SYMBOL",$data->[$n]);

      warn_missing_information("Point","LABEL","LABEL-COLOUR",$data->[$n]);
      warn_missing_information("Point","LABEL","LABEL-SIZE"  ,$data->[$n]);
      warn_missing_information("Point","LABEL","LABEL"       ,$data->[$n]);

      warn_missing_information("Point","LABEL2","LABEL2-COLOUR",$data->[$n]);
      warn_missing_information("Point","LABEL2","LABEL2-SIZE"  ,$data->[$n]);
      warn_missing_information("Point","LABEL2","LABEL2"       ,$data->[$n]);

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

         warn_overlapping_lines("Point","SYMBOL",$data->[$n],$data->[$m]);
         warn_overlapping_lines("Point","LABEL" ,$data->[$n],$data->[$m]);
         warn_overlapping_lines("Point","LABEL2",$data->[$n],$data->[$m]);
        }
     }

   # Create the layers, styles and rules

   my($zoom,$datum);

   foreach $zoom ($global->{MINZOOM}..$global->{MAXZOOM})
     {
      foreach $datum (@{$data})
        {
         # Create the symbolisers

         my(@symbolisers)=();

         if($zoom >= $datum->{'MIN-ZOOM-SYMBOL'} &&
            $zoom <= $datum->{'MAX-ZOOM-SYMBOL'} &&
            $datum->{'SYMBOL'} ne "")
           {
            push(@symbolisers,point_symboliser("",
                                               'base'=>'symbols',
                                               'file'=>$datum->{'SYMBOL'}));
           }

         if($zoom >= $datum->{'MIN-ZOOM-LABEL'} &&
            $zoom <= $datum->{'MAX-ZOOM-LABEL'} &&
            $datum->{'LABEL'} ne "")
           {
            push(@symbolisers,text_symboliser($datum->{'LABEL-STYLE'},
                                              $datum->{'LABEL'},
                                              'fill'=>$datum->{'LABEL-COLOUR'},
                                              'size'=>$datum->{'LABEL-SIZE'},
                                              'placement'=>'interior',
                                              'halo-radius'=>1,
                                              'wrap-width'=>20,
                                              'text-ratio'=>0.8,
                                              'fontset-name'=>'normal'));
           }

         if($zoom >= $datum->{'MIN-ZOOM-LABEL2'} &&
            $zoom <= $datum->{'MAX-ZOOM-LABEL2'} &&
            $datum->{'LABEL2'} ne "")
           {
            push(@symbolisers,text_symboliser($datum->{'LABEL2-STYLE'},
                                              $datum->{'LABEL2'},
                                              'fill'=>$datum->{'LABEL2-COLOUR'},
                                              'size'=>$datum->{'LABEL2-SIZE'},
                                              'placement'=>'interior',
                                              'halo-radius'=>1,
                                              'wrap-width'=>20,
                                              'text-ratio'=>0.8,
                                              'fontset-name'=>'normal'));
           }

         if($#symbolisers > -1)
           {
            # Create the layer (may re-use earlier one if names match)

            add_layer($global,
                      name=>"points--$datum->{LAYER}--z$zoom",
                      description=>"points $datum->{LAYER}",
                      zoom=>$zoom,
                      'datasource-base'=>'postgis',
                      'sql-table'=>'planet_osm_point');

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

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

            # Create the rules

            my($filter)="($datum->{FILTER})";

            if($datum->{'SUB-FILTER'} ne "")
              {
               $filter.=" and ($datum->{'SUB-FILTER'})";
              }

            add_rule($global,
                     zoom=>$zoom,
                     filter=>$filter,
                     symbolisers=>[@symbolisers]);


            if($datum->{POLYGON} eq "yes")
              {
               # Create the layer (may re-use earlier one if names match)

               add_layer($global,
                         name=>"points-polygon--$datum->{LAYER}--z$zoom",
                         description=>"points polygon $datum->{LAYER}",
                         zoom=>$zoom,
                         'datasource-base'=>'postgis',
                         'sql-table'=>'planet_osm_polygon');

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

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

               # Create the rule

               add_rule($global,
                        zoom=>$zoom,
                        filter=>$filter,
                        symbolisers=>[@symbolisers]);
              }
           }
        }
     }
  }

#
1;
