1/* 2 leaflet.responsive.popup 1.0.0 3 (c) 20222 https://github.com/yafred 4*/ 5 6L.ResponsivePopup = L.Popup.extend({ 7 8 options: { 9 hasTip: true 10 /* 11 * Inherited from L.Popup 12 * 13 * - offset 14 * 15 * - autoPanPadding 16 * - autoPanPaddingTopLeft 17 * - autoPanPaddingBottomRight 18 */ 19 }, 20 21 /** 22 * Overrides https://github.com/Leaflet/Leaflet/blob/399ed2105220f10b79e69b57420597e03502e611/src/layer/Popup.js#L183 23 * This is to add hasTip option 24 */ 25 _initLayout: function () { 26 27 var prefix = 'leaflet-popup', 28 container = this._container = L.DomUtil.create('div', 29 prefix + ' ' + (this.options.className || '') + 30 ' leaflet-zoom-animated'); 31 32 var wrapper = this._wrapper = L.DomUtil.create('div', prefix + '-content-wrapper', container); 33 this._contentNode = L.DomUtil.create('div', prefix + '-content', wrapper); 34 35 L.DomEvent.disableClickPropagation(container); 36 L.DomEvent.disableScrollPropagation(this._contentNode); 37 L.DomEvent.on(container, 'contextmenu', L.DomEvent.stopPropagation); 38 39 this._tipContainer = L.DomUtil.create('div', prefix + '-tip-container', container); 40 if(!this.options.hasTip) { 41 this._tipContainer.style.visibility = 'hidden'; 42 } 43 this._tip = L.DomUtil.create('div', prefix + '-tip', this._tipContainer); 44 45 if (this.options.closeButton) { 46 var closeButton = this._closeButton = L.DomUtil.create('a', prefix + '-close-button', container); 47 closeButton.setAttribute('role', 'button'); // overrides the implicit role=link of <a> elements #7399 48 closeButton.setAttribute('aria-label', 'Close popup'); 49 closeButton.href = '#close'; 50 closeButton.innerHTML = '<span aria-hidden="true">×</span>'; 51 52 L.DomEvent.on(closeButton, 'click', function (ev) { 53 L.DomEvent.preventDefault(ev); 54 this.close(); 55 }, this); 56 } 57 }, 58 59 60 61 /** 62 * Overrides https://github.com/Leaflet/Leaflet/blob/v1.3.4/src/layer/DivOverlay.js#L178 63 */ 64 _updatePosition: function () { 65 66 if (!this._map) { return; } 67 68 var pos = this._map.latLngToLayerPoint(this._latlng), 69 basePoint = this._map.layerPointToContainerPoint(pos), 70 containerWidth = this._container.offsetWidth, 71 containerHeight = this._container.offsetHeight, 72 padding = L.point(this.options.autoPanPadding), 73 paddingTL = L.point(this.options.autoPanPaddingTopLeft || padding), 74 paddingBR = L.point(this.options.autoPanPaddingBottomRight || padding), 75 mapSize = this._map.getSize(), 76 anchor = this._getAnchor(), // popup anchor 77 offset = L.point(this.options.offset); // offset relative to anchor (option from L.DivOverlay. We only use absolute values). 78 79 // Leaflet default dimensions (should not be hard coded in the future) 80 var tipHeight = 11; //px 81 var tipWidth = 22; //px 82 var containerRadius = 12; //px 83 84 // Tweak offset to include tip dimensions 85 var offsetX = Math.abs(offset.x); 86 var offsetY = Math.abs(offset.y); 87 if(this.options.hasTip) { 88 offsetX += tipHeight; 89 offsetY += tipHeight; 90 91 // clear CSS 92 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-north'); 93 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-south'); 94 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-east'); 95 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-west'); 96 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-north-east'); 97 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-north-west'); 98 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-south-east'); 99 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-south-west'); 100 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-east-north'); 101 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-east-south'); 102 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-west-north'); 103 L.DomUtil.removeClass(this._container, 'leaflet-resp-popup-west-south'); 104 // this._container.style.display = 'initial'; // this does not work 105 } 106 107 // Where can we fit the popup ? 108 var canGoTop = true, 109 canGoBottom = true, 110 canGoLeft = true, 111 canGoRight = true, 112 containerPos = false; 113 114 if(basePoint.y + anchor.y - offsetY - containerHeight - Math.abs(paddingTL.y) < 0) { 115 canGoTop = false; 116 } 117 if(basePoint.y + anchor.y + offsetY + containerHeight + Math.abs(paddingBR.y) > mapSize.y) { 118 canGoBottom = false; 119 } 120 if(basePoint.x + anchor.x - offsetX - containerWidth - Math.abs(paddingTL.x) < 0) { 121 canGoLeft = false; 122 } 123 if(basePoint.x + anchor.x + offsetX + containerWidth + Math.abs(paddingBR.x) > mapSize.x) { 124 canGoRight = false; 125 } 126 127 // manage overflows 128 var subtractX = containerWidth / 2 - anchor.x, 129 subtractY = containerHeight / 2 - anchor.y; 130 131 if(canGoTop || canGoBottom) { 132 var containerLeft = basePoint.x + anchor.x - (containerWidth / 2); 133 var containerRight = basePoint.x + anchor.x + (containerWidth / 2); 134 if(containerLeft < Math.abs(paddingTL.x)) { // left overflow 135 subtractX = containerWidth / 2 - anchor.x - Math.abs(paddingTL.x) + containerLeft; 136 } 137 if(containerRight > mapSize.x - Math.abs(paddingBR.x)) { // right overflow 138 subtractX = containerWidth / 2 - anchor.x + containerRight - mapSize.x + Math.abs(paddingBR.x); 139 } 140 } 141 if(canGoLeft || canGoRight) { 142 var containerTop = basePoint.y + anchor.y - (containerHeight / 2); 143 var containerBottom = basePoint.y + anchor.y + (containerHeight / 2); 144 if(containerTop < Math.abs(paddingTL.y)) { // top overflow 145 subtractY = containerHeight / 2 - anchor.y - Math.abs(paddingTL.y) + containerTop; 146 } 147 if(containerBottom > mapSize.y - Math.abs(paddingBR.y)) { // bottom overflow 148 subtractY = containerHeight / 2 - anchor.y + containerBottom - mapSize.y + Math.abs(paddingBR.y); 149 } 150 } 151 152 // position the popup (order of preference is: top, left, bottom, right, centerOnMap) 153 if(canGoTop) { 154 containerPos = pos.subtract(L.point(subtractX, -anchor.y + containerHeight + offsetY, true)); 155 if(this.options.hasTip) { 156 if(basePoint.x + anchor.x < paddingTL.x + containerRadius + tipWidth/2) { 157 containerPos.x = pos.x + anchor.x; 158 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-north-east'); 159 this._tipContainer.style.top = containerHeight + 'px'; 160 this._tipContainer.style.left = '0px'; 161 } 162 else if(basePoint.x + anchor.x > mapSize.x - paddingBR.x - containerRadius - tipWidth/2) { 163 containerPos.x = pos.x + anchor.x - containerWidth; 164 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-north-west'); 165 this._tipContainer.style.top = containerHeight + 'px'; 166 this._tipContainer.style.left = containerWidth + 'px'; 167 } 168 else { 169 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-north'); 170 this._tipContainer.style.top = containerHeight + 'px'; 171 this._tipContainer.style.left = (pos.x + anchor.x - containerPos.x) + 'px'; 172 } 173 } 174 } 175 else if(canGoLeft) { 176 containerPos = pos.subtract(L.point(-anchor.x + containerWidth + offsetX, subtractY, true)); 177 if(this.options.hasTip) { 178 if(basePoint.y + anchor.y < paddingTL.y + containerRadius + tipWidth/2) { 179 containerPos.y = pos.y + anchor.y; 180 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-west-south'); 181 this._tipContainer.style.top = '0px'; 182 this._tipContainer.style.left = containerWidth + 'px'; 183 } 184 else if(basePoint.y + anchor.y > mapSize.y - paddingBR.y - containerRadius - tipWidth/2) { 185 containerPos.y = pos.y + anchor.y - containerHeight; 186 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-west-north'); 187 this._tipContainer.style.top = containerHeight + 'px'; 188 this._tipContainer.style.left = containerWidth + 'px'; 189 } 190 else { 191 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-west'); 192 this._tipContainer.style.top = (pos.y + anchor.y - containerPos.y) + 'px'; 193 this._tipContainer.style.left = containerWidth + 'px'; 194 } 195 } 196 } 197 else if(canGoBottom) { 198 containerPos = pos.subtract(L.point(subtractX, -anchor.y - offsetY, true)); 199 if(this.options.hasTip) { 200 if(basePoint.x + anchor.x < paddingTL.x + containerRadius + tipWidth/2) { 201 containerPos.x = pos.x + anchor.x; 202 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-south-east'); 203 this._tipContainer.style.top = '0px'; 204 this._tipContainer.style.left = '0px'; 205 } 206 else if(basePoint.x + anchor.x > mapSize.x - paddingBR.x - containerRadius - tipWidth/2) { 207 containerPos.x = pos.x + anchor.x - containerWidth; 208 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-south-west'); 209 this._tipContainer.style.top = '0px'; 210 this._tipContainer.style.left = containerWidth + 'px'; 211 } 212 else { 213 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-south'); 214 this._tipContainer.style.top = '0px'; 215 this._tipContainer.style.left = (pos.x + anchor.x - containerPos.x) + 'px'; 216 } 217 } 218 } 219 else if(canGoRight) { 220 containerPos = pos.subtract(L.point(-anchor.x - offsetX, subtractY, true)); 221 if(this.options.hasTip) { 222 if(basePoint.y + anchor.y < paddingTL.y + containerRadius + tipWidth/2) { 223 containerPos.y = pos.y + anchor.y; 224 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-east-south'); 225 this._tipContainer.style.top = '0px'; 226 this._tipContainer.style.left = '0px'; 227 } 228 else if(basePoint.y + anchor.y > mapSize.y - paddingBR.y - containerRadius - tipWidth/2) { 229 containerPos.y = pos.y + anchor.y - containerHeight; 230 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-east-north'); 231 this._tipContainer.style.top = containerHeight + 'px'; 232 this._tipContainer.style.left = '0px'; 233 } 234 else { 235 L.DomUtil.addClass(this._container, 'leaflet-resp-popup-east'); 236 this._tipContainer.style.top = (pos.y + anchor.y - containerPos.y) + 'px'; 237 this._tipContainer.style.left = '0px'; 238 } 239 } 240 } 241 else { 242 var pos = this._map.latLngToLayerPoint(this._map.getCenter()); 243 containerPos = pos.subtract(L.point(containerWidth / 2, containerHeight / 2)); 244 if(this.options.hasTip) { 245 // this._tipContainer.style.display = 'none'; // this does not work 246 } 247 } 248 249 250 // if point is not visible, just hide the popup 251 if(basePoint.x < 0 || basePoint.y < 0 || basePoint.x > mapSize.x || basePoint.y > mapSize.y) { 252 // this._container.style.display = 'none'; // this does not work 253 } 254 255 // if container is too big, just hide the popup 256 if(containerWidth - Math.abs(paddingTL.x) - Math.abs(paddingBR.x) > mapSize.x || containerHeight - Math.abs(paddingTL.y) - Math.abs(paddingBR.y) > mapSize.y) { 257 // this._container.style.display = 'none'; // this does not work 258 } 259 260 L.DomUtil.setPosition(this._container, containerPos); 261 } 262 263}); 264 265 266//Instantiates a `ResponsivePopup` object given an optional `options` object that describes its appearance and location and an optional `source` object that is used to tag the popup with a reference to the Layer to which it refers. 267L.responsivePopup = function (options, source) { 268 return new L.ResponsivePopup(options, source); 269};
270 271//Adds Angular support 272if( typeof exports === 'object' && typeof module !== 'undefined') { 273 exports.responsivePopup = L.responsivePopup; 274 exports.ResponsivePopup = L.ResponsivePopup; 275}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.