PHP/MapScript layer mask test

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 "

Draw the base layers into an image...

\n"; printf("\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 "

Draw the mask into another image...

\n"; printf("\n", $url, $map->width, $map->height); //////// // Last step... combine the two images using pasteImage() // echo "

And combine the two with pasteImage()... you see the base layer through the holes in the mask...

\n"; $img1->pasteImage($img2, 0x0c0c0c); $url = $img1->saveWebImage(); printf("\n", $url, $map->width, $map->height); ?>