[Mapserver-users] Dynamic Features

Eduardo Spremolla edspremolla at antel.com.uy
Fri Jun 11 05:53:14 PDT 2004


Jonathan:
	this is what I do in www.trackbysat.com. Is a heavy hacked version of
map_quakes from the perl wiki. I don't use Postgis when I build this
site, now I do ;-)

First collect the points. I plot actual position plus a line with the
last 10 reports, so after the query:

      $result = $conn-> exec($sql);
       while(@row = $result->fetchrow)
         {
          next if ($row[1]==91);

           $reporte[$i]{ lat} =$row[1];
           $reporte[$i]{ lon} =$row[2];
           $reporte[$i]{ hora} = $row[0];
           $reporte[$i]{ io} = $row[3];
           $reporte[$i]{ vel} = $row[4];
         if ( $i == 0){
           $primero{ lat} =$row[1];
           $primero{ lon} =$row[2];
           $primero{ hora} = $row[0];
           $primero{ io} = $row[3];
           $primero{ vel} = $row[4];
           }
           $i++;
         }
       $ret = $conn->requestCancel;


Then I plot some base maps:

  die $mapscript::ms_error->{message} unless $map = new
	mapscript::mapObj($my_map);

  &set_extent();

  my $img = $map->prepareImage();

# draw basemap
  my $layer = $map->getLayerByName('fondo');
  $layer->draw($map, $img);
  $layer = $map->getLayerByName('plazas');
  $layer->draw($map, $img);
  $layer = $map->getLayerByName('ejes');
  $layer->draw($map, $img);
  $layer = $map->getLayerByName('calles');
  $layer->draw($map, $img);
  $layer = $map->getLayerByName('avda');
  $layer->draw($map, $img);
  $layer = $map->getLayerByName('vial');
  $layer->draw($map, $img);

#set the dinamic layers

  my $layer_t = $map->getLayerByName('timestamp');
  $layer_t-> { status} = 1;
# turn the layer on
  my $layer_p = $map->getLayerByName('movil');
  $layer_p-> { status} = 1;
# turn the layer on


Then create the points and lines:

  $layer = $map->getLayerByName('reporte');

  my $point = new mapscript::pointObj();
  my $line = new mapscript::lineObj();
  my $i = 1;


 foreach my $q(@reporte)
  {
    $point-> { x} = $q-> { lon};
    $point-> { y} = $q-> { lat};
    $line->add($point);
        }

  my $shape = new mapscript::shapeObj($mapscript::MS_SHAPE_LINE);
  $shape->add($line);
  $shape->draw($map, $layer, $img);

  foreach my $q(@reporte)
  {

    $point-> { x} = $q-> { lon};
    $point-> { y} = $q-> { lat};
    $etiqueta="$q->{hora}\|${spee}km/h";
    if ( $q->{vel}> $maxspeed )
            { $cl = 2; }
          else
            { $cl = 1; }
    $point->draw($map, $layer_t, $img, $cl, $etiqueta);
    $i++;
  }

And final draw everything :

 $map->drawLabelCache($img);
  $img->saveImage($image_path.$image_id, $map-> { imagetype} , $map-> {
transparent} , $map-> { interlace} , $map-> { imagequality});
  $img=$map->drawScalebar();
  $img->saveImage($image_path.$scalebar_id, $map-> { imagetype} , $map->
{ transparent} , $map-> { interlace} , $map-> { imagequality});


Hope this will help

LALO

-- 
Eduardo Spremolla <edspremolla at antel.com.uy>
Antel I+D




More information about the MapServer-users mailing list