"jp", /* title: page title */ "title" => "EasyWMSView", /* htmltitle: if not specified, $title is applied. */ "htmltitle" => null, /* copyright: footer string. simple html can be used. */ "copyright" => "powered by EasyWMSView.", /* keywords: meta keywords in html. */ "keywords" => "EasyWMSView, OpenLayers, WMS, WMTS", /* help_detail_url: custom help url. default help image (for jp or en) * is applied if not specified. */ "help_detail_url" => null, /* default params of lat, long and zoomlevel. * valid range and unit are depends on Map object's params hard-coded * in this php file. 0 will be good if you have no idea. */ "lat" => 4400000, "long" => 15300000, "zoomlevel" => 6, /* function switches */ "enableLegend" => true, "enableFeatureInfo" => true ); /*** * ADVANCED CUSTOM PARAMETERS ***/ /* image_url: applied to Ext.IMAGE_SRC_URL. */ #$image_url = 'http://js.example.org/ext-3.3.1/resources/images/default/s.gif'; /* parameters around zkurai * _url: zkurai service URL. disabled if not specified. * _pdf_width, _pdf_height: page size of generated PDF. */ #$zkurai_url = 'http://example.com/zkurai/genpdf'; $zkurai_url = 'https://gbank.gsj.jp/genPDF/cgi-bin/genpdf.php'; $zkurai_pdf_width = 595; $zkurai_pdf_height = 847; /*****************************************************************************/ /* parse params in HTTP-REQUEST. */ if (isset($_SERVER)) { switch($_SERVER['REQUEST_METHOD']) { case 'GET': $req = &$_GET; break; case 'POST': $req = &$_POST; break; } } if (isset($req) && isset($req['dataset'])) { $tmp_filename = htmlspecialchars($req['dataset'], ENT_QUOTES); if (preg_match('/[\'"\`;\/\\\]/', $tmp_filename) != 0) { printf("Error: invalid dataset
\n"); exit; } $json_filename = $tmp_filename . ".json"; } if (! isset($json_filename)) { /* dataset is not specified in HTTP-REQUEST. */ /* fallback sequence-1, auto redirect to specified URL. */ if (isset($redirect_url)) { print_auto_jump_page($redirect_url, $redirect_desc, $redirect_sec); exit; } /* skip auto-jumping unless redirect_url is set. */ /* fallback sequence-2, generate JSON-filename based on PHP-filename. */ $php_filename = basename(__FILE__); $json_filename = preg_replace("/\.php$/", ".json", $php_filename); if (strcmp($json_filename, $php_filename) == 0) { printf("Error: un-expected PHP filename
\n"); exit; } } $json_filename = $dataset_dir . "/" . $json_filename; if (! (file_exists($json_filename) && is_file($json_filename))) { printf("Error: invalid (or missing) dataset.
\n"); exit; } /* load and check json. */ if (prepare_json($json_filename) != true) { exit; } ?>

Loading ...
Missing dataset parameter.
You will be forwarded to $_desc ( $_url ) in $_sec seconds.
EOD; } function generate_js_parts() { global $image_url; global $ewv_option; global $zkurai_url, $zkurai_pdf_width, $zkurai_pdf_height; global $qtip_string; global $g_def_global; global $g_def_map; global $g_def_control; global $g_def_toolbar; global $g_def_viewport; $help_icon_url = "../images/help.png"; if (! isset($ewv_option[title])) { $ewv_option[title] = ""; } if (! isset($ewv_option[htmltitle])) { $ewv_option[htmltitle] = $ewv_option[title]; } if (! isset($ewv_option[copyright])) { $ewv_option[copyright] = ""; } if (! is_numeric($ewv_option[lat])) { $ewv_option[lat] = 0; } if (! is_numeric($ewv_option[long])) { $ewv_option[long] = 0; } if (! is_numeric($ewv_option[zoomlevel])) { $ewv_option[zoomlevel] = 0; } $_indent = " "; if ($ewv_option[lang] == "jp") { $menu_string = 'メニューパネル'; $layers_string = 'レイヤ選択'; $legend_string = '凡例'; $qtip_string = 'レイヤ名クリックで凡例表示'; $help_detail_url = '../images/help_detail.png'; $menu_help_string = 'チェックボックスで選択したレイヤ画像を描画します。\n' . 'レイヤ名をクリックすると凡例画像を表示します。\n' . 'レイヤ名を右クリックしてOpacityのスライドバーを変更すると\n' . 'そのレイヤの透明度が変化します。'; $legend_help_string = '左側のレイヤ名をクリックすると凡例画像を表示します。\n' . 'ただしクリックしたレイヤに凡例画像が存在しない場合は、\n' . '空白あるいは (no legend) と表示されます。\n' . '凡例を表示中のレイヤ名は下線・太字で装飾されています。'; } else { $menu_string = "menu"; $layers_string = "layers"; $legend_string = "legend"; $qtip_string = 'click layer name to draw legend'; $help_detail_url = "../images/help_detail_en.png"; $menu_help_string = 'Selected layers are drawn at the center pane.\n' . 'The legend is drawn of the layer which name is clicked.\n' . 'Opacity of each layer can be changed by the slide bar\n' . 'shown by right-clicking its layer name.'; $legend_help_string = 'The legend is drawn of the layer which is clicked at left pane.\n' . 'If the layer does not have legend, empty image or (no legend) ' . 'is drawn.\n' . 'Underline & bold name means the layer which legend is drawn.'; } if (isset($ewv_option[help_detail_url])) { /* overwrite $help_detail_url if specified in json file. */ $help_detail_url = $ewv_option[help_detail_url]; } $g_def_global = <<(no legend)'); } var _root = Ext.getCmp('layertree').getRootNode(); var child_callback = function() { if (this.leaf) { this.ui.removeClass("x-tree-selected-legend"); } else { this.eachChild(child_callback); } }; _root.eachChild(child_callback); n.ui.addClass("x-tree-selected-legend"); }; EOD; } else { $_func_switch_legend = "var switch_legend = function(n) { return; }"; } $_func_switch_legend = preg_replace("/(\n+)/m", "$1".$_indent , $_func_switch_legend); $g_def_control = <<' . '' . ''; $viewport_east = <<' . '' . ''; $viewport_west = << の id を付与してある。 _node = _root.findChild('id', "xlayer-" + _inst.params.LAYERS[n], true); var _name = _parent.text + " / " + _node.text; _name = _name.replace(/\"/g, '\\\"'); var _obj_data = '{' + '"url":"' + _inst.url + '", ' + '"params":' + JSON.stringify(_tmp_params) + ', ' + '"options":' + JSON.stringify(_inst.options) + '}'; if (_count++ > 0) _data += ', '; _data +='{' + '"type":"' + _type + '", ' + '"name":"' + _name + '", ' + '"opacity":' + _inst.opacity + ', ' + '"data":' + _obj_data + '}'; } continue; } // WMS + シングルレイヤ var _name = _root.findChild('layerNames', _inst.name, true).text; var _obj_data = '{' + '"url":"' + _inst.url + '", ' + '"params":' + JSON.stringify(_inst.params) + ', ' + '"options":' + JSON.stringify(_inst.options) + '}'; } else if (_inst.layer) { // params.LAYERS 要素を持たないのは WMTS クラス // !! Note !! // 今後、WMTS 以外のクラスをサポートする場合、それぞれの // クラスの識別方法を検討する必要がある。 var _node = _root.findChild('layerNames', _inst.name, true); var _type = "WMTS"; var _name = _node.text; var _obj_data = '{"options":' + JSON.stringify(_inst.options) + '}'; } else { // skip unknown. continue; } if (!_name) continue; if (_count++ > 0) _data += ', '; // 親ノードがあるなら PDF 上のレイヤ名に加える if (_node.parentNode && _node.parentNode.text) _name = _node.parentNode.text + " / " + _name; _name = _name.replace(/\"/g, '\\\"'); _data +='{' + '"type":"' + _type + '", ' + '"name":"' + _name + '", ' + '"opacity":' + _inst.opacity + ', ' + '"data":' + _obj_data + '}'; } _data += '] '; _data +='}'; // zkurai Service に送るデータの生成完了 var _encoded_data = encodeURIComponent(_data); // なぜか encodeURIComponent がシングルクオートをエンコードしてくれない // 仕方ないので手動対応。正常にエンコードしてくれる環境でも害はないはず。 _encoded_data = _encoded_data.replace(/'/g, "%27"); // zkurai サービスに POST メソッドでデータを送るためのフォームを生成 var _url = '$zkurai_url'; var _input = ""; var _form = "
" + _input + "
"; // console.log("FORM: " + _form); // 実行! jQuery(_form).appendTo('body').submit().remove(); return; }, iconCls: 'download', tooltip: 'generate PDF', scope: this }); toolbarItems.push(zkuraiAction); EOD; $zkurai_action = preg_replace("/(\n+)/m", "$1 ", $zkurai_action); } else { // zkurai サービスの URL が未設定なら PDF 作成ボタンを表示しない $zkurai_action = ""; } $g_def_toolbar = <<\n"); return false; } $loaded_objs = json_decode($loaded_data); /* This error handling comes from PHP official site. */ /* URI */ switch (json_last_error()) { case JSON_ERROR_NONE: break; case JSON_ERROR_DEPTH: echo ' - Maximum stack depth exceeded'; return false; case JSON_ERROR_STATE_MISMATCH: echo ' - Underflow or the modes mismatch'; return false; case JSON_ERROR_CTRL_CHAR: echo ' - Unexpected control character found'; return false; case JSON_ERROR_SYNTAX: echo ' - Syntax error, malformed JSON'; return false; case JSON_ERROR_UTF8: echo ' - Malformed UTF-8 characters, possibly incorrectly encoded'; return false; default: echo ' - Unknown error'; return false; } $ewv_option = array(); if (isset($loaded_objs->{"ewvOption"})) { $tmpopt = $loaded_objs->{"ewvOption"}; foreach($ewv_default_option as $key => $value) { if (isset($tmpopt->{$key})) { $ewv_option[$key] = $tmpopt->{$key}; } else { $ewv_option[$key] = $ewv_default_option[$key]; } if (is_string($ewv_option[$key])) { $ewv_option[$key] = preg_replace("/'/", "", $ewv_option[$key]); } } } else { $ewv_option = $ewv_default_option; } if (! isset($loaded_objs->{"wmstree"})) { echo 'Error: invalid JSON structure (missing wmstree).
\n'; return false; } $wmstree = $loaded_objs->{"wmstree"}; /* create main JavaScripts. */ return createJS($wmstree); } function print_head_info() { global $ewv_option; print("\n"); if (isset($ewv_option[htmltitle])) { print(" $ewv_option[htmltitle]\n"); } if (isset($ewv_option[keywords])) { print(" \n"); } } function print_load_title() { global $ewv_option; print($ewv_option[htmltitle] . "\n"); } function phpObj2jsCode($phpval) { if (is_scalar($phpval)) { if (is_string($phpval)) { return '"' . preg_replace("/\"/m", "\\\"", $phpval) . '"'; } else if (is_float($phpval)) { return var_export($phpval, true); } else { return var_export($phpval, true); } } else { if (is_array($phpval)) { $array = "["; $cnt = 1; foreach($phpval as $value) { if ($cnt != 1) $array .= ", "; $cnt++; $array .= phpObj2jsCode($value); } $array .= "]"; return $array; } else if (is_object($phpval)) { $object = "{"; $cnt = 1; foreach($phpval as $value) { if ($cnt != 1) $object .= ", "; $cnt++; $object .= phpObj2jsCode($value); } $object .= "}"; return $object; } } } function createSize($data) { if (is_array($data)) { if (count($data) != 2) { print("Error: invalid array for Size.
\n"); var_dump_html($data); return false; } return "new OpenLayers.Size({" . '"w":' . phpObj2jsCode($data[0]) . ", " . '"h":' . phpObj2jsCode($data[1]) . "})"; } if (!is_object($data) || !(isset($data->{"w"}) && isset($data->{"h"})) || !(is_numeric($data->{"w"}) && is_numeric($data->{"h"}))) { print("Error: invalid Size.
\n"); var_dump_html($data); return false; } return "new OpenLayers.Size({" . '"w":' . phpObj2jsCode($data->{"w"}) . ", " . '"h":' . phpObj2jsCode($data->{"h"}) . "})"; } function createLonLat($data) { if (is_array($data)) { if (count($data) != 2) { print("Error: invalid array for LonLat.
\n"); var_dump_html($data); return false; } return "new OpenLayers.LonLat([" . $data[0] . ", " . $data[1] . "])"; } if (!is_object($data) || !(isset($data->{"lon"}) && isset($data->{"lat"})) || !(is_numeric($data->{"lon"}) && is_numeric($data->{"lat"}))) { print("Error: invalid LonLat.
\n"); var_dump_html($data); return false; } return "new OpenLayers.LonLat([" . phpObj2jsCode($data->{"lon"}) . ", " . phpObj2jsCode($data->{"lat"}) . "])"; } function createBounds($data) { if (is_array($data)) { if (count($data) != 4) { print("Error: invalid array for Bounds.
\n"); var_dump_html($data); return false; } return "new OpenLayers.Bounds([" . $data[0] . ", " . $data[1] . ", " . $data[2] . ", " . $data[3] . "])"; } if (!is_object($data) || !(isset($data->{"left"}) && isset($data->{"bottom"}) && isset($data->{"right"}) && isset($data->{"top"})) || !(is_numeric($data->{"left"}) && is_numeric($data->{"bottom"}) && is_numeric($data->{"right"}) && is_numeric($data->{"top"}))) { print("Error: invalid Bounds.
\n"); var_dump_html($data); return false; } return "new OpenLayers.Bounds([" . phpObj2jsCode($data->{"left"}) . ", " . phpObj2jsCode($data->{"bottom"}) . ", " . phpObj2jsCode($data->{"right"}) . ", " . phpObj2jsCode($data->{"top"}) . "])"; } function createProjection($data) { if (is_string($data)) { /* return "new OpenLayers.Projection({" . "projCode:" . phpObj2jsCode($data) . "})"; */ return phpObj2jsCode($data); } if (!(is_object($data) && isset($data->{"projCode"}))) { print("Error: invalid Projection.
\n"); var_dump_html($data); return false; } /* return "new OpenLayers.Projection({" . "projCode:" . phpObj2jsCode($data->{"projCode"}) . "})"; */ return phpObj2jsCode($data->{"projCode"}); } function createMatrixId($data) { if (!is_object($data)) { print("Error: invalid matrixId.
\n"); var_dump_html($data); return false; } $str = "{"; $cnt = 1; foreach ($data as $key => $value) { if ($cnt++ != 1) $str .= ","; switch($key) { case "topLeftCorner": $lonlat = createLonLat($value); if ($lonlat == false) { print("Error: invalid matrixId.
\n"); return false; } $str .= "\n" . $key . ": " . $lonlat; break; default: $str .= "\n" . $key . ": " . phpObj2JsCode($value); } } $str .= "\n}"; return $str; } function createMatrixIds($data) { if (!is_array($data)) { print("Error: invalid MatrixIds.
\n"); var_dump_html($data); return false; } $str = "["; $cnt = 1; foreach ($data as $value) { if ($cnt++ != 1) $str .= ","; $mid = createMatrixId($value); if ($mid == false) { print("Error: invalid MatrixIds.
\n"); return false; } $str .= $mid; } $str .= "]\n"; return $str; } function createWMTS($mapdata) { if (!is_object($mapdata)) { print("Error: invalid mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } /* name */ if (!isset($mapdata->{"name"}) || !is_string($mapdata->{"name"})) { print("Error: invalid or missing name in mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } /* url */ if (!isset($mapdata->{"url"}) || !is_string($mapdata->{"url"})) { print("Error: invalid or missing url in mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } /* layer */ if (!isset($mapdata->{"layer"}) || !is_string($mapdata->{"layer"})) { print("Error: invalid or missing layer in mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } /* matrixSet */ if (!isset($mapdata->{"matrixSet"}) || !is_string($mapdata->{"matrixSet"})) { print("Error: invalid or missing matrixSet in mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } /* style */ if (!isset($mapdata->{"style"}) || !is_string($mapdata->{"style"})) { print("Error: invalid or missing style in mapdata for WMTS.
\n"); var_dump_html($mapdata); return false; } $str = "new OpenLayers.Layer.WMTS({"; $cnt = 1; foreach($mapdata as $key => $value) { if ($key == "class") { /* skip EasyWMSView specific property. */ continue; } if ($cnt++ == 1) { $str .= "\n "; } else { $str .= ",\n "; } switch($key) { case "projection": case "displayProjection": /* handling OpenLayers.Projection of String. */ $projstr = createProjection($value); if ($projstr == false) { print("Error: invalid projection at " . $mapdata->{"name"} . ".
\n"); return false; } $str .= $key . ": " . $projstr; break; case "maxExtent": case "minExtent": case "tileFullExtent": /* handling OpenLayers.Bounds. */ $boundsstr = createBounds($value); if ($boundsstr == false) { print("Error: invalid maxExtent/minExtent at " . $mapdata->{"name"} . ".
\n"); return false; } $str .= $key . ": " . $boundsstr; break; case "tileSize": /* handling OpenLayers.Size. */ $sizestr = createSize($value); if ($sizestr == false) { print("Error: invalid tileSize at " . $mapdata->{"name"} . ".
\n"); return false; } $str .= $key . ": " . $sizestr; break; case "tileOrigin": /* handling OpenLayers.LonLat. */ $lonlatstr = createLonLat($value); if ($lonlatstr == false) { print("Error: invalid tileOrigin at " . $mapdata->{"name"} . ".
\n"); return false; } $str .= $key . ": " . $lonlatstr; break; case "matrixIds": $midsstr = createMatrixIds($value); if ($midsstr == false) { print("Error: invalid matrixIds at " . $mapdata->{"name"} . ".
\n"); return false; } $str .= $key . ": " . $midsstr; break; default: /* handling primitive data types. */ $str .= $key . ": " . phpObj2jsCode($value); break; } } $str .= "\n})"; //$str = preg_replace("/\n+/m", "\n ", $str); return $str; } function createWMS($mapdata) { if (!is_object($mapdata)) { print("Error: invalid mapdata for WMS.
\n"); var_dump_html($mapdata); return false; } /* name dump */ if (!isset($mapdata->{"name"}) || !is_string($mapdata->{"name"})) { print("Error: invalid or missing name in mapdata for WMS.
\n"); var_dump_html($mapdata); return false; } $name = phpObj2jsCode($mapdata->{"name"}); /* url dump */ if (!isset($mapdata->{"url"}) || !is_string($mapdata->{"url"})) { print("Error: invalid or missing url in mapdata for WMS.
\n"); var_dump_html($mapdata); return false; } $url = phpObj2jsCode($mapdata->{"url"}); /* params dump */ if (!isset($mapdata->{"params"}) || !is_object($mapdata->{"params"})) { print("Error: invalid or missing params in mapdata for WMS.
\n"); var_dump_html($mapdata); return false; } $paramsobj = $mapdata->{"params"}; $paramsstr = "{"; $cnt = 1; foreach($paramsobj as $key => $value) { if ($cnt != 1) $paramsstr .= ", "; $cnt++; $paramsstr .= $key . ": " . phpObj2jsCode($value); } $paramsstr .= "}"; /* options dump */ if (!isset($mapdata->{"options"}) || !is_object($mapdata->{"options"})) { print("Error: invalid or missing options in mapdata for WMS.
\n"); var_dump_html($mapdata); return false; } $optionsobj = $mapdata->{"options"}; $optionsstr = "{"; $cnt = 1; foreach($optionsobj as $key => $value) { if ($cnt != 1) $optionsstr .= ", "; $cnt++; /* convert properties including ones of superclass. WMS inheritance shows below. OpenLayers.Layer -> OpenLayers.Layer.HTTPRequest -> OpenLayers.Grid -> OpenLayers.Layer.WMS */ switch($key) { case "projection": case "displayProjection": /* handling OpenLayers.Projection of String. */ $projstr = createProjection($value); if ($projstr == false) { print("Error: invalid projection at " . $mapdata->{"name"} . ".
\n"); return false; } $optionsstr .= $key . ": " . $projstr; break; case "maxExtent": case "minExtent": /* handling OpenLayers.Bounds. */ $boundsstr = createBounds($value); if ($boundsstr == false) { print("Error: invalid maxExtent/minExtent at " . $mapdata->{"name"} . ".
\n"); return false; } $optionsstr .= $key . ": " . $boundsstr; break; case "tileSize": /* handling OpenLayers.Size. */ $sizestr = createSize($value); if ($sizestr == false) { print("Error: invalid tileSize at " . $mapdata->{"name"} . ".
\n"); return false; } $optionsstr .= $key . ": " . $sizestr; break; case "tileOrigin": /* handling OpenLayers.LonLat. */ $lonlatstr = createLonLat($value); if ($lonlatstr == false) { print("Error: invalid tileOrigin at " . $mapdata->{"name"} . ".
\n"); return false; } $optionsstr .= $key . ": " . $lonlatstr; break; case "serverResolutions": /* handling array of Number.*/ case "scales": case "resolutions": /* handling array of float. */ case "eventListners": case "metadata": case "tileOptions": case "backBufferLonLat": case "gridLayout": /* handling object type. */ default: /* handling primitive data types. */ $optionsstr .= $key . ": " . phpObj2jsCode($value); break; } } $optionsstr .= "}"; $wmsstr = "new OpenLayers.Layer.WMS(\n" . " " . $name . ",\n" . " " . $url . ",\n" . " " . $paramsstr . ", \n" . " " . $optionsstr . "\n" . ")"; $wmsstr = preg_replace("/\n+/m", "\n", $wmsstr); return $wmsstr; } function createMapInstanceJS($mapdata, $class) { if ($class == null) { print("InternalError: no class specified.
\n"); return false; } switch($class) { case "WMS": return createWMS($mapdata); case "WMTS": return createWMTS($mapdata); } print("Error: not-supported class: " . $mapdata->{"class"} . "
\n"); return false; } function traverseTree($wmsnode, $tree_indent, $parent_class) { if (! isset($wmsnode->{"treeinfo"})) { print("Error: missing treeinfo.
\n"); return false; } else if (! is_object($wmsnode->{"treeinfo"})) { print("Error: invalid treeinfo.
\n"); var_dump_html($wmsnode->{"treeinfo"}); return false; } $treeinfo = $wmsnode->{"treeinfo"}; $mapdata = null; $class = null; $inherit_class = null; global $g_def_layertree; global $g_def_layermap; global $global_js_var_id; global $ewv_option; global $qtip_string; $varname = null; $is_folder = false; $is_group_parent = false; $is_group_layer = false; $is_single_layer = false; $is_base_layer = false; if (isset($wmsnode->{"mapdata"})) { $mapdata = $wmsnode->{"mapdata"}; if (isset($treeinfo->{"children"})) { $is_group_parent = true; } else { $is_single_layer = true; } if (isset($mapdata->{"isBaseLayer"})) { $is_base_layer = $mapdata->{"isBaseLayer"}; } else if (isset($mapdata->{"options"}->{"isBaseLayer"})) { $is_base_layer = $mapdata->{"options"}->{"isBaseLayer"}; } } else { if (isset($treeinfo->{"children"})) { $is_folder = true; } else if (isset($treeinfo->{"layerNames"})) { $is_group_layer = true; } } if ($is_group_layer) { if ($parent_class == null) { print("Internal Error: parent_class is null.
\n"); return false; } $class = $parent_class; } else if ($is_group_parent || $is_single_layer) { $class = "WMS"; if (isset($mapdata->{"class"})) { $class = $mapdata->{"class"}; } if ($is_group_parent) { $inherit_class = $class; } } if ($is_single_layer || $is_group_parent) { $varname = "_LAYER_" . var_export($global_js_var_id++, true); if ($is_single_layer) { $mapdata->{"name"} = $varname; } else if (! isset($mapdata->{"name"})) { print("Error: missing 'name' of GroupLayer-MapData.
\n"); return false; } $mapstr = createMapInstanceJS($mapdata, $class); if ($mapstr == false) return false; $g_def_layermap .= "var " . $varname . " = " . $mapstr . ";\n" . "maparray.push(" . $varname . ");\n\n"; } $cnt = 0; $g_def_layertree .= $tree_indent . "{\n"; foreach($treeinfo as $key => $value) { if ($key == "children") { continue; } if($cnt++ != 0) $g_def_layertree .= ",\n"; $g_def_layertree .= $tree_indent . " " . $key . ": " . phpObj2jsCode($value); } // GeoEXT の text パラメータを Map 側から参照するための細工をしておく。 // 自由に操作できるパラメータが少ないため、id を利用。 if ($is_single_layer) { // グループレイヤでないなら単純に id = name で関連付ける。 // Map 側の layerName に同じ name が入るので、検索できる。 if($cnt++ != 0) $g_def_layertree .= ",\n"; $g_def_layertree .= $tree_indent . " " . "layerName: " . phpObj2jsCode($mapdata->{"name"}); $g_def_layertree .= ",\n" . $tree_indent . " " . "id: " . phpObj2jsCode($mapdata->{"name"}); if ($ewv_option[enableLegend]) { $g_def_layertree .= ",\n" . $tree_indent . " " . "qtip: '$qtip_string'"; } } else if ($is_group_parent) { // グループレイヤの親の場合、id = name で関連付けておく。 // でも子ノードから直接親を辿れるので今のところ意味が無い。 if ($cnt++ != 0) $g_def_layertree .= ",\n"; $g_def_layertree .= $tree_indent . " " . "id: " . phpObj2jsCode($mapdata->{"name"}); } else if ($is_group_layer) { // グループレイヤの子の場合、xlayer-<レイヤ名> を id にする。 // 逆を言うと、xlayer- で始まる id だったらグループレイヤの子。 if ($cnt++ != 0) $g_def_layertree .= ",\n"; $layer_list = "xlayer-"; $__idx = 0; foreach ($treeinfo->{"layerNames"} as $layer) { $tokens = preg_split("/:/", $layer); if ($__idx++ == 0) $layer_list .= $tokens[1]; else $layer_list .= "," . $tokens[1]; } $g_def_layertree .= $tree_indent . " " . "id: " . phpObj2jsCode($layer_list); if ($ewv_option[enableLegend]) { $g_def_layertree .= ",\n" . $tree_indent . " " . "qtip: '$qtip_string'"; } } if ($is_base_layer) { $g_def_layertree .= ",\n" . $tree_indent . " " . "isBaseLayer: true"; } /* traverse children */ if ($is_folder || $is_group_parent) { $g_def_layertree .= ",\n" . $tree_indent . " children: [\n"; $cnt = 1; foreach($treeinfo->{"children"} as $child) { if ($cnt++ != 1) $g_def_layertree .= ",\n"; $result = traverseTree($child, $tree_indent." ", $inherit_class); if ($result == false) return false; } $g_def_layertree .= "\n" . $tree_indent . " ]"; } $g_def_layertree .= "\n" . $tree_indent . "}"; return true; } function var_dump_html($object) { print("
\n");
    var_dump($object);
    print("
\n"); } function createJS($wmstree) { global $ewv_option; global $global_js_var_id; global $generated_js; global $g_def_layermap; global $g_def_layertree; global $g_def_global, $g_def_map, $g_def_control, $g_def_toolbar, $g_def_viewport; $global_js_var_id = 1; generate_js_parts(); /* making javascript string from JSON. */ $g_def_layermap = ""; $g_def_layertree = ""; $cnt = 1; foreach($wmstree as $wmsnode) { if ($cnt++ != 1) $g_def_layertree .= ",\n"; $result = traverseTree($wmsnode, "", null); if ($result == false) { print("Error: invalid JSON structure.
\n"); return false; } } $g_def_layermap = preg_replace("/(\n+)/m", "$1 ", $g_def_layermap); $g_def_layertree = preg_replace("/(\n+)/m", "$1 ", $g_def_layertree); $js_ext_image = isset($image_url) ? "Ext.BLANK_IMAGE_URL = '$image_url';" : ""; $generated_js = << // common setting - Ext.js $js_ext_image Ext.namespace('basemap'); // common setting - OpneLayers OpenLayers.IMAGE_RELOAD_ATTEMPTS = 5; OpenLayers.Util.onImageLoadErrorColor = 'transparent'; OpenLayers.Animation.isNative = true; // start application basemap.app = function() { $g_def_global $g_def_map $g_def_control var createWmsLayer = function() { var maparray = new Array(); $g_def_layermap map.addLayers(maparray); LayerTree = [ $g_def_layertree ]; }; $g_def_viewport $g_def_toolbar return { init: function() { Ext.QuickTips.init(); createMap(); createWmsLayer(); addMapControls(); createToolbar(); createViewport(); Ext.get('loading').fadeOut({remove: true}); } }; }(); Ext.onReady(basemap.app.init, basemap.app); EOD; return true; } function printJS() { global $generated_js; print($generated_js); } ?>