2009年11月29日日曜日

OpenLayers 34 すべてオーバレイの表示 - AllOberLays

OpenLayers Overlays Only Example(all-overlays.html)を参考に ベースマップのない地図の表示します。

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

コードの修正とちょっと解説します。

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>OpenLayers34 All Overlays</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>

<!-- All Overlay コード -->

<script type="text/javascript">
var map;
function init() {
// 東京都用 map の設定
map = new OpenLayers.Map('map', {
allOverlays: true, // ここ
projection: new OpenLayers.Projection("EPSG:2456"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
maxResolution: 'auto',
units: 'meters',
maxExtent: new OpenLayers.Bounds(-279000,1054000,-185000,1104000)
});

// ここまで
// give the features some style

var styles = new OpenLayers.StyleMap({
"default": {
strokeWidth: 2
},
"select": {
strokeColor: "#0099cc",
strokeWidth: 4
}
});

// add rules from the above lookup table

styles.addUniqueValueRules("default", "RP_TYPE", {
10: {strokeColor: "#000000", strokeWidth: 2},
12: {strokeColor: "#222222", strokeWidth: 2},
14: {strokeColor: "#444444", strokeWidth: 2},
16: {strokeColor: "#666666", strokeWidth: 2},
18: {strokeColor: "#888888", strokeWidth: 2},
19: {strokeColor: "#666666", strokeWidth: 1}
});

var vectors = new OpenLayers.Layer.Vector("Lines", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "ol27_line2.json", // 修正
format: new OpenLayers.Format.GeoJSON({
internalProjection: new OpenLayers.Projection("EPSG:2456"), // 追加
externalProjection: new OpenLayers.Projection("EPSG:4326") // 追加
})
}),
styleMap: styles
});

map.addLayer(vectors);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition()); // 追加
map.addControl(new OpenLayers.Control.ScaleLine()); // 追加
map.zoomToMaxExtent();

} // End of function init()
</script>
</head>

<!-- body 部分 -->

<body onload="init()">
<h1 id="title">OpenLayers Overlays Only Example</h1>
<p id="shortdesc">
Demonstrates a map with overlays only.
</p>
<div id="map" class="smallmap"></div>
<div id="docs">
To create a map that allows any draw order with all layer types
and lets you set the visibility of any layer independently, set
the allOverlays property on the map to true.
</div>
</body>
</html>

0 件のコメント: