title = $title; $this->endpoint = $endpoint; $this->layer = $layer; $this->sld = $sld; $this->transparent = true; if (!$transparency) $this->transparent = 'false'; $this->format= 'image/png'; } /** * */ function toJS($vname) { $js = "$vname = new OpenLayers.Layer.WMS('$this->title','$this->endpoint',{"; $js .= "layers: '$this->layer'"; $js .= ", format: '$this->format'"; if ($this->sld != '') $js .= ", sld: '$this->sld'"; if ($this->transparent) $js .= ", transparent:true"; else $js .= ", transparent:false"; $js .= "});\n"; return $js; } } class MapLayerWFS extends MapLayer { function MapLayerWFS($title, $endpoint, $layer, $maxfeatures) { $this->title = $title; $this->endpoint = $endpoint; $this->layer = $layer; settype($maxfeatures,'integer'); $this->maxfeatures = $maxfeatures; } function toJS($vname) { $js = "$vname = new OpenLayers.Layer.WFS('$this->title','$this->endpoint',{"; $js .= "typename: '$this->layer'"; if ($this->maxfeatures > 0) $js .= ", maxfeatures: '$this->maxfeatures'"; $js .= "}, { featureClass: OpenLayers.Feature.WFS});\n"; return $js; } } /** * Class implements a simple OpenLayers map generator. */ class MapIFrame { /** * Constructor for IFrame generator */ function MapIFrame($width, $height, $divid) { settype($width, 'string'); settype($height, 'string'); $this->width = $width; $this->height = $height; $this->divname = $divid; $this->googlebasemap = 1; //longitude latitude $this->initialPos = Array('0.0', '0.0', '2'); $this->layers = Array(); } /** * Add a Wms layer to the map */ function addWmsLayer($title, $endpoint, $layer, $sld, $transparency) { $wmslayer = new MapLayerWMS($title, $endpoint, $layer, $sld, $transparency); $this->layers[] = $wmslayer; } /** * Add a WFS layer to the map */ function addWfsLayer($title, $endpoint, $layer, $maxfeatures) { $wfslayer = new MapLayerWFS($title, $endpoint, $layer, $maxfeatures); $this->layers[] = $wfslayer; } /** * */ function toHTML() { $html = ""; $html .= ""; $html .= ""; $html .= "\n"; $html .= ""; $html .= sprintf("
\n", $this->width, $this->height); $html .= "
\n"; $html .= ""; return $html; } } /** * Retrieve the value of the GET or POST parameter with name = $name. If the name is not present, * return $defaultval * * @returns Value of GET or POST parameter */ function _getVar($name,$defaultval) { if (is_array($_GET)) { $kys = array_keys($_GET); $n = count($_GET); for ($i=0; $i < $n; $i++) { if (strcasecmp($kys[$i],$name)==0) { $tmp = $kys[$i]; if (strlen($tmp) <= 0) return NULL; return $_GET[$kys[$i]]; } } } if (is_array($_POST)) { $kys = array_keys($_POST); $n = count($_POST); for ($i=0; $i < $n; $i++) { if (strcasecmp($kys[$i],$name)==0) { $tmp = $kys[$i]; if (strlen($tmp) <= 0) return NULL; return $_POST[$kys[$i]]; } } } return $defaultval; } function _splita($delim, $str) { if (strpos($str, $delim) === false) return Array($str); return split($delim, $str); } /** * */ function generateIFrameContent() { $width = _getVar('width',800); $height = _getVar('height',475); $divid = _getVar('divid','mappa_1'); $delim = _getVar('delim','\|'); $usegoogle = _getVar('google',0); $genie = new MapIFrame($width, $height, $divid); $genie->googlebasemap = $usegoogle; //Add wms layers $titles = _splita($delim, _getVar('mtitles','')); $wmss = _splita($delim, _getVar('wms', '' )); $layers = _splita($delim, _getvar('mlyrs', '')); $slds = _splita($delim, _getVar('mslds', '')); $trans = _splita($delim, _getVar('trans','')); $nlayers = count($wmss); error_log("nlayers: $nlayers"); for ($i=0; $i < $nlayers; $i++) { $title = $titles[$i]; $wms = $wmss[$i]; $layer = $layers[$i]; $sld = $slds[$i]; $tran = $trans[$i]; if (strlen($wms) > 0 && strlen($title) > 0 && strlen($layer) > 0) { $genie->addWmsLayer($title, $wms, $layer, $sld, $tran); } } //Add wfs layers $ftitles = _splita($delim, _getVar('ftitles','')); $wfss = _splita($delim, _getVar('wfs', '' )); $flayers = _splita($delim, _getvar('flyrs', '')); $fmaxf = _splita($delim, _getVar('fmaxfeat', '500')); $nlayers = count($wfss); for ($i=0; $i < $nlayers; $i++) { $title = $ftitles[$i]; $wfs = $wfss[$i]; $layer = $flayers[$i]; $maxfeats = $fmaxf[$i]; if (strlen($wfs) > 0 && strlen($title) > 0 && strlen($layer) > 0) { $genie->addWfsLayer($title, $wfs, $layer, $maxfeats); } } return $genie->toHTML(); } /** * */ function showHelp() { header("Content-Type: text/html"); ?> Openlayers IFrame generator
Generates HTML that can be included in a web page to show a map of _whatever_.

Parmeters may be specified by GET or POST.

Parameters:
  width  - The width of the IFrame (default = 800)
  height - The height of the IFrame (default = 475)
  delim  - The delimiter to use for lists of values.  Default is "|". Don't use ","
  google - Display google background. 0=none, 1=satellite, 2=plain. 
  
  wms    - A list of web mapping service endpoints to render (order is preserved).
  mlyrs  - A list of layers, each entry corresponding to a wms endpoint.  Note that
           a single wms endpoint may have more than one layer, separated by ","
  mtitles - A list of titles for wms layers
  mtrans - Transparency for each layer (use 0 or 1)
  sld - A list of SLDs for wms layers
  
  wfs    - A list of web feature service endpoints to render (order is preserved).
  flyrs  - A list of layers, each entry corresponding to a wfs endpoint.  
  ftitles - A list of titles for wms layers
  fmaxf - A list of max number of features per layer
  
           
Example:
  mapIFrame.php?op=map&mtitles=OpenLayers&wms=http%3A//labs.metacarta.com/wms/vmap0%3F&mlyrs=basic&mslds=
  
  mapIFrame.php?op=map&google=1
  mapIFrame.php?op=map&google=1&ftitles=ds12003896&wfs=http%3A//omtest.cria.org.br%3A8080/geoserver/wfs&flyrs=ds12003896&maxfeat=500
  
  mapIFrame.php?op=map&mtitles=meanRad&mtrans=true&wms=http%3A//omtest.cria.org.br/cgi-bin/mapserv%3Fmap%3D/opt/data/mapfiles/envlayers.map&mlyrs=meanRad&mslds=
  
                      &ftitles=example_dataset&wfs=http%3A//omtest.cria.org.br%3A8080/geoserver/wfs&flyrs=example_dataset&maxfeat=500
                      
                      sld: http%3A//nomad.vieglais.com/biogeosdi/backend/util/rasterDps/sldrasrc.php%3Fl%3DmeanRad%26m%3D60%26x%3D300%26n%3D6%26o%3D0.5
                      
&mtitles=meanRad&mtrans=true&wms=http://omtest.cria.org.br/cgi-bin/ogctemp.cgi/nPUGQi&mlyrs=nPUGQi&mslds=http%3A//nomad.vieglais.com/biogeosdi/backend/util/rasterDps/sldrasrc.php%3Fl%3DnPUGQi%26m%3D0.1%26x%3D2%26n%3D6%26o%3D0.5

 

Example:

Try me.