ラベル Map Context の投稿を表示しています。 すべての投稿を表示
ラベル Map Context の投稿を表示しています。 すべての投稿を表示

2009年12月15日火曜日

OpenLayers 40h WMC - OpenLayers で Map Context を試す5 HTML の全体のコード

HTML の全体のコードは次のようになります。

openlayers40_wmc.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OpenLayers40 WMC</title>
<link rel="stylesheet" href="./theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="./examples/style.css" type="text/css" />

<!-- Map Context ドキュメントの出力欄のスタイル -->
<style type="text/css">
#wmc {
width: 90%;
height: 300px;
}
</style>

<!-- OpenLayers ライブラリ -->
<script src="./lib/Firebug/firebug.js"></script>
<script src="./lib/OpenLayers.js"></script>

<!-- Proj4js ライブラリ -->
<script type="text/javascript" src="./lib/proj4js/lib/proj4js-compressed.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/projCode/tmerc.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/defs/EPSG2456.js"></script>

<!-- WMC のコード -->

<script type="text/javascript">
// no pink please
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 2;
OpenLayers.Util.onImageLoadErrorColor = "transparent";

var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
var map, options; // 修正

function init() {
// 東京都用 map の設定
options = {
projection: new OpenLayers.Projection("EPSG:2456"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 'auto',
units: 'meters',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000)
};
map = new OpenLayers.Map("map", options);

// ここまで
// 東京都のレイヤの追加

layer1 = new OpenLayers.Layer.WMS( "Tokyo Height WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img.map',
layers: 'height',
format: 'image/png'
});
layer2 = new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
});
layer3 = new OpenLayers.Layer.WMS( "Tokyo Gyoseikai mlit WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_pf_pgis.map',
layers: 'gyoseikai',
transparent: true,
format: 'image/png'
});
map.addLayers([layer1, layer2, layer3]);
// ここまで
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition()); // 追加
map.addControl(new OpenLayers.Control.ScaleLine()); // 追加
// map.setCenter(new OpenLayers.LonLat(-95, 34.5), 1);
map.zoomToMaxExtent();
} End of functin init()

// WMC Read

function readWMC(merge) {
var text = document.getElementById("wmc").value;

if(merge) {
try {
map = format.read(text, {map: map});
} catch(err) {
document.getElementById("wmc").value = err;
}
} else {
map.destroy();
try {
// map = format.read(text, {map: "map"});
map = format.read(text, {map: new OpenLayers.Map("map", options)});
map.addControl(new OpenLayers.Control.LayerSwitcher());
} catch(err) {
document.getElementById("wmc").value = err;
}
}
}

// WMC Write

function writeWMC(merge) {
try {
var text = format.write(map);
document.getElementById("wmc").value = text;
} catch(err) {
document.getElementById("wmc").value = err;
}
}

</script>
</head>

<!-- body 部分 -->

<body onload="init()">
<h1 id="title">WMC Example</h1>
<div id="tags"></div>
<p id="shortdesc">
Shows parsing of Web Map Context documents.
</p>
<div id="map" class="smallmap"></div>
<button onclick="writeWMC();">write</button>
<button onclick="readWMC();">read as new map</button>
<button onclick="readWMC(true);">read and merge</button>
<textarea id="wmc">paste WMC doc here</textarea>
<div id="docs">
This is an example of parsing WMC documents. <br />
The format class has a layerOptions property, which can be used
to control the default options of the layer when it is created
by the parser.
</div>
</body>
</html>

2009年12月13日日曜日

OpenLayers 40f WMC - OpenLayers で Map Context を試す3 地図の表示のテスト1 Merge

wmc.html のコードを単純にして、地図を表示するためにいろいろ試してみました。
HTMLファイル全体のコードを次のようにしました。

openlayers40_wmc2.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OpenLayers40 WMC 2</title>
<link rel="stylesheet" href="./theme/default/style.css" type="text/css" />
<link rel="stylesheet" href="./examples/style.css" type="text/css" />

<!-- OpenLayers ライブラリ -->
<script src="./lib/Firebug/firebug.js"></script>
<script src="./lib/OpenLayers.js"></script>

<!-- Proj4js ライブラリ -->
<script type="text/javascript" src="./lib/proj4js/lib/proj4js-compressed.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/projCode/tmerc.js"></script>
<script type="text/javascript" src="./lib/proj4js/lib/defs/EPSG2456.js"></script>

<!-- WMC のコード -->

<script type="text/javascript">
// no pink please
OpenLayers.IMAGE_RELOAD_ATTEMPTS = 2;
OpenLayers.Util.onImageLoadErrorColor = "transparent";

var format = new OpenLayers.Format.WMC({'layerOptions': {buffer: 0}});
var map, options; // 修正

function init() {
// 東京都用 map の設定
options = {
projection: new OpenLayers.Projection("EPSG:2456"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 'auto',
units: 'meters',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000)
};
map = new OpenLayers.Map("map", options);

// ここまで

// 出力した Map Context にマップファイルのディレクトリを追加して保存
var url = "./tokyo_map_context_ol.xml";
// tokyo_map_context_ol.xml をファイルを読み込み
OpenLayers.loadURL(url, null, null, loadSuccess);

} End of functin init()

// 読み込みが成功したときの処理
function loadSuccess(request){
var wmc_doc = request.responseText;
// map.destroy();
// map = format.read(wmc_doc, {map: new OpenLayers.Map("map", options)});
map = format.read(wmc_doc, {map: map});
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition()); // 追加
map.addControl(new OpenLayers.Control.ScaleLine()); // 追加
map.zoomToMaxExtent();
}

</script>
</head>
<body onload="init()">
<h1 id="title">OpenLayers Tokyo Map Context</h1>
<div id="map" class="smallmap"></div>
</body>
</html>

wmc.html の「read and merge」のボタンをクリックしたとき、次のコードが実行されます。

map = format.read(wmc_doc, {map: map});

動作は、元の地図上に Map Context で設定された地図が合併(merge)されます。
この単純なコードの openlayers40_wmc2.html ファイルでも Map Context に設定された地図(だけ)表示されます。



次回は、New Map の動作

2009年12月12日土曜日

OpenLayers 40e WMC - OpenLayers で Map Context を試す2 地図の表示

「read as new map」ボタンをクリックするとタイルの区切りだけ表示されます。
(次のコードで画像が表示されないときのタイルは透明になります。
OpenLayers.Util.onImageLoadErrorColor = "transparent";)
レイヤ自体は設定できているようです。



再読み込みして「write」ボタン、「read and merge」ボタンの順にクリックします。
元の地図の上にタイルの区切りだけ表示されます。
レイヤ自体は設定できているようです。



MapServer と OpenLayers の Map Context を比較すると、OpenLayers の方の <OnlineResource> の xlink:href のリンクにマップファイルのディレクトリの指定がないので次のように修正しました。

height、kukaku レイヤ

<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.1.6/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map"/>

gyoseikai レイヤ

<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.1.6/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map"/>


再び、「read as new map」ボタンをクリックすると地図が表示されます。
しかし、拡大された地図が表示されます。



再読み込みして「write」ボタン、「read and merge」ボタンの順にクリックします。
地図が表示されます。

2009年12月10日木曜日

OpenLayers 40d WMC - OpenLayers で Map Context を試す1 Map Cntext ドキュメントの出力

OpenLayers.Format.WMC は、WMC ドキュメントの読み書きに使用します。

HTML ファイルを新規作成します。
「openlayersTokyoproj」 を右クリックして 新規 -> HTML ファイル をクリック。
「HTML ファイル」ウィンドウの「ファイル名(任意:openlayers_wmc.html)」に入力して「完了」ボタンをクリック。
「charset」を「utf-8」にします。
「examples」の「wmc.html」の内容をコピーして新規作成したファイルに貼り付けます。

map と layer 部分を次のように修正して、「write」ボタンをクリックすると WMC ドキュメントを表示します。

---
function init() {
var options = {
projection: new OpenLayers.Projection("EPSG:2456"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 183.593750,
units: 'meters',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000)
};
map = new OpenLayers.Map("map", options);

layer1 = new OpenLayers.Layer.WMS( "Tokyo Height WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img.map',
layers: 'height',
format: 'image/png'
});
layer2 = new OpenLayers.Layer.WMS( "Tokyo Kukaku Sen WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_bmi_pgis_img2.map',
layers: 'kukaku',
transparent: true,
format: 'image/png'
});
layer3 = new OpenLayers.Layer.WMS( "Tokyo Gyoseikai mlit WMS",
"http://192.168.1.6/cgi-bin/mapserv?",
{
map: '/home/user/mapfile/tokyo_pf_pgis.map',
layers: 'gyoseikai',
transparent: true,
format: 'image/png'
});
map.addLayers([layer1, layer2, layer3]);
---

出力した WMC ドキュメント

<ViewContext xmlns="http://www.opengis.net/context" version="1.1.0" id="OpenLayers_Context_188" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<General>
<Window width="512" height="256"/>
<BoundingBox minx="-279000.0000" miny="1055500.000" maxx="-185000.0000" maxy="1102500.000" SRS="EPSG:2456"/>
<Title/>
<Extension>
<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-279000.0000" miny="1054000.000" maxx="-185000.0000" maxy="1104000.000"/>
</Extension>
</General>
<LayerList>
<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1">
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.1.6/cgi-bin/mapserv?"/>
</Server>
<Name>height</Name>
<Title>Tokyo Height WMS</Title>
<FormatList>
<Format current="1">image/png</Format>
</FormatList>
<StyleList>
<Style current="1">
<Name/>
<Title>Default</Title>
</Style>
</StyleList>
<Extension>
<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-279000.0000" miny="1054000.000" maxx="-185000.0000" maxy="1104000.000"/>
<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">16</ol:numZoomLevels>
<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>
<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">true</ol:isBaseLayer>
<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>
<ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile>
</Extension>
</Layer>


<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1">
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.1.6/cgi-bin/mapserv?"/>
</Server>
<Name>kukaku</Name>
<Title>Tokyo Kukaku Sen WMS</Title>
<FormatList>
<Format current="1">image/png</Format>
</FormatList>
<StyleList>
<Style current="1">
<Name/>
<Title>Default</Title>
</Style>
</StyleList>
<Extension>
<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-279000.0000" miny="1054000.000" maxx="-185000.0000" maxy="1104000.000"/>
<ol:transparent xmlns:ol="http://openlayers.org/context">true</ol:transparent>
<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">16</ol:numZoomLevels>
<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>
<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer>
<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>
<ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile>
</Extension>
</Layer>


<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1">
<OnlineResource xlink:type="simple" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://192.168.1.6/cgi-bin/mapserv?"/>
</Server>
<Name>gyoseikai</Name>
<Title>Tokyo Gyoseikai mlit WMS</Title>
<FormatList>
<Format current="1">image/png</Format>
</FormatList>
<StyleList>
<Style current="1">
<Name/>
<Title>Default</Title>
</Style>
</StyleList>
<Extension>
<ol:maxExtent xmlns:ol="http://openlayers.org/context" minx="-279000.0000" miny="1054000.000" maxx="-185000.0000" maxy="1104000.000"/>
<ol:transparent xmlns:ol="http://openlayers.org/context">true</ol:transparent>
<ol:numZoomLevels xmlns:ol="http://openlayers.org/context">16</ol:numZoomLevels>
<ol:units xmlns:ol="http://openlayers.org/context">m</ol:units>
<ol:isBaseLayer xmlns:ol="http://openlayers.org/context">false</ol:isBaseLayer>
<ol:displayInLayerSwitcher xmlns:ol="http://openlayers.org/context">true</ol:displayInLayerSwitcher>
<ol:singleTile xmlns:ol="http://openlayers.org/context">false</ol:singleTile>
</Extension>
</Layer>
</LayerList>
</ViewContext>

2009年12月9日水曜日

OpenLayers 40c WMC - MapServer で Map Context を試す3 デフォルトマップファイルと地図の表示

MapServer CGI で地図を表示するために、デフォルトのマップファイルを作成します。

tokyo_context_default.map

MAP
NAME tokyo_context_default_map
STATUS ON
SIZE 600 300
EXTENT -279000 1054000 -185000 1104000
UNITS METERS
IMAGECOLOR 255 255 255
IMAGETYPE png
#
# Start of web interface definition
#
WEB
# MINSCALE 2000000
# MAXSCALE 50000000
#
# On Windows systems, /tmp and /tmp/ms_tmp/ should be created at the root
# of the drive where the .MAP file resides.
#
IMAGEPATH "/home/user/ka-map/htdocs/tmp/ms_tmp/"
IMAGEURL "/ms_tmp/"
END
END # Map File


ウェッブブラウザのアドレス欄に次のように入力しました。

http://localhost/cgi-bin/mapserv?MODE=map&MAP=/home/user/mapfile/tokyo_context_default.map&CONTEXT=/home/user/mapfile/tokyo_map_context.xml&LAYERS=kukaku

次のようにエラーが表示されたので

msBuildWMSLayerURLBase(): WMS connection error. At least wms_format or wms_formatlist is required for layer kukaku. Please either provide a valid CONNECTION URL, or provide those values in the layer's metadata.

tokyo_bmi_pgis_img.map の該当レイヤと tokyo_wms.map の各レイヤの Metadata に "wms_format" "image/png" を追加しました。
再びウェッブブラウザのアドレス欄に次のように入力して、結果をtokyo_map_context.xml に保存します。

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_wms.map&service=WMS&request=GetContext&version=1.1.0

Map Context ドキュメントを使って地図を表示します。
ウェッブブラウザのアドレス欄に次のように入力しました。

http://localhost/cgi-bin/mapserv?MODE=map&MAP=/home/user/mapfile/tokyo_context_default.map&CONTEXT=/home/user/mapfile/tokyo_map_context.xml&LAYERS=kukaku

画像が表示されたので次のように3つのレイヤを表示しました。

http://localhost/cgi-bin/mapserv?MODE=map&MAP=/home/user/mapfile/tokyo_context_default.map&CONTEXT=/home/user/mapfile/tokyo_map_context.xml&LAYERS=height kukaku gyoseikai

2009年12月8日火曜日

OpenLayers 40b WMC - MapServer で Map Context を試す2 Map Context ドキュメント

OpenLayers 40b WMC - MapServer で Map Context を試す2 Map Context ドキュメント

ブラウザには次のように表示されるので、tokyo_map_context.xml というファイル名で保存します。

<ViewContext version="1.1.0" id="tokyo_wms_map" xsi:schemaLocation="http://www.opengis.net/context http://schemas.opengis.net/context/1.1.0/context.xsd">
<General>
<Window width="600" height="300"/>
<!--
Bounding box corners and spatial reference system
-->
<BoundingBox SRS="EPSG:2456" minx="-279000.000000" miny="1054000.000000" maxx="-185000.000000" maxy="1104000.000000"/>
<!-- Title of Context -->
<Title>Tokyo WMS</Title>
<ContactInformation>
</ContactInformation>
</General>
<LayerList>
<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1" title="Context Hight">
<OnlineResource xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map"/>
</Server>
<Name>height</Name>
<Title>Context Hight</Title>
</Layer>
<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1" title="Context Kukaku">
<OnlineResource xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map"/>
</Server>
<Name>kukaku</Name>
<Title>Context Kukaku</Title>
</Layer>
<Layer queryable="0" hidden="0">
<Server service="OGC:WMS" version="1.1.1" title="Context Gyoseikai">
<OnlineResource xlink:type="simple" xlink:href="http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map"/>
</Server>
<Name>gyoseikai</Name>
<Title>Context Gyoseikai</Title>
</Layer>
</LayerList>
</ViewContext>

2009年12月7日月曜日

OpenLayers 40a WMC - MapServer で Map Context を試す1 マップファイル

WMC Example(wmc.html)を参考に Web Map Context を試してみます。

MapServer ホームページの

Map Context サイト
http://mapserver.org/ogc/mapcontext.html

を参考にマップサーバで試してみます。
Map Context は、WMS の情報が保存されている XML フォーマットのファイルです。

最初に、Map Context のデータを取得するためのマップファイルを作成します。
Required (必須)の Metadata を設定して、ウェッブブラウザのアドレス欄に次のように入力しました。

http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_wms.map&service=WMS&request=GetContext&version=1.1.0

次の警告が表示されたので、マップファイルを下記のように設定しました。


1. WARNING: Mandatory data 'projection' was missing in this context.
2. WARNING: Mandatory metadata 'wms_server_version' was missing in this context.
3. WARNING: Mandatory metadata 'wms_name' was missing in this context.

tokyo_wms.map


MAP
NAME tokyo_wms_map
STATUS ON
SIZE 600 300
EXTENT -279000 1054000 -185000 1104000
UNITS meters
IMAGECOLOR 255 255 255
IMAGETYPE png
FONTSET "fonts.txt"

PROJECTION # 1
"init=epsg:2456" #
END #


WEB
METADATA
"wms_title" "Tokyo WMS"
"wms_getcontext_enabled" "1" # WMS を経由して Map Context を取得するため追加
END
END


LAYER
NAME height
TYPE RASTER
STATUS ON
CONNECTIONTYPE WMS
CONNECTION "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map"
METADATA
"wms_name" "height" #3
"wms_server_version" "1.1.1" #2
"wms_title" "Context Hight" # Required
"wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map" # Required
END
END # Layer


LAYER
NAME kukaku
TYPE LINE
STATUS ON
CONNECTIONTYPE WMS
CONNECTION "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map"
METADATA
"wms_name" "kukaku" #3
"wms_server_version" "1.1.1" #2
"wms_title" "Context Kukaku" # Required
"wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_bmi_pgis_img.map" # Required
END
END # Layer


LAYER
NAME gyoseikai
TYPE LINE
STATUS ON
CONNECTIONTYPE WMS
CONNECTION "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map"
METADATA
"wms_name" "gyoseikai" #3
"wms_server_version" "1.1.1" #2
"wms_title" "Context Gyoseikai" # Required
"wms_onlineresource" "http://localhost/cgi-bin/mapserv?map=/home/user/mapfile/tokyo_pf_pgis.map" # Required
END
END # Layer

END # Map