Hello Armin, thank you for your detailed description.
[should go to the Wiki to some extend] On Thu, 08 Jun 2006 19:45:28 +0200 Armin Burger <armin.burger at gmx.net> wrote: > Stephan, > > at the moment I have not access to the code because it's used only > for an application at work. But I will describe the steps to keep in > mind for pmapper and dynamic layers. > > There are 2 parts to consider: > > 1) The dynamic layers have to be initilized, ie. defined with all > their properties. This has just to be done once when you want to add > one or more layers. And it has of course to be repeated if you want > to add other ones. > > 2) Once the layers have been initialized and are referenced for > p.mapper, you have to add them to the map all the time you want to do > something with them, ie. for every new map image creation or for > queries. > > > to 1) > --------------- > The script I attached has a function called > 'dyn_initPMLayerGroups()'. This function has to be completely adapted > to your application. Dynamic layers can have nearly indefinite > compositions that I don't see a generic way of doing this. Typically > one starts with a database query or user input that provides the > necessary parameters. OK, done. Works as expected. > > For easier definition I typically use an existing layer as template, > so I do not have to define all the properties by hand, just the ones > that differ from dynamic layer to another (think about a layer with > 10 classes and all the colors etc., would be quite tedious to code > this all via Mapscript). One can of course also create dynamic layers > based on different templates at the same time. > > The pre-defined layer definitions are saved in the > $_SESSION['dynLayerList'] as well as the names of them in > $_SESSION['allGroups']. > > The call at the end of this function > $this->dyn_addLayersToMap($dynLayerList); > > adds the layers to the map. When referencing a layer list as argument > these list is taken, otherwise the same function with argument > 'false' is used in step 2) (see below). > > For each layer definition in this 'dynLayerList' a call is made to > 'dyn_createMSlayer()' to actually create each single layer and add it > to the map. You can see that this function uses the template layer > specified in 'dyn_initPMLayerGroups()'. > > At the end of the 'dyn_initPMLayerGroups()' the initialization of > groups ('new Init_groups') is called again in order to reference all > these dynamic layers in the session var 'grouplist' for further use > in p.mapper. > > In order to have a way to distinguish between static layers and > dynamic layers the static ones are also additionally once referenced > in 'allGroups0' in initmap.php like > $_SESSION["allGroups0"] = $allGroups; > > The layers for templates should have set the status to 'OFF' and > should not be referenced in allGroups in config.ini if they are only > templates for dynamic layers. One could probably also define a second > map file just for the dynamic layers, but I don't know if one can > transfer the layer definition from one map to another. OK, now I have some problems. My template does not get recognized by pmapper. It is simple and called 'template'. The getLayerByName() inside dyn_createMSlayer() fails. but I cannot say why. basically I need to do: $templateLayer = $this->map->getLayerByName($templateLayName); $newMSLayer = $templateLayer; $newMSLayer->setMetaData("DESCRIPTION", $dyn_descr); $newMSLayer->set("name", $dyn_name); $newMSLayer->set("status", "ON"); $newMSLayer->set("data", $dyn_data); This does not work with my template layer, but with others already in the mapfile?! What is wrong here? > > > to 2) > --------------- > once dynamic layers are initialized they have to be added to the map > every time the map image is created or the map is queried. In map.php > there is already the function 'pmap_addCustomLayers()' where one > needs to add > > $dyn = new DynLayer($this->map); > $res = $dyn->dyn_addLayersToMap(false); OK, done. I inserted this: include_once("dynlayer.php"); if (isset($_SESSION['dynLayerList'])) { $dyn = new DynLayer($this->map); $res = $dyn->dyn_addLayersToMap(false); } > You will have to do the same for the queries. So add this call also > in query.php in function 'Query($map)', I hope this is sufficient, > otherwise you have to investigate further. Printing should already be > covered by map.php because the printing uses the 'PMap' class. THis is the next step as soon as I have the getLayerByName-stuff sorted out... > > The dynamic layers are added at the end of the map, so they are drawn > on top of the existing static layers. I used also always the call > 'dyn_moveStaticLayersDown()' in order to change the layer orders and > to move the static layers down in the map file structure, that means > they are displayed *on top* of the dynamic layers. > > > A slightly different approach instead of 2) would be to initialize > the layers like in 1), but then write everything to a temp map file > (using eg. the session var as file name) and then reference this file > as the map file in the session. This way you could more or less > completely drop setp 2) because the used map file has always the > dynamically created layers in it. I normally try to avoid working too > much with temp files if it does not have real benefits. But you could > think about that too. > > I hope this helps a bit. If you succeed you could also write a > description for this in the FAQ on the Wiki... Yes, this are very good hints and should go to the wiki, when I am done with it. Again, thanks for your help. Best regards Stephan -- GDF Hannover - Solutions for spatial data analysis and remote sensing Hannover Office - Mengendamm 16d - D-30177 Hannover Internet: www.gdf-hannover.de - Email: holl at gdf-hannover.de Phone : ++49-(0)511.39088507 - Fax: ++49-(0)511.39088508