Hello Armin, 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. > > 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. > > > 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); > > 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. > > 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. > This seems to work so far. I have created another popup-window where the layers can be selected. after submtting the $_SESSION-vars are updated inside the popup. But when I initiate a reloadMap() for the opener.window, the $_SESSION (printed in the main-window) does not contain any new dynlayer entries and the map/legend will not yet be updated. I am a bit lost in the xmlhttp.js for reloading the legend and the mapframe to show up the dynadded layers. Thanks 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