()
| 64 | }); |
| 65 | } |
| 66 | _attachedToMap() { |
| 67 | // need the map to convert container points to LatLngs |
| 68 | this._map = this.parentElement._map; |
| 69 | var map = this.parentElement._map; |
| 70 | |
| 71 | // don't go through this if already done |
| 72 | if (!this._feature) { |
| 73 | // Scale this.coords if the this._map.poster exists because |
| 74 | // the img might have been scaled by CSS. |
| 75 | // compute the style properties to be applied to the feature |
| 76 | var options = this._styleToPathOptions(window.getComputedStyle(this)), |
| 77 | points = this.coords ? this._coordsToArray(this.coords) : null; |
| 78 | // scale points if the poster exists because responsive areas |
| 79 | if (points && this.parentElement.poster) { |
| 80 | var worig = this.parentElement.poster.width, |
| 81 | wresp = this.parentElement.width, |
| 82 | wadjstmnt = (worig - wresp) / 2, |
| 83 | horig = this.parentElement.poster.height, |
| 84 | hresp = this.parentElement.height, |
| 85 | hadjstmnt = (horig - hresp) / 2; |
| 86 | for (var i = 0; i < points.length; i++) { |
| 87 | points[i][0] = points[i][0] - wadjstmnt; |
| 88 | points[i][1] = points[i][1] - hadjstmnt; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | if (this.shape === 'circle') { |
| 93 | var pixelRadius = parseInt(this.coords.split(',')[2]), |
| 94 | pointOnCirc = point(points[0]).add(point(0, pixelRadius)), |
| 95 | latLngOnCirc = map.containerPointToLatLng(pointOnCirc), |
| 96 | latLngCenter = map.containerPointToLatLng(points[0]), |
| 97 | radiusInMeters = map.distance(latLngCenter, latLngOnCirc); |
| 98 | this._feature = circle(latLngCenter, radiusInMeters, options).addTo( |
| 99 | map |
| 100 | ); |
| 101 | } else if (!this.shape || this.shape === 'rect') { |
| 102 | var bnds = latLngBounds( |
| 103 | map.containerPointToLatLng(points[0]), |
| 104 | map.containerPointToLatLng(points[1]) |
| 105 | ); |
| 106 | this._feature = rectangle(bnds, options).addTo(map); |
| 107 | } else if (this.shape === 'poly') { |
| 108 | this._feature = polygon(this._pointsToLatLngs(points), options).addTo( |
| 109 | map |
| 110 | ); |
| 111 | } else { |
| 112 | // whole initial area of map is a hyperlink |
| 113 | this._feature = rectangle(map.getBounds(), options).addTo(map); |
| 114 | } |
| 115 | if (this.alt) { |
| 116 | // other Leaflet features are implemented via SVG. SVG displays tooltips |
| 117 | // based on the <svg:title> graphics child element. |
| 118 | var title = SVG.create('title'), |
| 119 | titleText = document.createTextNode(this.alt); |
| 120 | title.appendChild(titleText); |
| 121 | this._feature._path.appendChild(title); |
| 122 | } |
| 123 | if (this.href) { |
no test coverage detected