2010-07-30 38 views
2

我正在開發一個使用Google Maps API v3的應用程序。我想要製作定製的覆蓋圖,每邊都有1000km的正方形(每個覆蓋層實際上都是1000x1000的透明png,每個像素代表1平方公里)。我目前的實施是這樣的:如何轉換Google地圖中的自定義疊加圖以進行投影計算?

function PngOverlay(map,loc) { 
    this._png = null; 
    this._location = loc; //lat,lng of the square's center 
    this.setMap(map); 
} 

PngOverlay.prototype = new google.maps.OverlayView(); 

PngOverlay.prototype.onAdd = function() { 
    this._png = new Element('image',{ //using mootools 
    'src': pngForLoc(this._location), 
    'styles': { 
     'width': 1000, 
     'height': 1000,   
     'position': 'absolute' 
    } 
}); 

var panes = this.getPanes(); 
    panes.overlayLayer.appendChild(this._png); 
} 

PngOverlay.prototype.onRemove = function() { 
    this._png.parentNode.removeChild(this._png); 
    this._png = null; 
} 

PngOverlay.prototype.draw = function() { 
    var dp = this.getProjection().fromLatLngToDivPixel(this._location);  
    var ps = this._png.getSize(); 

    var t = dp.y - (ps.y/2); 
    this._png.setStyle('top',t); 

    var l = dp.x - (ps.x/2); 
    this._png.setStyle('left',l); 
} 

我的問題是:如果有什麼,我需要做什麼來說明谷歌地圖的投影?我對墨卡託的理解有限,是它保留了水平距離而不是垂直距離。我該如何適當地轉換()我的PNG來解釋這一點?

回答

0

沒有足夠的信息,但是您可能會發現開源proj4js庫很有用,因爲它可以執行各種投影轉換,例如。致Google的Spherical Mercator投影系統。

相關問題