Jquery 如何使OpenLayers.Popup可拖动?

Jquery 如何使OpenLayers.Popup可拖动?,jquery,jquery-ui,popup,openlayers,Jquery,Jquery Ui,Popup,Openlayers,我使用了jquery ui拖动选项,如下所示,但一旦开始拖动,移动弹出窗口就无法结束。是否有其他方法使OpenLayers.Popup可拖动 popup = new OpenLayers.Popup.AnchoredBubble( "JInfo", // id

我使用了jquery ui拖动选项,如下所示,但一旦开始拖动,移动弹出窗口就无法结束。是否有其他方法使OpenLayers.Popup可拖动

popup = new OpenLayers.Popup.AnchoredBubble(
                                           "JInfo",                                                                // id
                                           jFeature.geometry.getBounds().getCenterLonLat(),  // lonlat
                                           new OpenLayers.Size(ISA.Size.POPUP_WIDTH, ISA.Size.POPUP_HEIGHT),
                                           html,                                           // contentHTML
                                           null,                                              // anchor
                                           true,                                             // closeBox
                                           function() {                                    // closeBoxCallback
                                                      jSelectControl.unselect(jFeature);
                                           });

                    jFeature.popup = popup;
                    map.addPopup(popup);

                    $("#JInfo").draggable();
谢谢你的帮助

Yasemin

查看我写的博客文章,并提供解决方案

/*
 * Move a popup with a drag.
 * 
 * @author Matt Walker
 * @class
 */
OpenLayers.Control.DragPopup = OpenLayers.Class(OpenLayers.Control, {
    down: false,
    popPnt: null,
    mapPnt: null,
    popup: null,
    docMouseUpProxy: null,
    /**
     * Constructor: OpenLayers.Control.DragPopup
     * Create a new control to drag a popup.
     *
     * Parameters:
     * @param {OpenLayers.Popup} popup
     * @param {Object} options
     */
    initialize: function(popup, options) {
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
        this.popup = popup;
        this.popup.events.register('mousedown', this, this.mouseDown);
        this.popup.events.register('mouseup', this, this.mouseUp);
        this.popup.events.register('mousemove', this, this.mouseMove);
        // Define a function bound to this used to listen for
        // document mouseout events
        this.docMouseUpProxy = OpenLayers.Function.bind(this.mouseUp, this);
    },

    /**
     * Method: setMap
     * Set the map property for the control.
     *
     * Parameters: 
     * map - {<OpenLayers.Map>} The controls map.
     */
    setMap: function(map) {
        OpenLayers.Control.prototype.setMap.apply(this, [map]);
        this.map.events.register('mousemove', this, this.mouseMove);
    },

    mouseDown: function(evt) {
        //console.log('mouseDown');
        this.down = true;
        this.popPnt = this.popup.events.getMousePosition(evt);
        OpenLayers.Event.observe(document, 'mouseup', this.docMouseUpProxy);
        OpenLayers.Event.stop(evt);
    },

    mouseUp: function(evt) {
        //console.log('mouseUp');
        this.down = false;
        OpenLayers.Event.stopObserving(document, 'mouseup', this.docMouseUpProxy);
        OpenLayers.Event.stop(evt);
    },

    mouseOut: function(evt) {
        //console.log('map.mouseOut');
        this.down = false;
        OpenLayers.Event.stop(evt);
    },

    mouseMove: function(evt) {
        //console.log('mouseMove');
        if (this.down) {
            var mapPntPx = this.map.events.getMousePosition(evt);
            mapPntPx = mapPntPx.add((this.popPnt.x*-1), (this.popPnt.y*-1));
            this.popup.lonlat = this.map.getLonLatFromViewPortPx(mapPntPx);
            this.popup.updatePosition();
        }
        OpenLayers.Event.stop(evt);
    },

    destroy: function() {
        // Remove listeners
        this.popup.events.unregister('mousedown', this, this.mouseDown);
        this.popup.events.unregister('mouseup', this, this.mouseUp);
        this.popup.events.unregister('mousemove', this, this.mouseMove);
        this.map.events.unregister('mousemove', this, this.mouseMove);
        // Clear object references
        this.popup = null;
        this.popPnt = null;
        // allow our superclass to tidy up
        OpenLayers.Control.prototype.destroy.apply(this, []);
    },

    /** @final @type String */
    CLASS_NAME: "OpenLayers.Control.DragPopup"
});
/*
*拖动鼠标移动弹出窗口。
* 
*@作者马特·沃克
*@级
*/
OpenLayers.Control.DragPopup=OpenLayers.Class(OpenLayers.Control{
唐:错,
popPnt:null,
mapPnt:null,
弹出窗口:空,
docMouseUpProxy:null,
/**
*构造函数:OpenLayers.Control.DragPopup
*创建新控件以拖动弹出窗口。
*
*参数:
*@param{OpenLayers.Popup}Popup
*@param{Object}选项
*/
初始化:功能(弹出窗口、选项){
OpenLayers.Control.prototype.initialize.apply(这个[options]);
this.popup=弹出;
this.popup.events.register('mousedown',this,this.mousedown);
this.popup.events.register('mouseup',this,this.mouseup);
this.popup.events.register('mousemove',this,this.mousemove);
//定义一个绑定到此函数的函数,用于侦听
//记录mouseout事件
this.docMouseUpProxy=OpenLayers.Function.bind(this.mouseUp,this);
},
/**
*方法:setMap
*设置控件的映射属性。
*
*参数:
*映射-{}控件映射。
*/
setMap:函数(map){
OpenLayers.Control.prototype.setMap.apply(这个[map]);
this.map.events.register('mousemove',this,this.mousemove);
},
mouseDown:函数(evt){
//console.log('mouseDown');
this.down=true;
this.popPnt=this.popup.events.getMousePosition(evt);
OpenLayers.Event.observe(文档'mouseup',this.docMouseUpProxy);
OpenLayers.Event.stop(evt);
},
mouseUp:函数(evt){
//console.log('mouseUp');
this.down=false;
OpenLayers.Event.stopObserving(文档'mouseup',this.docMouseUpProxy);
OpenLayers.Event.stop(evt);
},
mouseOut:函数(evt){
//console.log('map.mouseOut');
this.down=false;
OpenLayers.Event.stop(evt);
},
mouseMove:函数(evt){
//console.log('mouseMove');
如果(这个向下){
var mappnptpx=this.map.events.getMousePosition(evt);
mapPntPx=mapPntPx.add((this.popPnt.x*-1),(this.popPnt.y*-1));
this.popup.lonlat=this.map.getLonLatFromViewPortPx(mapPntPx);
this.popup.updatePosition();
}
OpenLayers.Event.stop(evt);
},
销毁:函数(){
//删除侦听器
取消注册('mousedown',this,this.mousedown);
this.popup.events.unregister('mouseup',this,this.mouseup);
取消注册('mousemove',this,this.mousemove);
取消注册('mousemove',this,this.mousemove);
//清除对象引用
this.popup=null;
this.popPnt=null;
//让我们的超类整理一下
OpenLayers.Control.prototype.destroy.apply(这个,[]);
},
/**@final@type字符串*/
类名:“OpenLayers.Control.DragPopup”
});
查看我写的带有解决方案的博客文章

/*
 * Move a popup with a drag.
 * 
 * @author Matt Walker
 * @class
 */
OpenLayers.Control.DragPopup = OpenLayers.Class(OpenLayers.Control, {
    down: false,
    popPnt: null,
    mapPnt: null,
    popup: null,
    docMouseUpProxy: null,
    /**
     * Constructor: OpenLayers.Control.DragPopup
     * Create a new control to drag a popup.
     *
     * Parameters:
     * @param {OpenLayers.Popup} popup
     * @param {Object} options
     */
    initialize: function(popup, options) {
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
        this.popup = popup;
        this.popup.events.register('mousedown', this, this.mouseDown);
        this.popup.events.register('mouseup', this, this.mouseUp);
        this.popup.events.register('mousemove', this, this.mouseMove);
        // Define a function bound to this used to listen for
        // document mouseout events
        this.docMouseUpProxy = OpenLayers.Function.bind(this.mouseUp, this);
    },

    /**
     * Method: setMap
     * Set the map property for the control.
     *
     * Parameters: 
     * map - {<OpenLayers.Map>} The controls map.
     */
    setMap: function(map) {
        OpenLayers.Control.prototype.setMap.apply(this, [map]);
        this.map.events.register('mousemove', this, this.mouseMove);
    },

    mouseDown: function(evt) {
        //console.log('mouseDown');
        this.down = true;
        this.popPnt = this.popup.events.getMousePosition(evt);
        OpenLayers.Event.observe(document, 'mouseup', this.docMouseUpProxy);
        OpenLayers.Event.stop(evt);
    },

    mouseUp: function(evt) {
        //console.log('mouseUp');
        this.down = false;
        OpenLayers.Event.stopObserving(document, 'mouseup', this.docMouseUpProxy);
        OpenLayers.Event.stop(evt);
    },

    mouseOut: function(evt) {
        //console.log('map.mouseOut');
        this.down = false;
        OpenLayers.Event.stop(evt);
    },

    mouseMove: function(evt) {
        //console.log('mouseMove');
        if (this.down) {
            var mapPntPx = this.map.events.getMousePosition(evt);
            mapPntPx = mapPntPx.add((this.popPnt.x*-1), (this.popPnt.y*-1));
            this.popup.lonlat = this.map.getLonLatFromViewPortPx(mapPntPx);
            this.popup.updatePosition();
        }
        OpenLayers.Event.stop(evt);
    },

    destroy: function() {
        // Remove listeners
        this.popup.events.unregister('mousedown', this, this.mouseDown);
        this.popup.events.unregister('mouseup', this, this.mouseUp);
        this.popup.events.unregister('mousemove', this, this.mouseMove);
        this.map.events.unregister('mousemove', this, this.mouseMove);
        // Clear object references
        this.popup = null;
        this.popPnt = null;
        // allow our superclass to tidy up
        OpenLayers.Control.prototype.destroy.apply(this, []);
    },

    /** @final @type String */
    CLASS_NAME: "OpenLayers.Control.DragPopup"
});
/*
*拖动鼠标移动弹出窗口。
* 
*@作者马特·沃克
*@级
*/
OpenLayers.Control.DragPopup=OpenLayers.Class(OpenLayers.Control{
唐:错,
popPnt:null,
mapPnt:null,
弹出窗口:空,
docMouseUpProxy:null,
/**
*构造函数:OpenLayers.Control.DragPopup
*创建新控件以拖动弹出窗口。
*
*参数:
*@param{OpenLayers.Popup}Popup
*@param{Object}选项
*/
初始化:功能(弹出窗口、选项){
OpenLayers.Control.prototype.initialize.apply(这个[options]);
this.popup=弹出;
this.popup.events.register('mousedown',this,this.mousedown);
this.popup.events.register('mouseup',this,this.mouseup);
this.popup.events.register('mousemove',this,this.mousemove);
//定义一个绑定到此函数的函数,用于侦听
//记录mouseout事件
this.docMouseUpProxy=OpenLayers.Function.bind(this.mouseUp,this);
},
/**
*方法:setMap
*设置控件的映射属性。
*
*参数:
*映射-{}控件映射。
*/
setMap:函数(map){
OpenLayers.Control.prototype.setMap.apply(这个[map]);
this.map.events.register('mousemove',this,this.mousemove);
},
mouseDown:函数(evt){
//console.log('mouseDown');
this.down=true;
this.popPnt=this.popup.events.getMousePosition(evt);
OpenLayers.Event.observe(文档'mouseup',this.docMouseUpProxy);
OpenLayers.Event.stop(evt);
},
mouseUp:函数(evt){
//console.log('mouseUp');
this.down=false;
OpenLayers.Event.stopObserving(文档'mouseup',this.docMouseUpProxy);
OpenLayers.Event.stop(evt);
},
mouseOut:函数(evt){
//console.log('map.mouseOut');
this.down=false;
OpenLayers.Event.stop(evt);
},
mouseMove:函数(evt){
//console.log('mouseMove');
如果(这个向下){
var mappnptpx=this.map.events.getMousePosition(evt);
mapPntPx=mapPntPx.add((this.popPnt.x*-1),(this.popPnt.y*-1));
this.popup.lonlat=this.map.getLonLatFromViewPortPx(mapPntPx);
this.popup.updatePosition();
}
OpenLayers.Event.stop(evt);
},
销毁:函数(){
//删除侦听器
取消注册('mousedown',this,this.mousedown);
this.popup.events.unregister('mouseup',this,this.mouseup);
取消注册('mousemove',this,this.mousemove);
this.map.events.unregister('mou