[Mapserver-users] automatic extension of map-file with dynamic layers?

Vinko Vrsalovic vinko at cprsig.cl
Wed Sep 24 02:54:55 EDT 2003


On Tue, Sep 23, 2003 at 08:48:51AM +0200, Frieso ter Haseborg wrote:
>  
> Is there any (build-in) way to do this extension of the map-file
> automatically?


No, there is no built-in way to do it, but it's not too difficult to
program, only tedious :)

You can create a hierarchy of tables on your DB to represent the
mapfile:

(assuming only one map, of course you can also add the Map table)

Layer
	Class
		Style
		Label

In each table you store all the parameters you need the user to be able
to change, then you do an interface to populate the DB and a wrapper to
construct the MapScript object instances from the DB representation.

The basic idea of the wrapper is:

<?php

	...
	
	// In the mapfile you can put the static stuff, but there's no
	// need to, you can use an empty mapfile (MAP END) if everything is stored
	// in the DB and then set it through the MapScript methods.
	// There're no dynamic fontsets or symbolsets, so if you need
	// that definition dynamic (you can still change symbols/fonts
	// dynamically choosing from the static symbol/fontset) you must
	// modify physically the appropriate file _before_ creating the
	// MapObj instance.
	
	$map = ms_newMapObject("/path/to/mapfile.map");
	
	$DBlayers = $db->Execute("SELECT * from Layer");
	
	while ($lyrow = $DBlayers->getNext()) {
	
		$lay = ms_newLayerObj($map);
		$lay->set("status",$lyrow->field['status']);
		$lay->set(......
		$DBclasses = $db->Execute("SELECT * from Class where
		LayerId = ".$lyrow->field['id']);
	
		while ($clarow = $DBclasses->getNext()) {
		
			$cla = ms_newClassObj($lay);
			$cla->color->setRGB($clarow->field['color']['r'],...
			//and so on...
		
		}
	}

	//Here you now have a complete MapObj , you can check with
	//$map->save("/path/to/save/mapfile.map");

	...
?>

Caveats: You have to pay attention to default values, if you choose them
wrong the layer might just not appear, and there is a lot of debugging
needed to check all the conditions (especially the minscales), but it
works. Also, you must create interfaces to pick colors and symbols and
fonts, besides the interfaces to set/modify all the numeric and text parameters 
for each table. And of course there's a penalty performace in all this
object creation and DB queries. In my experience it's not a showstopper,
but you can reduce the penalty by only storing in the DB the needed
parameters/objects, or by another, more clever, means :)

MapLab has good pickers (symbol,font,color) to stea^H^H^H^H copy.

HTH,
-- 
Vinko Vrsalovic <el[|- at -|]vinko.cl>
http://www.cprsig.cl



More information about the mapserver-users mailing list