adding labels on points after map->draw()

eric BELENFANT eric.belenfant at AC-ORLEANS-TOURS.FR
Thu Jan 6 08:26:25 PST 2005


Hi !!

I would like to write some lables on points i draw on a map after i calling
map->draw()

I use this piece of code :
 #########################################
 # INFOS DE CONNEXION A LA BASE
 #########################################

 $dsn = 'mysql://root@amethyse/dep';
 $options = array(
     'debug'       => 2,
     'portability' => DB_PORTABILITY_ALL,
 );
 $db =& DB::connect($dsn, $options);

 # récupération de la liste des communes

 $modele = & new carteModel($db);
 $modele->calculeCapaciteByCommunes($secteur,$diplome,$filiere,$formation);
 $Lcommunes=$map->getLayerByName("communeSelection");
 $LSymbolInd=$map->getLayerByName("Indicateurs");
 $LSymbolLab=$map->getLayerByName("Indicateurs Labels");

 $Lindex=$LSymbolInd->index;
 $classe=$LSymbolInd->getClass(0);
 $style = $classe->getStyle(0);

 #echo $style->size;
 $i=0;
 $Lcommunes->set("status", MS_ON);
 # détermination de l'échelle
 # SIZE=1 ====> minimum de capacité


 while ($item = $modele->getItem()) {
  #echo
$item["code_com"]."".$item["sigle"]."".$cartoSymbol[$item["sigle"]]."<br>";
  if ($i==0) $echelle = $item["capa"];
  $taille = (int) ($item["capa"]/$echelle) * 10;
  $style->set("size",$taille);
  #echo "taille ".$item["code_com"]." ".$taille."<br>";
  $style->set("offsetx",$taille);
  $style->set("offsety",$taille);

  # récupération du centre de la commune
  #echo $item["code_com"]." toto \n";
  if (!$item["code_com"]) continue;
  @$Lcommunes->queryByAttributes("CODE_INSEE",$item["code_com"],MS_SINGLE);
  if (!$Lcommunes->getNumResults()) continue;
  #echo $item["code_com"]." affiché";
  $resultat=$Lcommunes->getResult(0);
  $Lcommunes->open();
  $shape = $Lcommunes->getShape($resultat->tileindex,$resultat->shapeindex);
  #$shape = $Lcommunes->getShape(-1,$resultat->shapeindex);
     $ShpBounds = $shape->bounds;
     $shpMinx = $ShpBounds->minx;
     $shpMiny = $ShpBounds->miny;
     $shpMaxx = $ShpBounds->maxx;
     $shpMaxy = $ShpBounds->maxy;
  #print_r($ShpBounds);

  $centreX = ($shpMinx + $shpMaxx)/2;
  $centreY = ($shpMiny + $shpMaxy)/2;
  #print_r($map->extent);
  #echo $centreX." / ";
  #echo $centreY;
  #print_r($shape->bounds);
  # écriture des symboles des établissements sur les communes
  $point = ms_newPointObj();
  #$point->setXY($centreX ,$centreY);
  #$point->setXY($centreX + 12 * $i * ($shpMaxx-$shpMinx)/$map->width,$centreY);
  $point->setXY($centreX,$centreY);
  #echo $classe;
  $point->draw($map,$LSymbolInd,$mapImg,0,"");
  $point->draw($map,$LSymbolLab,$mapImg,0,"toto");
  $i++;
  $oldCom=$item["code_com"];
  $Lcommunes->close();
  $shape->free();
 }
assuming this .map
....
############################################################################################
# COUCHE DYNAMIQUE DES NOMS DE COMMUNES SELECTIONNES AVEC LES LISTES
############################################################################################

LAYER
  NAME "communeSelection"
  GROUP "communes"
  TYPE POLYGON
  STATUS OFF
  CONNECTIONTYPE OGR
  CONNECTION "data/communes_eric.TAB"
  LABELITEM "NOM_COM"
  CLASSITEM "CODE_INSEE"
  LABELMINSCALE 150000
  #FILTER "1=1"

  METADATA
    "DESCRIPTION"   "|||Communes"
    "RESULT_FIELDS" "NOM_COM,PSDC99,SUPERFICIE_KM2,CODE_INSEE"
    "RESULT_HEADERS" "|||Nom,Population,Superficie (km2),Indicateurs de
formation"
    "RESULT_HYPERLINK" "CODE_INSEE||Voir"
  END

  CLASS
 NAME "Commune analysée"
 OUTLINECOLOR 48 106 137
 COLOR 255 149 79
 TEMPLATE void
 #EXPRESSION /45234/
      LABEL
        COLOR 0 0 127
        #BACKGROUNDCOLOR 200 200 100
        POSITION AUTO
        TYPE bitmap
        SIZE tiny
 WRAP " "
 FORCE TRUE
      END
  END

END # LAYER

####################################################################
# THEME : affichage des indicateurs (capacité, effectifs ...)
####################################################################

LAYER
  NAME "Indicateurs"
  GROUP "analyse"
  STATUS ON
  TYPE POINT

  METADATA
    "DESCRIPTION"   "|||Analyse"
  END
  CLASS
 #NAME "Cercles"
 #TEMPLATE void
 COLOR 39 152 221
 SYMBOL 'circle'
 SIZE 3
      LABEL
        COLOR 0 0 127
        #BACKGROUNDCOLOR 200 200 100
        POSITION AUTO
        TYPE bitmap
        SIZE tiny
 WRAP " "
 FORCE TRUE
      END
  END
END #LAYER

LAYER
  NAME "Indicateurs Labels"
  GROUP "analyse"
  STATUS ON
  TYPE ANNOTATION

  METADATA
    "DESCRIPTION"   "|||Analyse"
  END
  CLASS
      LABEL
        COLOR 0 0 127
        #BACKGROUNDCOLOR 200 200 100
        POSITION AUTO
        TYPE bitmap
        SIZE tiny
  WRAP " "
  FORCE TRUE
   END
  END
END #LAYER
....


but nothing appear when i call the point->draw method ...

I must be wrong somewhere !!!???

eric



More information about the MapServer-users mailing list