[Mapserver-users] How to Draw Annotation Layer Last

Dan Barron dbarron at ddive.com
Thu Jan 23 21:51:29 PST 2003


--=====================_25681046==.ALT
Content-Type: text/plain; charset="iso-8859-1"; format=flowed
Content-Transfer-Encoding: quoted-printable

For future reference for anyone who may have a similar problem, here is the=
=20
path I took to resolve the problem in drawing the annotation layer last.

I finally took a step back on this problem and simplified my map file and=20
my php/mapscript code and was successful in getting the layer to appear on=
=20
top of all other layers.  I also upgraded to MapServer 3.6.4, php/mapscript=
=20
3.6, and PHP 4.3.0 so as the have the current stable versions to work with.

With the help of the folks on the list - here's a couple observations that=
=20
seemed worth sharing.  If these are well known to everyone, then my=20
apologies up front.

- The position of the annotation layer object in the map file had no=20
effect.  Once working properly, the annotation layer FEATURE TEXT was drawn=
=20
last and therefore visible on top of all other layers in all cases whether=
=20
the annotation layer object was first or last in the map file.

- In php/mapscript, the method $map->drawLabelCache($image) was needed only=
=20
when the annotation layer object STATUS was set to OFF in the map file and=
=20
you dynamically retrieved the layer object in php/mapscript and set the=20
layer object STATUS ON then called $layer->draw($image).  Otherwise, if the=
=20
STATUS was set to ON or DEFAULT, the FEATURE TEXT would appear successfully.

I've included the simplified map file and php/mapscript code used to get my=
=20
bearings on this.

Dan

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~
# mapnavigatorTEST.map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~

name mapnavigatorTEST
size 720 360
status ON
extent -120.0 0.0 -10.0 70.0
units DD
shapepath "data"
imagetype PNG
transparent off
fontset "./fonts/font.list"
symbolset "./symbols/symbols.list"

PROJECTION
  "proj=3Dlatlong"
  "ellps=3DGRS80"
END

WEB
   imagepath "c:/bin/jboss-2.4.0_tomcat-3.2.3/tomcat/webapps/tmp/"
   imageurl "/tmp/"
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Start of scalebar
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SCALEBAR
   label
     color 50 50 150
     size tiny
   end
   style 0
   size 200 4
   color 50 50 150
   outlinecolor 0 0 0
   units miles
   intervals 3
   transparent false
   status off
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# REFERENCE map
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
REFERENCE
   image ""
   size 100 100
   extent -190 -95 190 95
   color -1 -1 -1
   outlinecolor 255 50 50
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# LAYER definitions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Credits
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LAYER
  NAME credits
  STATUS off
  TRANSFORM false
  TYPE annotation
  FEATURE
    points 1 10 end
    text '=A9 www.destinationdive.com'
  END
  CLASS
    NAME credits
    LABEL
      type truetype
      font verdana
      size 8
      antialias true
      color 51 51 51
      position UR
      backgroundcolor 255 255 255
      buffer 2
    END
  END
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# main base map layer
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LAYER
     name Country
     type POLYGON
     status on
     data 'country'
     minscale 26000010
     class
       name Country
          outlinecolor 204 204 204
       color 255 255 204
     end
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# NORTH AMERICA
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LAYER
   NAME canada
   TYPE POLYGON
   STATUS ON
   GROUP 'north_america'
   DATA 'north_america/canada/ponet_poly_poly'
   MAXSCALE 26000000
   class
     name canada
     outlinecolor 204 204 204
     color 255 255 204
   END
END

LAYER
   NAME mexico
   TYPE POLYGON
   STATUS ON
   GROUP 'north_america'
   DATA 'north_america/mexico/ponet_poly_poly'
   MAXSCALE 26000000
   CLASS
     name mexico
     outlinecolor 204 204 204
     color 255 255 204
   END
END

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# USA
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

LAYER
   NAME states
   TYPE POLYGON
   STATUS ON
   DATA 'north_america/usa/statesp020'
   MAXSCALE 26000000
   GROUP 'north_america'
   CLASS
     name states
     outlinecolor 204 204 204
     color 255 255 204
   END
END

END

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~
// simple-map-test.php
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~

<?php

$mapPath=3D"c:/bin/jboss-2.4.0_tomcat-3.2.3/tomcat/webapps/mapserver3.5/";
$mapFile=3D"mapNavigator-test.map";

$map =3D ms_newMapObj($mapPath.$mapFile);
$image=3D$map->draw();

$credits =3D $map->getLayerByName("credits");
$credits->set("status", MS_ON );
$credits->draw( $image );

$map->drawLabelCache($image);
$image_url_PNG=3D$image->saveWebImage(MS_PNG,1,1,0);

$image->free();

?>

<img src=3D"<?php echo $image_url_PNG?>" border=3D"1"=
 style=3D"background-color:=20
#99ccff;" alt=3D"">


--=====================_25681046==.ALT
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<html>
<body>
<tt>For future reference for anyone who may have a similar problem, here
is the path I took to resolve the problem in drawing the annotation layer
last.<br><br>
I finally took a step back on this problem and simplified my map file and
my php/mapscript code and was successful in getting the layer to appear
on top of all other layers.  I also upgraded to MapServer 3.6.4,
php/mapscript 3.6, and PHP 4.3.0 so as the have the current stable
versions to work with.<br><br>
With the help of the folks on the list - here's a couple observations
that seemed worth sharing.  If these are well known to everyone,
then my apologies up front.<br><br>
- The position of the annotation layer object in the map file had no
effect.  Once working properly, the annotation layer FEATURE TEXT
was drawn last and therefore visible on top of all other layers in all
cases whether the annotation layer object was first or last in the map
file.<br><br>
- In php/mapscript, the method $map->drawLabelCache($image) was needed
only when the annotation layer object STATUS was set to OFF in the map
file and you dynamically retrieved the layer object in php/mapscript and
set the layer object STATUS ON then called $layer->draw($image). 
Otherwise, if the STATUS was set to ON or DEFAULT, the FEATURE TEXT would
appear successfully.<br><br>
I've included the simplified map file and php/mapscript code used to get
my bearings on this.<br><br>
Dan<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~<br>
# mapnavigatorTEST.map<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~~~~~~<br><br>
name mapnavigatorTEST<br>
size 720 360<br>
status ON<br>
extent -120.0 0.0 -10.0 70.0<br>
units DD<br>
shapepath "data"<br>
imagetype PNG<br>
transparent off<br>
fontset "./fonts/font.list"<br>
symbolset "./symbols/symbols.list"<br><br>
PROJECTION<br>
 "proj=3Dlatlong"<br>
 "ellps=3DGRS80"<br>
END<br><br>
WEB<br>
  imagepath
"c:/bin/jboss-2.4.0_tomcat-3.2.3/tomcat/webapps/tmp/"<br>
  imageurl "/tmp/"<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# Start of scalebar<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
SCALEBAR<br>
  label<br>
    color 50 50 150<br>
    size tiny<br>
  end<br>
  style 0<br>
  size 200 4<br>
  color 50 50 150<br>
  outlinecolor 0 0 0<br>
  units miles<br>
  intervals 3<br>
  transparent false<br>
  status off<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# REFERENCE map<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
REFERENCE<br>
  image ""<br>
  size 100 100<br>
  extent -190 -95 190 95<br>
  color -1 -1 -1 <br>
  outlinecolor 255 50 50<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# LAYER definitions<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# Credits<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>
LAYER<br>
 NAME credits<br>
 STATUS off<br>
 TRANSFORM false<br>
 TYPE annotation<br>
 FEATURE<br>
   points 1 10 end  <br>
   text '=A9
<a href=3D"http://www.destinationdive.com/" eudora=3D"autourl">www.destinati=
ondive.com</a>' 
<br>
 END<br>
 CLASS<br>
   NAME credits<br>
   LABEL<br>
     type truetype<br>
     font verdana<br>
     size 8<br>
     antialias true<br>
     color 51 51 51 <br>
     position UR <br>
     backgroundcolor 255 255 255<br>
     buffer 2<br>
   END<br>
 END<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# main base map layer <br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>
LAYER<br>
    name Country<br>
    type POLYGON<br>
    status on<br>
    data 'country'<br>
    minscale 26000010<br>
    class<br>
      name Country<br>
<x-tab>        </x-tab>
outlinecolor 204 204 204<br>
      color 255 255 204<br>
    end<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# NORTH AMERICA<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>
LAYER<br>
  NAME canada<br>
  TYPE POLYGON<br>
  STATUS ON<br>
  GROUP 'north_america'<br>
  DATA 'north_america/canada/ponet_poly_poly'<br>
  MAXSCALE 26000000<br>
  class<br>
    name canada<br>
    outlinecolor 204 204 204<br>
    color 255 255 204<br>
  END<br>
END<br><br>
LAYER<br>
  NAME mexico<br>
  TYPE POLYGON<br>
  STATUS ON<br>
  GROUP 'north_america'<br>
  DATA 'north_america/mexico/ponet_poly_poly'<br>
  MAXSCALE 26000000<br>
  CLASS<br>
    name mexico<br>
    outlinecolor 204 204 204<br>
    color 255 255 204<br>
  END<br>
END<br><br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
# USA<br>
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><br>
LAYER<br>
  NAME states<br>
  TYPE POLYGON<br>
  STATUS ON<br>
  DATA 'north_america/usa/statesp020'<br>
  MAXSCALE 26000000<br>
  GROUP 'north_america'<br>
  CLASS<br>
    name states<br>
    outlinecolor 204 204 204<br>
    color 255 255 204<br>
  END<br>
END<br><br>
END<br><br>
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~<br>
// simple-map-test.php<br>
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~=
~~~~~<br><br>
<?php <br><br>
$mapPath=3D"c:/bin/jboss-2.4.0_tomcat-3.2.3/tomcat/webapps/mapserver3.5=
/";<br>
$mapFile=3D"mapNavigator-test.map";<br><br>
$map =3D ms_newMapObj($mapPath.$mapFile);<br>
$image=3D$map->draw();<br><br>
$credits =3D $map->getLayerByName("credits");<br>
$credits->set("status", MS_ON );<br>
$credits->draw( $image );<br><br>
$map->drawLabelCache($image);<br>
$image_url_PNG=3D$image->saveWebImage(MS_PNG,1,1,0);<br><br>
$image->free();<br><br>
?><br><br>
<img src=3D"<?php echo $image_url_PNG?>"=
 border=3D"1" style=3D"background-color: #99ccff;"=
 alt=3D""><br><br>
</body>
</html>

--=====================_25681046==.ALT--




More information about the MapServer-users mailing list