Hi Dominic,
Here's a little snipit i've thrown together that should accomodate your request. Although it's untested it would be a good start to doing this.
How it works is:
You have two mapfiles. One is your application which is loaded in the fusion AppDef and the other is a mapfile that has all the layers you wish to add.
This "catalogue" map file is what this code will search through to find the layer requested by the user
These javascript functions are to be included in your applications template code. and the php script can be placed anywhere in the applications web accessible folder.
You simply call the javascript function addCatalogLayer() with the layername as it is specified in the catalogue map file and it will search through it and add it to the active sessions mapfile and reload the map from the callback.
Note I've wipped this together from another application i've worked on with out testing it at all so there may be errors. :)
Hope this helps.
Cheers
Paul D.
--
Paul Deschamps
Applications Specialist
DM Solutions Group Inc.
Office: (613) 565-5056 x28
[hidden email] http://www.dmsolutions.ca
http://research.dmsolutions.ca<?
// BEGIN PHP CODE SNIPIT -----------------------------
// path to fusion root
define('FUSION_ROOT','/opt/fgs/apps/fusion');
// path to a valid mapserver mapfile with all the layers we are going to allow the user to add.
define('APP_LAYER_CATALOG','/opt/fgs/apps/fusion/layers.map');
include FUSION_ROOT."/mapserver/php/Common.php";
include FUSION_ROOT."/common/php/Utilities.php";
if (!isset($mapName)) {
die('mapname not set');
}
// defaults to false
$szObject->addedLayer = false;
if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
$szObject = addLayer($_REQUEST["layername"]);
}
$szJsonData = var2json($szObject);
header('Content-type: text/plain');
header('X-JSON: true');
echo $szJsonData;
function addLayer($szValue){
global $mapName;
$oReturn->addedLayer = false;
// open up the session mapfile.
$oMap = ms_newMapObj($_SESSION['maps'][$mapName]);
// open up the catalogue map file.
$oCatalogMapFile = ms_newMapObj(APP_LAYER_CATALOG);
// loop through the catalogue mapfile.
for($i = 0; $i < $oCatalogMapFile->numlayers; $i++){
// get the layer
$oLayer = $oCatalogMapFile->getLayer( $i );
// did we find the layer by it's layername.
if($oLayer->name == $szValue){
//found layer add it to the session mapfile.
ms_newLayerObj( $oMap, $oLayer );
// return true
$oReturn->addedLayer = true;
}
}
// save map file if we've added a layer.
if($oReturn->addedLayer == true){
// save the session mapfile.
$oMap->save($_SESSION['maps'][$mapName]);
}
return $oReturn;
}
// END PHP CODE SNIPIT -----------------------------
?>
<!-- BEGIN JAVASCRIPT CODE SNIPIT ----------------------------- -->
// place this javascript in your application template.
<script language="javascript">
function addCatalogLayer(szLayerName){
var s = pathToAddLayer + "addLayer.php";
var mapWidget = Fusion.getMapById('mapArea');
var maps = mapWidget.getAllMaps();
var map = maps[0];
var session = 'session='+map.getSessionID();
var mapName = '&mapname='+ map._sMapname;
var layername = '&layername=' +szLayerName;
var params = session+mapName+layername;
var opts = {parameters: params, onComplete: addCatalogLayerCB.bind(null)};
Fusion.ajaxRequest(s, opts);
}
/*
function addCatalogLayerCB - CB func from addCatalogLayer. The Layer is now added to mapfile,
if o.addedLayer = true else something when wrong.
*/
function addCatalogLayerCB(r){
var o = '';
eval('o='+r.responseText);
if(o.addedLayer == true){
var map = Fusion.getMapById('mapArea');
var maps = map.getAllMaps();
maps[0].reloadMap();
} else {
alert('addCatalogLayerCB:could not add layer');
}
}
</script>
<!-- END JAVASCRIPT CODE SNIPIT ----------------------------- -->
On Mon, Jun 15, 2009 at 4:17 PM, Dominic Gervais
<[hidden email]> wrote:
Hello All fusion users....
Is there a way of adding a layer to the mapfile using PHP/MapScript. I'd like to enpower users so they can choose to add a layer of their choice to a "base" Mapfile. So, scaling is out of the question.
I know I can add some code in the loadMap.php file. But, is it possible to retrieve some variables in that file that would be submitted by the user prior to accessing the index.html (or index.php in my case) via a form of some sort.
Any hints would be appreciated...
Thanks,
Dominic
Windows Live helps you keep up with all your friends,
in one place.
_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users
_______________________________________________
fusion-users mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/fusion-users