File: test_layer_mask.phtml

package info (click to toggle)
mapserver 5.6.5-2%2Bsqueeze3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,900 kB
  • ctags: 25,593
  • sloc: ansic: 201,813; cpp: 49,629; cs: 11,792; python: 5,233; perl: 3,249; sh: 1,199; makefile: 884; lex: 592; java: 466; xml: 373; yacc: 334; tcl: 158; ruby: 53
file content (113 lines) | stat: -rw-r--r-- 2,991 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<HTML>

<BODY BGCOLOR="#888888">

<CENTER>

<H1>PHP/MapScript layer mask test</H1>
<P>
 
<?php
//
// This example shows how to create an opaque mask layer using shapes coming
// from a map layer, and using the imageObj's pasteImage() method.
//
// This example uses the GMap demo's mapfile and data.
//

//
// Load MapScript module.
//
if (PHP_OS == "WINNT" || PHP_OS == "WIN32")
{
  dl("php_mapscript.dll");
}
else
{
  dl("php_mapscript.so");
}

// 
// Load MapServer .map file
//
// You can download the GMap demo at http://www2.dmsolutions.ca/mapserver/dl/
//
$map = ms_newMapObj("gmap75.map");

 
//
// Note: If you get errors with the saveWebImage() call below, then make sure
// that the directory specified by IMAGEPATH in the .MAP file exists and is
// writable by the httpd user.
//

// This works only with GIF or PNG
$map->SelectOutputFormat("PNG");

////////
// Draw the base layers into an imageObj
$img1 = $map->prepareimage();
$layer = $map->getLayerByName("bathymetry");
$layer->set("status", 1);
$layer->draw($img1);

//$img = $map->draw();
$url = $img1->saveWebImage();
echo "<P>Draw the base layers into an image...<p>\n";
printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $map->width, $map->height);


//////////////
// Use the parks layer as a mask... we only want to see the base layers
// through the area of the park polygons and the rest should be light grey.

// Start by creating a new image ... 
$img2 = $map->prepareimage();

// ... and we'll use a rectObj to draw the opaque mask background
$rect = ms_newRectObj();
$rect->setExtent(0, 0, $map->width, $map->height);

// We need to create a temporary layer and class to use in drawing the 
// filled rectangle that will be the opaque part of the mask.
$tmplayer = ms_newLayerObj($map);
$tmplayer->set("type", MS_LAYER_POLYGON);
$tmplayer->set("status", 1);
$tmplayer->set("transform", MS_FALSE);
$tmpclass = ms_newClassObj($tmplayer);
$tmpstyle = ms_newStyleObj($tmpclass);
$tmpstyle->color->setRGB(222,222,222);
$rect->draw($map, $tmplayer, $img2, 0, "");  // Draw rect with class 0

// Now fetch the park layer and change its only class to use color index 0
// which is the transparent background color... so the parks polygons will
// create transparent holes in the mask

$layer = $map->getLayerByName("park");
$layer->set("status", 1);

$class = $layer->getClass(0);
$style = $class->getStyle(0);
$style->color->setRGB(12,12,12);
$style->outlinecolor->setRGB(12,12,12);

$layer->draw($img2);

$url = $img2->saveWebImage();
echo "<P>Draw the mask into another image...<p>\n";
printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $map->width, $map->height);

////////
// Last step... combine the two images using pasteImage()
//
echo "<P>And combine the two with pasteImage()... you see the base layer through the holes in the mask...<p>\n";
$img1->pasteImage($img2, 0x0c0c0c);
$url = $img1->saveWebImage();
printf("<IMG SRC=%s WIDTH=%d HEIGHT=%d>\n", $url, $map->width, $map->height);

 
?>
 
</BODY>
</HTML>