⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_layer_mask.phtml

📁 Welcome to MS4W, the no fuss installer for setting up MapServer on Microsoft Windows platforms. The
💻 PHTML
字号:
<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>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -