how to make a Custom Overlays draggable using google-maps v3

廉价感情. 提交于 2019-12-09 13:54:19

问题


the marker can drag , so the Custom Overlays can drag too ,

so how to make the Custom Overlays draggable ,

thanks


回答1:


I recently put together a solution on a similar thread that applies greatly to this question as well:

Here is the other Stack Overflow Thread Showing how to create a custom overlay in V3 with a draggable object

Here is the working example: http://www.johnmick.net/drag-div-v3/

Here is some of the source: http://www.johnmick.net/drag-div-v3/js/main.js

To make the Custom Overlay itself draggable, using jQuery UI, you would just make the div object of the overlay draggable like:

    CustomOverlay.prototype.onAdd = function()
    {
        var div = document.createElement("DIV");
        div.style.border = "none";
        div.style.borderWidth = "0px";
        div.style.position = "absolute";
        div.style.visibility = "visible";
        jQuery(div).draggable();   //Make the overlay itself draggable
        this.div = div;
        this.addPolygon(new google.maps.LatLng(46,0));
        this.getPanes().overlayLayer.appendChild(div);
    };



回答2:


If you are using a custom "OverlayView" I found that adding your draggable objects the "overlayMouseTarget" pane will allow you to capture mouse events on that object and for example use jQuery UI to and apply draggable() to an object.



来源:https://stackoverflow.com/questions/3662955/how-to-make-a-custom-overlays-draggable-using-google-maps-v3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!