2009年3月18日水曜日

OpenLayers 18a Shift+Click で座標表示

Custom Control Point Example(custom-control-point.html) Shift+Click で座標表示
を参考に座標表示させます。

次のコードを追加します。

---
// ここから追加
var control = new OpenLayers.Control();
OpenLayers.Util.extend(control, {
draw: function () {
// this Handler.Point will intercept the shift-mousedown
// before Control.MouseDefault gets to see it
this.point = new OpenLayers.Handler.Point(
control,
{"done": this.notice},
{keyMask: OpenLayers.Handler.MOD_SHIFT}
);
this.point.activate();
},

notice: function (bounds) {
document.getElementById('bounds').innerHTML = bounds;
}
});

map.addControl(control);
// ここまで

} // End of function init()
---
</script>
</head>
<body onload="init()">
<h1 id="title">Display Data1</h1>
<div id="layerswitcher" style="position:absolute; z-index:1;"></div>
<div id="map"></div>
<div id="paneldiv" class="olControlNavToolbar"></div>
<!-- ここを追加 -->
<div id="bounds" style="margin-left:50px;"></div><br />
<!-- ここまで -->
---

地図上を Shift + クリック で地図のしたに座標が表示されます。

0 件のコメント: