This work is licensed under a Creative Commons .
© 2007 Jaime M. As Nozawa. You are free to copy, distribute and transmit the work and make derivative works under the following conditions: a) You must give the original author. b) can not use this work for commercial purposes (including publication by any means, by entities profit). c) If you alter, transform this work or creates a derivative work, distribute the work only under a license identical to this one. For any reuse or distribution, you must make clear to others the license terms of this work. Any of these conditions can be waived if you get permission from the owner of the copyright. The rights under fair use and other constraints are not affected by the above. Full license Castilian. The information contained in this document and the derivatives thereof are provided as they are, the authors assume no liability if the user or reader of these misuses.In this second part of the tutorial will try to do more dynamic our Mapfile (. Map). As we saw in Part 1, we could create a startup configuration file and upload the data listed in the file contents. Now we want to capture the data (properties) and modify the data found within the file, of course, without having to enter. Map to make a change, but performed only by code.
1. First the . Map will be like this to make it more interesting:
# Home mapfile
MAP NAME testSince we now realize I have added new features (in bold) of our initial mapfile. Our Window object
EXTENT SIZE 600 400 63 114 -19.0216 1.19528 -87.9964
WEB
ImagePath "C: / ms4w-php5/tmp/ms_tmp /" # This may vary according to your configuration
ImageURL "/ ms_tmp / "END
LAYER NAME" Departments "
STATUS ON DATA" Lim_dep.shp "TYPE POLYGON
CLASSITEM Nom_Dep
CLASS NAME" LIMA "
EXPRESSION / LIMA /
STYLE COLOR 200 OutlineColor
150 2 200 200 200
END END
CLASS NAME "OTHER"
EXPRESSION / .* /
STYLE COLOR 100 28 55 0 0 0
OutlineColor
END END END END
# end mapfile
layer now has one more property:
CLASSITEM Nom_Dep
with him we can choose a field within the table, in this case Nom_dep order to make some search and filter or segment by different criteria. CLASS In our view it is within LAYER now has more properties:
CLASS NAME "LIMA"
EXPRESSION / LIMA /
STYLE COLOR 200 150 2 200 200 200
OutlineColor
END END
In this case I am putting a name to the CLASS: LIMA, and the filter is made according to a regular expression in this case / LIMA / bone looks inside the column Nom_dep all records containing the word "LIMA".
STYLE At the other called OTHER, the regular expression / .* / means one or more characters. In other words, all the rest. and note that each CLASS colored with different colors both edges as the content.
2. now proceed to add more lines in our Ejemplo01.php and rename it to
ejemplo02.php
1 \u0026lt;? Php 2
/ / ejemplo02.php
3 / / Jaime M. As Nozawa
4 5 / / Load MapScript extension. Check if the extension is already loaded by default.
6 if (! extension_loaded ( "MapScript" )) dl ( 'php_mapscript. " . PHP_SHLIB_SUFFIX )
7 8 / / instantiate a new object: map object. The constructor must receive at least the parameter file location.
map 9 $ JMap = ms_newMapObj ( "ejemplo01.map" ) 10
11 / / Rendering 12
$ jImagen = $ JMap -> draw ();
13 14 / / create and capture the rendered image path. 15
$ url_imagen = $ jImagen -> saveWebImage ();
16 ?>
17 \u0026lt;HTML>
18
\u0026lt;HEAD> \u0026lt;TITLE> Example 19 1 \u0026lt;/ TITLE>
20 \u0026lt;/ HEAD>
21 \u0026lt;BODY>
22 \u0026lt;IMG SRC = \u0026lt;? php echo $ url_imagen ; ?> ; >
23 24 \u0026lt;? php
25 / / Get Properties MapaObj called JMap
26 echo "Name map: $ { JMap-> name} Facebook " ;
27 echo "Extent map {$ JMap-> extent-> minx} / / {$ JMap-> extent-> miny} / / {$ JMap-> extent-> maxx} / / {$ JMap-> extent-> maxy} Facebook " ;
28 echo" Size ñ or image: {$ jImagen-> width} {$ jImagen-> Facebook height} " ;
29 echo" Scale: 1 / {$ JMap-> scale} \u0026lt;p> " ;
30/ /
echo
ms_GetVersion ()
31 ?>
32 \u0026lt;/ BODY>
33 \u0026lt;/ HTML>
We clearly see that we can access the properties of MapObj: $ JMap
$ JMap -> name : Name property of the object MapObject
$ jImagen-> width: width of the image in pixels
$ JMap-> extent-> miny (minx) (maxx) (maxy) to capture
The Extent of the map scale is not very good proportion that is being used geodetic coordinates (do not get areas)
in next tutorials we will see how to correct this option.
3. Now that you know more or less objects and properties, they leave some interesting code for analysis:
1 \u0026lt;? Php
2 / / Get the layers
3 4 $ jCapas = $ JMap -> getAllLayerNames ();
5 $ layersOn = array ();
6 foreach ($ jCapas as $ idx => $ layer ) {
7 8
$ capaObj = $ JMap -> getLayerByName ( $ layer);
9
10 if ($ capaObj -> status == MS_ON ) {echo
11 "** COVER: $ {capaObj-> name} ** \u0026lt;ul> " ;
12
13 for ($ i = 0 ; $ capaObj - > getClass ( $ i) $ i + +) {
14 $ Class = $ capaObj -> getClass ( $ i);
15 echo "\u0026lt;li> ; CLASS: 16
\u0026lt;ul>
\u0026lt;li> 17 CLASS NAME: {$ class-> name} \u0026lt;/ li>
18 \u0026lt;li> EXPRESSION {$ Class-> ; getExpression ()}\u0026lt;/ li>
19 <li>COLOR: {$Class->getStyle(0)->color->red} {$Class->getStyle(0)->color->green} {$Class->getStyle(0)->color->blue}</li>
20 </ul></li>
21 " ;
22
23 }
24
25 echo "\u0026lt;/ Ul>" ;
26}
27 28 29 }
?>
Result:
continued ...
0 comments:
Post a Comment