openscales基于事件驅動,一般對地圖的操作應用openscales已經提供了基本的訪問框架和部件來支持不同的應用
ClickHandler處于event/mouse包內,我們遇到要處理點擊地圖捕捉Click,doubleClick,DropDrag時就會用到這個東東了
那很簡單,我們只需要new ClickHandler(map,false) , 設置幾個回調函數(click,doubleclick等等),最后調用這個handler.active =true即可
啟用這個handler了。
在地圖上用鼠標點擊即可測試了
注意到ClickHandler里面用到了一個Timer,覺得奇怪的
1 protected function mouseUp(evt:MouseEvent):void {
2 if (evt) {
3
4 this.map.removeEventListener(MouseEvent.MOUSE_MOVE,this.mouseMove);
5
6 if (this._downPixel != null) {
7 // It was not a drag, but was it a simple or a double click ?
8 // Just wait for a timer duration to know and call the right function.
9 this._upPixel = new Pixel(evt.currentTarget.mouseX, evt.currentTarget.mouseY);
10 this._ctrlKey = evt.ctrlKey;
11 this._shiftKey = evt.shiftKey;
12 this._clickNum++;
13 this._timer.start();
14 }
15 }
想了一下就明白了期間的用意,看看注釋,目的是為了推遲回調,防止回調處理繁忙阻塞交互界面