| 140 | // 宣告 PolarStereographicProjection 實作 interface GProjection 回傳 GPoint |
| 141 | PolarStereographicProjection.prototype = new GProjection(); |
| 142 | |
| 143 | // 重新實作 interface GProjection 的 fromLatLngToPixel(latlng, zoom) |
| 144 | PolarStereographicProjection.prototype.fromLatLngToPixel = function(latlng, zoom) { |
| 145 | var lat = Math.PI/180 * latlng.lat(); |
| 146 | var lon = Math.PI/180 * latlng.lng(); |
| 147 | var s1 = Math.cos(lat)/(1.0 + this.zvector * Math.sin(lat)); |
| 148 | var s2 = 256 / 2 * Math.pow(2,zoom); |
| 149 | var x = ( Math.sin(lon) * s1 + 1 ) * s2; |
| 150 | var y = ( this.zvector * Math.cos(lon) * s1 + 1 ) * s2; |
| 151 | return new GPoint(x,y); |
| 152 | }; |
| 153 | |
| 154 | // 重新實作 interface GProjection 的 fromPixelToLatLng(pixel, zoom, unbounded?) 回傳 GLatLng |
| 155 | PolarStereographicProjection.prototype.fromPixelToLatLng = function(pixel, zoom, unbounded) { |
| 156 | var s2 = 256 / 2 * Math.pow(2,zoom); |
| 157 | var x = pixel.x / s2 - 1; |
| 158 | var y = pixel.y / s2 - 1; |
| 159 | if ( x == 0 && y == 0 ) return new GLatLng(90,0); |
| 160 | var z = this.zvector * Math.min( 2.0 / ( x*x + y*y + 1 ) - 1.0, 1.0 ); |
| 161 | var lon = 180/Math.PI * Math.atan2( x, this.zvector * y ); |
| 162 | var lat = 180/Math.PI * Math.asin( z ); |
| 163 | return new GLatLng(lat,lon); |
| 164 | }; |
| 165 | |
| 166 | // 重新實作 interface GProjection 的 tileCheckRange(tile, zoom, tilesize) 回傳 Boolean |
| 167 | PolarStereographicProjection.prototype.tileCheckRange = function(tile, zoom, tilesize) { |
| 168 | if( zoom > this.zoomlevels ) return false; |
| 169 | else return true; |
| 170 | }; |
| 171 | |
| 172 | // 重新實作 interface GProjection 的 getWrapWidth(zoom) 回傳 Number (比例尺的數字) |
| 173 | PolarStereographicProjection.prototype.getWrapWidth = function(zoom) { |
| 174 | // Is there a better cross-platform way to represent Infinity here? |
| 175 | return 1E+100 * Math.pow(2,zoom); |
| 176 | }; |