From e5f23bcfd86dc9c8de876856e8cce923e434976a Mon Sep 17 00:00:00 2001 From: Jonas Liljegren Date: Tue, 24 May 2016 10:08:30 +0200 Subject: [PATCH 1/4] Updated closure compiler link to google_maps_api_v3.js --- src/richmarker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/richmarker.js b/src/richmarker.js index 2b4ef0c..4171b59 100755 --- a/src/richmarker.js +++ b/src/richmarker.js @@ -1,6 +1,6 @@ // ==ClosureCompiler== // @compilation_level ADVANCED_OPTIMIZATIONS -// @externs_url http://closure-compiler.googlecode.com/svn/trunk/contrib/externs/maps/google_maps_api_v3.js +// @externs_url https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/maps/google_maps_api_v3.js // @output_wrapper (function() {%output%})(); // ==/ClosureCompiler== From 0e28c718b7359c20b908c0e2ff15929e627820d1 Mon Sep 17 00:00:00 2001 From: Jonas Liljegren Date: Tue, 24 May 2016 14:44:17 +0200 Subject: [PATCH 2/4] Makes click on draggable objects work with Firefox (v38-v46), and keeps working with Chrome and IE. --- src/richmarker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/richmarker.js b/src/richmarker.js index 4171b59..eda56f6 100755 --- a/src/richmarker.js +++ b/src/richmarker.js @@ -612,7 +612,7 @@ RichMarker.prototype.addDragging_ = function(node) { RichMarker.prototype.addDraggingListeners_ = function() { var that = this; if (this.markerWrapper_.setCapture) { - this.markerWrapper_.setCapture(true); + this.markerWrapper_.setCapture(); this.draggingListeners_ = [ google.maps.event.addDomListener(this.markerWrapper_, 'mousemove', function(e) { that.drag(e); From 9e80206171585633a444e6632bc9a69da385cd88 Mon Sep 17 00:00:00 2001 From: Jonas Liljegren Date: Wed, 25 May 2016 15:21:08 +0200 Subject: [PATCH 3/4] Do not fire click event on dragging --- src/richmarker.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/src/richmarker.js b/src/richmarker.js index eda56f6..6897b96 100755 --- a/src/richmarker.js +++ b/src/richmarker.js @@ -238,9 +238,11 @@ RichMarker.prototype['setDraggable'] = RichMarker.prototype.setDraggable; RichMarker.prototype.draggable_changed = function() { if (this.ready_) { if (this.getDraggable()) { + this.removeNondraggingListeners_(); this.addDragging_(this.markerWrapper_); } else { this.removeDragListeners_(); + this.addNondraggingListeners_(); } } }; @@ -582,6 +584,19 @@ RichMarker.prototype.removeDragListeners_ = function() { this.setCursor_(''); }; +/** + * Removes nondragging listeners associated with the marker. + * + * @private + */ +RichMarker.prototype.removeNondraggingListeners_ = function() { + if (this.nondraggingListeners_) { + for (var i = 0, listener; listener = this.nondraggingListeners_[i]; i++) { + google.maps.event.removeListener(listener); + } + this.nondraggingListeners_.length = 0; + } +}; /** * Add dragability events to the marker. @@ -597,6 +612,8 @@ RichMarker.prototype.addDragging_ = function(node) { var that = this; this.draggableListener_ = google.maps.event.addDomListener(node, 'mousedown', function(e) { + that.mousedownX_ = e.clientX; + that.mousedownY_ = e.clientY; that.startDrag(e); }); @@ -635,6 +652,26 @@ RichMarker.prototype.addDraggingListeners_ = function() { }; +/** + * Add nondragging listeners. + * + * @private + */ +RichMarker.prototype.addNondraggingListeners_ = function() { + var that = this; + this.nondraggingListeners_ = [ + google.maps.event.addDomListener(this.markerWrapper_, 'mouseup', function(e) { + google.maps.event.trigger(that, 'mouseup', e); + }), + google.maps.event.addDomListener(this.markerWrapper_, 'mousedown', function(e) { + that.mousedownX_ = e.clientX; + that.mousedownY_ = e.clientY; + google.maps.event.trigger(that, 'mousedown', e); + }), + ]; +}; + + /** * Remove dragging listeners. * @@ -729,7 +766,10 @@ RichMarker.prototype.onAdd = function() { var that = this; google.maps.event.addDomListener(this.markerContent_, 'click', function(e) { - google.maps.event.trigger(that, 'click', e); + if( !that.mousedownX_ || ( Math.abs(that.mousedownX_ - e.clientX) < 4 && + Math.abs(that.mousedownY_ - e.clientY) < 4 )) { + google.maps.event.trigger(that, 'click', e); + } }); google.maps.event.addDomListener(this.markerContent_, 'mouseover', function(e) { google.maps.event.trigger(that, 'mouseover', e); From 6e9895d7c4756c232f1ef7afbf0ebd8e29c6c065 Mon Sep 17 00:00:00 2001 From: Jonas Liljegren Date: Tue, 31 May 2016 10:40:52 +0200 Subject: [PATCH 4/4] Added anchorOffset for markers of dynamic size, positioned with RichMarkerPosition and then moved a fixed number of pixels --- reference.html | 27 +++++++++++++++++++++++- src/richmarker-compiled.js | 42 ++++++++++++++++++++------------------ src/richmarker.js | 37 +++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 21 deletions(-) diff --git a/reference.html b/reference.html index 2f385cd..2f4ab85 100755 --- a/reference.html +++ b/reference.html @@ -129,6 +129,11 @@

Methods

None Anchor changed event. + + anchorOffset_changed() + None + AnchorOffset changed event. + content_changed() None @@ -159,6 +164,11 @@

Methods

google.maps.Size Gets the anchor. + + getAnchorOffset() + google.maps.Point + Gets the anchor offset. + getContent() string|Node @@ -222,7 +232,12 @@

Methods

setAnchor(anchor:RichMarkerPosition|google.maps.Size) None - Position changed event. + . + + + setAnchorOffset(google.maps.Point) + None + . setContent(content:string|Node) @@ -297,6 +312,11 @@

Events

None This event is fired when the anchor property changes. + + anchorOffset_changed + None + This event is fired when the anchorOffset property changes. + click Event @@ -322,6 +342,11 @@

Events

None This event is fired when the height property changes. + + offset_changed + None + This event is fired when the offset property changes. + position_changed None diff --git a/src/richmarker-compiled.js b/src/richmarker-compiled.js index 4cfef1d..9cbc3e7 100755 --- a/src/richmarker-compiled.js +++ b/src/richmarker-compiled.js @@ -1,20 +1,22 @@ -(function(){var b=true,f=false;function g(a){var c=a||{};this.d=this.c=f;if(a.visible==undefined)a.visible=b;if(a.shadow==undefined)a.shadow="7px -3px 5px rgba(88,88,88,0.7)";if(a.anchor==undefined)a.anchor=i.BOTTOM;this.setValues(c)}g.prototype=new google.maps.OverlayView;window.RichMarker=g;g.prototype.getVisible=function(){return this.get("visible")};g.prototype.getVisible=g.prototype.getVisible;g.prototype.setVisible=function(a){this.set("visible",a)};g.prototype.setVisible=g.prototype.setVisible; -g.prototype.s=function(){if(this.c){this.a.style.display=this.getVisible()?"":"none";this.draw()}};g.prototype.visible_changed=g.prototype.s;g.prototype.setFlat=function(a){this.set("flat",!!a)};g.prototype.setFlat=g.prototype.setFlat;g.prototype.getFlat=function(){return this.get("flat")};g.prototype.getFlat=g.prototype.getFlat;g.prototype.p=function(){return this.get("width")};g.prototype.getWidth=g.prototype.p;g.prototype.o=function(){return this.get("height")};g.prototype.getHeight=g.prototype.o; -g.prototype.setShadow=function(a){this.set("shadow",a);this.g()};g.prototype.setShadow=g.prototype.setShadow;g.prototype.getShadow=function(){return this.get("shadow")};g.prototype.getShadow=g.prototype.getShadow;g.prototype.g=function(){if(this.c)this.a.style.boxShadow=this.a.style.webkitBoxShadow=this.a.style.MozBoxShadow=this.getFlat()?"":this.getShadow()};g.prototype.flat_changed=g.prototype.g;g.prototype.setZIndex=function(a){this.set("zIndex",a)};g.prototype.setZIndex=g.prototype.setZIndex; -g.prototype.getZIndex=function(){return this.get("zIndex")};g.prototype.getZIndex=g.prototype.getZIndex;g.prototype.t=function(){if(this.getZIndex()&&this.c)this.a.style.zIndex=this.getZIndex()};g.prototype.zIndex_changed=g.prototype.t;g.prototype.getDraggable=function(){return this.get("draggable")};g.prototype.getDraggable=g.prototype.getDraggable;g.prototype.setDraggable=function(a){this.set("draggable",!!a)};g.prototype.setDraggable=g.prototype.setDraggable; -g.prototype.k=function(){if(this.c)this.getDraggable()?j(this,this.a):k(this)};g.prototype.draggable_changed=g.prototype.k;g.prototype.getPosition=function(){return this.get("position")};g.prototype.getPosition=g.prototype.getPosition;g.prototype.setPosition=function(a){this.set("position",a)};g.prototype.setPosition=g.prototype.setPosition;g.prototype.q=function(){this.draw()};g.prototype.position_changed=g.prototype.q;g.prototype.l=function(){return this.get("anchor")};g.prototype.getAnchor=g.prototype.l; -g.prototype.r=function(a){this.set("anchor",a)};g.prototype.setAnchor=g.prototype.r;g.prototype.n=function(){this.draw()};g.prototype.anchor_changed=g.prototype.n;function l(a,c){var d=document.createElement("DIV");d.innerHTML=c;if(d.childNodes.length==1)return d.removeChild(d.firstChild);else{for(var e=document.createDocumentFragment();d.firstChild;)e.appendChild(d.firstChild);return e}}function m(a,c){if(c)for(var d;d=c.firstChild;)c.removeChild(d)} -g.prototype.setContent=function(a){this.set("content",a)};g.prototype.setContent=g.prototype.setContent;g.prototype.getContent=function(){return this.get("content")};g.prototype.getContent=g.prototype.getContent; -g.prototype.j=function(){if(this.b){m(this,this.b);var a=this.getContent();if(a){if(typeof a=="string"){a=a.replace(/^\s*([\S\s]*)\b\s*$/,"$1");a=l(this,a)}this.b.appendChild(a);var c=this;a=this.b.getElementsByTagName("IMG");for(var d=0,e;e=a[d];d++){google.maps.event.addDomListener(e,"mousedown",function(h){if(c.getDraggable()){h.preventDefault&&h.preventDefault();h.returnValue=f}});google.maps.event.addDomListener(e,"load",function(){c.draw()})}google.maps.event.trigger(this,"domready")}this.c&& -this.draw()}};g.prototype.content_changed=g.prototype.j;function n(a,c){if(a.c){var d="";if(navigator.userAgent.indexOf("Gecko/")!==-1){if(c=="dragging")d="-moz-grabbing";if(c=="dragready")d="-moz-grab"}else if(c=="dragging"||c=="dragready")d="move";if(c=="draggable")d="pointer";if(a.a.style.cursor!=d)a.a.style.cursor=d}} -function o(a,c){if(a.getDraggable())if(!a.d){a.d=b;var d=a.getMap();a.m=d.get("draggable");d.set("draggable",f);a.h=c.clientX;a.i=c.clientY;n(a,"dragready");a.a.style.MozUserSelect="none";a.a.style.KhtmlUserSelect="none";a.a.style.WebkitUserSelect="none";a.a.unselectable="on";a.a.onselectstart=function(){return f};p(a);google.maps.event.trigger(a,"dragstart")}} -function q(a){if(a.getDraggable())if(a.d){a.d=f;a.getMap().set("draggable",a.m);a.h=a.i=a.m=null;a.a.style.MozUserSelect="";a.a.style.KhtmlUserSelect="";a.a.style.WebkitUserSelect="";a.a.unselectable="off";a.a.onselectstart=function(){};r(a);n(a,"draggable");google.maps.event.trigger(a,"dragend");a.draw()}} -function s(a,c){if(!a.getDraggable()||!a.d)q(a);else{var d=a.h-c.clientX,e=a.i-c.clientY;a.h=c.clientX;a.i=c.clientY;d=parseInt(a.a.style.left,10)-d;e=parseInt(a.a.style.top,10)-e;a.a.style.left=d+"px";a.a.style.top=e+"px";var h=t(a);a.setPosition(a.getProjection().fromDivPixelToLatLng(new google.maps.Point(d-h.width,e-h.height)));n(a,"dragging");google.maps.event.trigger(a,"drag")}}function k(a){if(a.f){google.maps.event.removeListener(a.f);delete a.f}n(a,"")} -function j(a,c){if(c){a.f=google.maps.event.addDomListener(c,"mousedown",function(d){o(a,d)});n(a,"draggable")}}function p(a){if(a.a.setCapture){a.a.setCapture(b);a.e=[google.maps.event.addDomListener(a.a,"mousemove",function(c){s(a,c)},b),google.maps.event.addDomListener(a.a,"mouseup",function(){q(a);a.a.releaseCapture()},b)]}else a.e=[google.maps.event.addDomListener(window,"mousemove",function(c){s(a,c)},b),google.maps.event.addDomListener(window,"mouseup",function(){q(a)},b)]} -function r(a){if(a.e){for(var c=0,d;d=a.e[c];c++)google.maps.event.removeListener(d);a.e.length=0}} -function t(a){var c=a.l();if(typeof c=="object")return c;var d=new google.maps.Size(0,0);if(!a.b)return d;var e=a.b.offsetWidth;a=a.b.offsetHeight;switch(c){case i.TOP:d.width=-e/2;break;case i.TOP_RIGHT:d.width=-e;break;case i.LEFT:d.height=-a/2;break;case i.MIDDLE:d.width=-e/2;d.height=-a/2;break;case i.RIGHT:d.width=-e;d.height=-a/2;break;case i.BOTTOM_LEFT:d.height=-a;break;case i.BOTTOM:d.width=-e/2;d.height=-a;break;case i.BOTTOM_RIGHT:d.width=-e;d.height=-a}return d} -g.prototype.onAdd=function(){if(!this.a){this.a=document.createElement("DIV");this.a.style.position="absolute"}if(this.getZIndex())this.a.style.zIndex=this.getZIndex();this.a.style.display=this.getVisible()?"":"none";if(!this.b){this.b=document.createElement("DIV");this.a.appendChild(this.b);var a=this;google.maps.event.addDomListener(this.b,"click",function(){google.maps.event.trigger(a,"click")});google.maps.event.addDomListener(this.b,"mouseover",function(){google.maps.event.trigger(a,"mouseover")}); -google.maps.event.addDomListener(this.b,"mouseout",function(){google.maps.event.trigger(a,"mouseout")})}this.c=b;this.j();this.g();this.k();var c=this.getPanes();c&&c.overlayImage.appendChild(this.a);google.maps.event.trigger(this,"ready")};g.prototype.onAdd=g.prototype.onAdd; -g.prototype.draw=function(){if(!(!this.c||this.d)){var a=this.getProjection();if(a){var c=this.get("position");a=a.fromLatLngToDivPixel(c);c=t(this);this.a.style.top=a.y+c.height+"px";this.a.style.left=a.x+c.width+"px";a=this.b.offsetHeight;c=this.b.offsetWidth;c!=this.get("width")&&this.set("width",c);a!=this.get("height")&&this.set("height",a)}}};g.prototype.draw=g.prototype.draw;g.prototype.onRemove=function(){this.a&&this.a.parentNode&&this.a.parentNode.removeChild(this.a);k(this)}; -g.prototype.onRemove=g.prototype.onRemove;var i={TOP_LEFT:1,TOP:2,TOP_RIGHT:3,LEFT:4,MIDDLE:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM:8,BOTTOM_RIGHT:9};window.RichMarkerPosition=i; -})(); +function b(a){var c=a||{};this.f=this.c=!1;void 0==a.visible&&(a.visible=!0);void 0==a.shadow&&(a.shadow="7px -3px 5px rgba(88,88,88,0.7)");void 0==a.anchor&&(a.anchor=f.BOTTOM);this.setValues(c)}b.prototype=new google.maps.OverlayView;window.RichMarker=b;b.prototype.getVisible=function(){return this.get("visible")};b.prototype.getVisible=b.prototype.getVisible;b.prototype.setVisible=function(a){this.set("visible",a)};b.prototype.setVisible=b.prototype.setVisible; +b.prototype.O=function(){this.c&&(this.a.style.display=this.getVisible()?"":"none",this.draw())};b.prototype.visible_changed=b.prototype.O;b.prototype.M=function(a){this.set("flat",!!a)};b.prototype.setFlat=b.prototype.M;b.prototype.A=function(){return this.get("flat")};b.prototype.getFlat=b.prototype.A;b.prototype.I=function(){return this.get("width")};b.prototype.getWidth=b.prototype.I;b.prototype.H=function(){return this.get("height")};b.prototype.getHeight=b.prototype.H; +b.prototype.N=function(a){this.set("shadow",a);this.i()};b.prototype.setShadow=b.prototype.N;b.prototype.B=function(){return this.get("shadow")};b.prototype.getShadow=b.prototype.B;b.prototype.i=function(){this.c&&(this.a.style.boxShadow=this.a.style.webkitBoxShadow=this.a.style.MozBoxShadow=this.A()?"":this.B())};b.prototype.flat_changed=b.prototype.i;b.prototype.setZIndex=function(a){this.set("zIndex",a)};b.prototype.setZIndex=b.prototype.setZIndex;b.prototype.getZIndex=function(){return this.get("zIndex")}; +b.prototype.getZIndex=b.prototype.getZIndex;b.prototype.P=function(){this.getZIndex()&&this.c&&(this.a.style.zIndex=this.getZIndex())};b.prototype.zIndex_changed=b.prototype.P;b.prototype.getDraggable=function(){return this.get("draggable")};b.prototype.getDraggable=b.prototype.getDraggable;b.prototype.setDraggable=function(a){this.set("draggable",!!a)};b.prototype.setDraggable=b.prototype.setDraggable; +b.prototype.u=function(){if(this.c)if(this.getDraggable()){if(this.o){for(var a=0,c;c=this.o[a];a++)google.maps.event.removeListener(c);this.o.length=0}h(this,this.a)}else k(this),l(this)};b.prototype.draggable_changed=b.prototype.u;b.prototype.getPosition=function(){return this.get("position")};b.prototype.getPosition=b.prototype.getPosition;b.prototype.setPosition=function(a){this.set("position",a)};b.prototype.setPosition=b.prototype.setPosition;b.prototype.J=function(){this.draw()}; +b.prototype.position_changed=b.prototype.J;b.prototype.v=function(){return this.get("anchor")};b.prototype.getAnchor=b.prototype.v;b.prototype.K=function(a){this.set("anchor",a)};b.prototype.setAnchor=b.prototype.K;b.prototype.G=function(){this.draw()};b.prototype.anchor_changed=b.prototype.G;b.prototype.w=function(){return this.get("anchorOffset")};b.prototype.getAnchorOffset=b.prototype.w;b.prototype.L=function(a){this.set("anchorOffset",a)};b.prototype.setAnchorOffset=b.prototype.L; +b.prototype.F=function(){this.draw()};b.prototype.anchorOffset_changed=b.prototype.F;function m(a){var c=document.createElement("DIV");c.innerHTML=a;if(1==c.childNodes.length)return c.removeChild(c.firstChild);for(a=document.createDocumentFragment();c.firstChild;)a.appendChild(c.firstChild);return a}function n(a){if(a)for(var c;c=a.firstChild;)a.removeChild(c)}b.prototype.setContent=function(a){this.set("content",a)};b.prototype.setContent=b.prototype.setContent;b.prototype.getContent=function(){return this.get("content")}; +b.prototype.getContent=b.prototype.getContent; +b.prototype.s=function(){if(this.b){n(this.b);var a=this.getContent();if(a){"string"==typeof a&&(a=a.replace(/^\s*([\S\s]*)\b\s*$/,"$1"),a=m(a));this.b.appendChild(a);for(var c=this,a=this.b.getElementsByTagName("IMG"),d=0,e;e=a[d];d++)google.maps.event.addDomListener(e,"mousedown",function(a){c.getDraggable()&&(a.preventDefault&&a.preventDefault(),a.returnValue=!1)}),google.maps.event.addDomListener(e,"load",function(){c.draw()});google.maps.event.trigger(this,"domready")}this.c&&this.draw()}}; +b.prototype.content_changed=b.prototype.s;function p(a,c){if(a.c){var d="";if(-1!==navigator.userAgent.indexOf("Gecko/"))"dragging"==c&&(d="-moz-grabbing"),"dragready"==c&&(d="-moz-grab");else if("dragging"==c||"dragready"==c)d="move";"draggable"==c&&(d="pointer");a.a.style.cursor!=d&&(a.a.style.cursor=d)}} +function q(a,c){if(a.getDraggable()&&!a.f){a.f=!0;var d=a.getMap();a.C=d.get("draggable");d.set("draggable",!1);a.j=c.clientX;a.l=c.clientY;p(a,"dragready");a.a.style.MozUserSelect="none";a.a.style.KhtmlUserSelect="none";a.a.style.WebkitUserSelect="none";a.a.unselectable="on";a.a.onselectstart=function(){return!1};r(a);google.maps.event.trigger(a,"dragstart")}} +function t(a){a.getDraggable()&&a.f&&(a.f=!1,a.getMap().set("draggable",a.C),a.j=a.l=a.C=null,a.a.style.MozUserSelect="",a.a.style.KhtmlUserSelect="",a.a.style.WebkitUserSelect="",a.a.unselectable="off",a.a.onselectstart=function(){},u(a),p(a,"draggable"),google.maps.event.trigger(a,"dragend"),a.draw())} +function v(a,c){if(a.getDraggable()&&a.f){var d=a.j-c.clientX,e=a.l-c.clientY;a.j=c.clientX;a.l=c.clientY;d=parseInt(a.a.style.left,10)-d;e=parseInt(a.a.style.top,10)-e;a.a.style.left=d+"px";a.a.style.top=e+"px";var g=w(a),d=new google.maps.Point(d-g.width,e-g.height);a.setPosition(a.getProjection().fromDivPixelToLatLng(d));p(a,"dragging");google.maps.event.trigger(a,"drag")}else t(a)}function k(a){a.h&&(google.maps.event.removeListener(a.h),delete a.h);p(a,"")} +function h(a,c){c&&(a.h=google.maps.event.addDomListener(c,"mousedown",function(c){a.m=c.clientX;a.D=c.clientY;q(a,c)}),p(a,"draggable"))} +function r(a){a.a.setCapture?(a.a.setCapture(),a.g=[google.maps.event.addDomListener(a.a,"mousemove",function(c){v(a,c)},!0),google.maps.event.addDomListener(a.a,"mouseup",function(){t(a);a.a.releaseCapture()},!0)]):a.g=[google.maps.event.addDomListener(window,"mousemove",function(c){v(a,c)},!0),google.maps.event.addDomListener(window,"mouseup",function(){t(a)},!0)]} +function l(a){a.o=[google.maps.event.addDomListener(a.a,"mouseup",function(c){google.maps.event.trigger(a,"mouseup",c)}),google.maps.event.addDomListener(a.a,"mousedown",function(c){a.m=c.clientX;a.D=c.clientY;google.maps.event.trigger(a,"mousedown",c)})]}function u(a){if(a.g){for(var c=0,d;d=a.g[c];c++)google.maps.event.removeListener(d);a.g.length=0}} +function w(a){var c=a.v();if("object"==typeof c)return c;var d=new google.maps.Size(0,0);if(!a.b)return d;var e=a.b.offsetWidth,g=a.b.offsetHeight;switch(c){case f.TOP:d.width=-e/2;break;case f.TOP_RIGHT:d.width=-e;break;case f.LEFT:d.height=-g/2;break;case f.MIDDLE:d.width=-e/2;d.height=-g/2;break;case f.RIGHT:d.width=-e;d.height=-g/2;break;case f.BOTTOM_LEFT:d.height=-g;break;case f.BOTTOM:d.width=-e/2;d.height=-g;break;case f.BOTTOM_RIGHT:d.width=-e,d.height=-g}if(a=a.w())d.width+=a.x,d.height+= +a.y;return d} +b.prototype.onAdd=function(){this.a||(this.a=document.createElement("DIV"),this.a.style.position="absolute");this.getZIndex()&&(this.a.style.zIndex=this.getZIndex());this.a.style.display=this.getVisible()?"":"none";if(!this.b){this.b=document.createElement("DIV");this.a.appendChild(this.b);var a=this;google.maps.event.addDomListener(this.b,"click",function(c){(!a.m||4>Math.abs(a.m-c.clientX)&&4>Math.abs(a.D-c.clientY))&&google.maps.event.trigger(a,"click",c)});google.maps.event.addDomListener(this.b,"mouseover", +function(c){google.maps.event.trigger(a,"mouseover",c)});google.maps.event.addDomListener(this.b,"mouseout",function(c){google.maps.event.trigger(a,"mouseout",c)})}this.c=!0;this.s();this.i();this.u();var c=this.getPanes();c&&c.overlayMouseTarget.appendChild(this.a);google.maps.event.trigger(this,"ready")};b.prototype.onAdd=b.prototype.onAdd; +b.prototype.draw=function(){if(this.c&&!this.f){var a=this.getProjection();if(a){var c=this.get("position"),a=a.fromLatLngToDivPixel(c),c=w(this);this.a.style.top=a.y+c.height+"px";this.a.style.left=a.x+c.width+"px";a=this.b.offsetHeight;c=this.b.offsetWidth;c!=this.get("width")&&this.set("width",c);a!=this.get("height")&&this.set("height",a)}}};b.prototype.draw=b.prototype.draw;b.prototype.onRemove=function(){this.a&&this.a.parentNode&&this.a.parentNode.removeChild(this.a);k(this)}; +b.prototype.onRemove=b.prototype.onRemove;var f={TOP_LEFT:1,TOP:2,TOP_RIGHT:3,LEFT:4,MIDDLE:5,RIGHT:6,BOTTOM_LEFT:7,BOTTOM:8,BOTTOM_RIGHT:9};window.RichMarkerPosition=f; diff --git a/src/richmarker.js b/src/richmarker.js index 6897b96..9b1c0d1 100755 --- a/src/richmarker.js +++ b/src/richmarker.js @@ -313,6 +313,37 @@ RichMarker.prototype.anchor_changed = function() { RichMarker.prototype['anchor_changed'] = RichMarker.prototype.anchor_changed; +/** + * Gets the anchor offset. + * + * @return {google.maps.Point} The offset of the anchor relative the position. + */ +RichMarker.prototype.getAnchorOffset = function() { + return /** @type {google.maps.Point} */ (this.get('anchorOffset')); +}; +RichMarker.prototype['getAnchorOffset'] = RichMarker.prototype.getAnchorOffset; + + +/** + * Sets the anchor offset. + * + * @param {google.maps.Point} offset The anchor offset to set. + */ +RichMarker.prototype.setAnchorOffset = function(anchorOffset) { + this.set('anchorOffset', anchorOffset); +}; +RichMarker.prototype['setAnchorOffset'] = RichMarker.prototype.setAnchorOffset; + + +/** + * Offset changed event. + */ +RichMarker.prototype.anchorOffset_changed = function() { + this.draw(); +}; +RichMarker.prototype['anchorOffset_changed'] = RichMarker.prototype.anchorOffset_changed; + + /** * Converts a HTML string to a document fragment. * @@ -740,6 +771,12 @@ RichMarker.prototype.getOffset_ = function() { break; } + var anchorOffset = this.getAnchorOffset(); + if( anchorOffset ) { + offset.width += anchorOffset.x; + offset.height += anchorOffset.y; + } + return offset; };