簡體   English   中英

使用OpenLayers在地圖區域上創建Box控件

[英]Creating a Box Control over an area of the map with OpenLayers

我正在使用OpenLayers在我的程序中創建一個感興趣的框。 我正在使用此代碼:

var control = new OpenLayers.Control();
OpenLayers.Util.extend(control, {
    draw: function () {
        this.box = new OpenLayers.Handler.Box( control,
            {"done": this.notice},
            {keyMask: OpenLayers.Handler.MOD_SHIFT});
        this.box.activate();
    },
    notice: function (bounds) {
        areaSelected(bounds);
    }
});
map.addControl(control);

捕獲“ Shift Create a Box” 控件並使用選擇的區域作為我感興趣的區域。 但是,這些值以像素形式返回。 但是我想要經度和緯度 ,而不是像素。 鼠標位置控件確實顯示正確的long&lat。 我真的不在乎如何創建框,我只想為用戶提供一種選擇地圖區域的簡單方法,並且我需要獲取該區域的經緯度。 (盒子,圓圈,沒關系)

檢出: http : //garmin.na1400.info/routable.php

它有一個復選框來設置“啟用磁貼選擇”進行設置。

現在,當您在地圖上拖動一個框時,它將選擇基礎對象。

您可以重用源代碼。 所有的魔力都在: http//garmin.na1400.info/routable.js

回復很晚,但是我以后會幫助別人!

我設法通過執行以下操作從像素獲取小數度:

var point1 = new OpenLayers.Pixel(bounds.left, bounds.bottom);
var point2 = new OpenLayers.Pixel(bounds.right, bounds.top);

var ll1 = map.getLonLatFromPixel(point1);
var ll2 = map.getLonLatFromPixel(point2);

將其放在您的通知函數中,您將在ll1和ll2中擁有經/緯度對!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM