PHP & JavaScript Room :: 設置サンプル

実行結果



イベントハンドラ解除

ソース

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAvABrzCnRluKK0Cj97fTMThTNR7aHVSEFb0WbViWwc6F-_w9PjBSogZu_7UgOTbx25ka46X-fnGmyvw" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map, cEvent, dEvent;
function load() {
    if(GBrowserIsCompatible()){
        /* 地図インスタンス生成 */
        map=new GMap2(document.getElementById("map"));
        /* 中心地点 */
        map.setCenter(new GLatLng(35.665246,139.712319), 14);
        /* コントロール追加 */
        map.addControl(new GLargeMapControl()); /* コントロール大 */

        /* 地図をクリックした時 */
        cEvent=GEvent.addListener(map, "click", function(overlay, point){
            document.getElementById("res").value="クリックした地点の地理座標:"+point+"\n";
        });
        dEvent=GEvent.addDomListener(document.getElementById("gb"), "click", function(){
            document.getElementById("res").value="現在の地図の矩形領域:"+map.getBounds();
        });
    }
}
function fRemoveEvent(eObj){
    document.getElementById("res").value="";
    /* イベントハンドラ削除 */
    GEvent.removeListener(eObj);
}
window.onload=load;
window.unload=GUnload;
//]]>
</script>
<div id="map" style="width:425px;height:300px"><!-- 地図描画領域 --></div><br>
<form action="#">
    <p>
        <input type="button" id="gb" value="地図の矩形領域を取得" /><br>
        <textarea id="res" cols="64" rows="2" style="width:421px;">地図をクリックしてください</textarea>
    </p>
    <fieldset style="width:402px;">
        <legend>イベントハンドラ解除</legend>
        <input type="button" value="地図クリック)" onclick="fRemoveEvent(cEvent)" />
        <input type="button" value="「地図の矩形領域を取得」ボタンクリック" onclick="fRemoveEvent(dEvent)" />
    </fieldset>
</form>

polarized women