![](/img/trans.png)
[英]Erratic overlay behavior with custom projection, Google Maps API v3
[英]How can I transform a custom overlay in Google Maps to account for projection?
我正在开发使用Google Maps API v3的应用程序。 我想制作自定义叠加层,每边的正方形恰好是1000km(每个叠加层实际上是1000x1000透明png,每个像素代表1平方千米)。 我当前的实现是这样的:
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);
}
我的问题是:如果需要考虑Google Maps的投影,我需要做什么? 我对墨卡托的有限理解是,它保留水平距离,但不保留垂直距离。 我如何适当地将我的png转换为()以解决这个问题?
确实没有足够的信息,但是您可能会发现开源proj4js库很有用,因为它可以执行各种投影转换,例如。 到Google的球形墨卡托投影系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.