tecnica:gps_cartografia_gis:php_mapscript_recipes
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tecnica:gps_cartografia_gis:php_mapscript_recipes [2009/09/16 15:52] – niccolo | tecnica:gps_cartografia_gis:php_mapscript_recipes [2010/02/26 23:46] (current) – niccolo | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| **[[http:// | **[[http:// | ||
| + | |||
| + | ===== Return a map image from a map file ===== | ||
| + | |||
| + | We can build an image from a working map file. Here we just turn on one layer, setting its status to '' | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | // PHP MapScript example. | ||
| + | // Display a map as an inline image or embedded into an HTML page. | ||
| + | $inline = true; | ||
| + | $map_path = '/ | ||
| + | $mapfile = ' | ||
| + | $map = ms_newMapObj($map_path . $mapfile); | ||
| + | $layer = $map-> | ||
| + | $layer-> | ||
| + | $map_image = $map-> | ||
| + | if ($inline) { | ||
| + | header(' | ||
| + | $map_image-> | ||
| + | exit; | ||
| + | } | ||
| + | $image_url = $map_image-> | ||
| + | ?> | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | </ | ||
| + | < | ||
| + | <IMG SRC=<? | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Build a map from scratch ===== | ||
| + | |||
| + | See [[http:// | ||
| ===== Generate the legend image ===== | ===== Generate the legend image ===== | ||
| Line 38: | Line 74: | ||
| For inline images you can omit web paths, because no temporary images will be created. | For inline images you can omit web paths, because no temporary images will be created. | ||
| + | |||
| + | ===== Make a query ===== | ||
| + | |||
| + | Open an existing map file and perform a **query by rectangle** on a layer, print results with a **template**. | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | $map = ms_newMapObj("/ | ||
| + | $selrect = ms_newrectObj(); | ||
| + | $selrect-> | ||
| + | $map-> | ||
| + | $buffer = $map-> | ||
| + | |||
| + | print "< | ||
| + | print $buffer; | ||
| + | print "</ | ||
| + | ?> | ||
| + | </ | ||
| + | |||
| + | The **'' | ||
| + | |||
| + | The querable layer is definend in the '' | ||
| + | |||
| + | < | ||
| + | MAP | ||
| + | ... | ||
| + | LAYER | ||
| + | ... | ||
| + | TEMPLATE " | ||
| + | TOLERANCE 6 | ||
| + | METADATA | ||
| + | DESCRIPTION | ||
| + | RESULT_FIELDS | ||
| + | RESULT_HEADERS " | ||
| + | END | ||
| + | END | ||
| + | END | ||
| + | </ | ||
| + | |||
| + | This is an example for **'' | ||
| + | |||
| + | <code html> | ||
| + | <!-- MapServer Template --> | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | This example does not use the template, it **iterates through the query results**: | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | $map = ms_newMapObj("/ | ||
| + | $selrect = ms_newrectObj(); | ||
| + | $selrect-> | ||
| + | |||
| + | $map-> | ||
| + | $layer = $map-> | ||
| + | $count = $layer-> | ||
| + | |||
| + | print "Query result count: " . $count . "< | ||
| + | print "< | ||
| + | for ($i = 0; $i < $count; $i++) { | ||
| + | $qRes = $layer-> | ||
| + | print_r($qRes); | ||
| + | } | ||
| + | print "</ | ||
| + | ?> | ||
| + | </ | ||
tecnica/gps_cartografia_gis/php_mapscript_recipes.1253109142.txt.gz · Last modified: by niccolo
