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, for-profit entities). 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. 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 ) {
11 echo "** CAPA :{$capaObj->name} **<ul>" ;
12
13 for( $i = 0 ; $capaObj -> getClass ( $i ); $i ++){
14 $Class = $capaObj -> getClass ( $i );
15 echo "<li>CLASS:
16 <ul>
17 <li>NOMBRE CLASS: {$Class->name}</li>
18 \u0026lt;li> EXPRESSION {$ Class-> getExpression ()}\u0026lt;/ li>
\u0026lt;li> 19 COLOR: {$ class-> getStyle (0) -> color-> red} {$ class-> getStyle (0) -> color-> green} {$ class-> getStyle (0) -> color-> blue} \u0026lt;/ li>
20 \u0026lt;/ ul> \u0026lt;/ li>
21 " ;
22 23}
24 25
echo "\u0026lt;/ ul>" ;
26}
27 28 29 }
?>
Explanation ...
a) $ jCapas = $ JMap-> getAllLayerNames ();
With the method (class MapObj) getAllLayerNames get an array ($ jCapas) in which we will have the names of each layer (Layers) of our mapfile. So doing a foreach would do a tour of array:
foreach ($ jCapas as $ idx => $ layer)
b) Re LayerObj
$ capaObj = $ JMap-> getLayerByName ($ layer);
With the method (class MapObj) getLayerByName LayerObj get an object ($ capaObj) from where you enter your parameter the name of the layer. As we got the names of each layer using the above method then we have no problems. In other words, the previous foreach travels layer by layer, and this method gets the LayerObj (See Table of tutorial part 1).
property
$ capaObj-> status
get itself the state of the layer, ON / OFF / DEFAULT. Values \u200b\u200bare constants in the mapscript API environment. In this case you can get the values: MS_ON, MS_OFF, MS_DEFAULT.
Other Boolean constants used in other situations: MS_TRUE, MS_FALSE, MS_YES, MS_NO
More Properties:
$ capaObj-> name: The name of the layer (String)
$ capaObj-> Transparency: Transparency layer (Q) $
capaObj-> maxscale: Maximum scale display (double) $
capaObj-> minscale: Minimum scale display (double) $
capaObj-> CLASSITEM: String CLASSITEM as explained at the start (string)
And all the properties you can add in the mapfile
c) Re ClassObj LayerObj
Each object can have many objects ClassObj inside, but always at least one. The ClassObj used to categorize our filter layer according to the field and filtering CLASSITEM with EXPRESSION. If you omit the EXPRESSION means that only had one ClassObj.
$ Class = $ capaObj-> getClass ($ i)
In our case I am using the method getClass (ObjLayer class) returns an object you ClassObj that is stored in the variable $ Class. The $ i is an integer that should represent CLASS which we refer. Zero (0) be the first class and compulsory for all Layer must always have a Class.
For a change now but I did not use foreach to a for travel.
More ClassObj object properties:
$ Class-> name: Name of the class
More ClassObj object methods:
$ Class-> getExpression (): Returns a string that gets the filter to use
d) styleObj
This object can set the background color, line thickness and color, font size, etc ...
I am in this case using
$ Class-> getStyle (0)
Method ClassObj class that gets an object styleObj. Because I've always used
a single Layer Style to get the number 0, but if more would have sequence numbers
Properties:
$ class-> getStyle (0) -> color: Property which holds the object colorObj.
This object has properties color RGB (red, green, blue)
$ Class-> getStyle (0) -> backgroundColor: background color (colorObj)
$ class-> getStyle (0) -> OutlineColor: color edge the CLASS (colorObj)
$ Class-> getStyle (0) -> size: Font size (int)
's all for the previous code, easy?
4. Modifying the properties
Let's start with something simple, let's modify the Extent of the map
(apparently we zoom) and the color of a Class of a layer:
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 $ jmap -> SetExtent (-80.17494, -14.0216, -72.93546, -9.19528) ;
12
13 $ jColor = $ jmap -> getLayerByName ('Departments')->
getClass (0)
->
getStyle (0)
->
color;
14
15 $ jColor
->
setRGB (100,150,120);
16
17 $ jImagen = $ jMap -> draw ();
18 / / create and capture the rendered image path. 19
$ url_imagen = $ jImagen -> saveWebImage ();
20 ?>
$ JMap-> setExtent (-80.17494, -14.0216, -72.93546, -9.19528);
In this case we are using the method to MODIFY
setExtent the Extent of the map and therefore we zoom into a region getting
the coordinates of the endpoints.
setExtent (double minx, double miny, double maxx, double maxy)
sieguiente
With online:
$ jColor = $ JMap-> getLayerByName ('Departments') -> getClass (0) -> getStyle ( 0) -> color;
As explained above colorObj have taken ownership style
0, Class 0, the layer called 'Departments' Map object.
After that modifies the color of that STYLE:
$ jColor-> setRGB (100,150,120);
Later I'll be working on a tutorial more interesting, I'll call
: Without Mapserver Mapfile (. Map) .
@ __ @
Result:
0 comments:
Post a Comment