Lea*_*ode 22 google-maps overlay google-maps-api-3
我希望有人能指出我正确的方向.
我有一个谷歌地图加载XML文件中的标记,以及其他各种地图元素,效果很好.但是我现在需要将PNG图像叠加到地图上.
我已经尝试了几个小时来正确地将PNG对准网站的顶部但是却找不到我需要的两个坐标(西南和东北).有没有这样做的工具?理想情况下上传图像并拖动角落以适应,它会输出您需要的两个坐标(lat/lng)?
我尝试过使用这个工具:http://overlay-tiler.googlecode.com/svn/trunk/upload.html - 但它有三个联系点.
我也尝试过使用这个工具:http://www.birdtheme.org/useful/customoverlay.html - 但是一旦上传到地图就无法调整图像大小,你有机会点击西南标记!
我也可以使用Google Earth完美地对齐PNG,但我看不到输出lat/lng点的方法.
任何建议将不胜感激.
Rob*_*bin 25
下面是AndréDion解释的一个实例.
var overlay;
DebugOverlay.prototype = new google.maps.OverlayView();
function initialize() {
var mapOptions = {
zoom: 15,
center: new google.maps.LatLng(40.743388,-74.007592)
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var swBound = new google.maps.LatLng(40.73660837340877, -74.01852328);
var neBound = new google.maps.LatLng(40.75214181, -73.99661518216243);
var bounds = new google.maps.LatLngBounds(swBound, neBound);
console.log(map);
var srcImage = 'http://robincwillis.com/top/splash/04.jpg';
overlay = new DebugOverlay(bounds, srcImage, map);
var markerA = new google.maps.Marker({
position: swBound,
map: map,
draggable:true
});
var markerB = new google.maps.Marker({
position: neBound,
map: map,
draggable:true
});
google.maps.event.addListener(markerA,'drag',function(){
var newPointA = markerA.getPosition();
var newPointB = markerB.getPosition();
var newBounds = new google.maps.LatLngBounds(newPointA, newPointB);
overlay.updateBounds(newBounds);
});
google.maps.event.addListener(markerB,'drag',function(){
var newPointA = markerA.getPosition();
var newPointB = markerB.getPosition();
var newBounds = new google.maps.LatLngBounds(newPointA, newPointB);
overlay.updateBounds(newBounds);
});
google.maps.event.addListener(markerA, 'dragend', function () {
var newPointA = markerA.getPosition();
var newPointB = markerB.getPosition();
console.log("point1"+ newPointA);
console.log("point2"+ newPointB);
});
google.maps.event.addListener(markerB, 'dragend', function () {
var newPointA = markerA.getPosition();
var newPointB = markerB.getPosition();
console.log("point1"+ newPointA);
console.log("point2"+ newPointB);
});
}
function DebugOverlay(bounds, image, map) {
this.bounds_ = bounds;
this.image_ = image;
this.map_ = map;
this.div_ = null;
this.setMap(map);
}
DebugOverlay.prototype.onAdd = function() {
var div = document.createElement('div');
div.style.borderStyle = 'none';
div.style.borderWidth = '0px';
div.style.position = 'absolute';
var img = document.createElement('img');
img.src = this.image_;
img.style.width = '100%';
img.style.height = '100%';
img.style.opacity = '0.5';
img.style.position = 'absolute';
div.appendChild(img);
this.div_ = div;
var panes = this.getPanes();
panes.overlayLayer.appendChild(div);
};
DebugOverlay.prototype.draw = function() {
var overlayProjection = this.getProjection();
var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());
var div = this.div_;
div.style.left = sw.x + 'px';
div.style.top = ne.y + 'px';
div.style.width = (ne.x - sw.x) + 'px';
div.style.height = (sw.y - ne.y) + 'px';
};
DebugOverlay.prototype.updateBounds = function(bounds){
this.bounds_ = bounds;
this.draw();
};
DebugOverlay.prototype.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
this.div_ = null;
};
initialize();
Run Code Online (Sandbox Code Playgroud)
不久前我不得不为客户解决这个问题.我的解决方案是简单地创建两个标记; 每个一个LatLng用于叠加层LatLngBounds,当移动时,将更新叠加层并记录LatLndBounds给console我以供参考.我还添加了在拖动标记时显示的标线(垂直和水平线),因此更容易在视觉上定位叠加层.
我无法与您共享解决方案中的代码,但它涉及使用a OverlayView来转换LatLng坐标与像素之间的坐标MapCanvasProjection.
和你一样,我们最终用户不需要这个功能,所以我添加了一个"创作模式",通过为debug解决方案的查询字符串提供参数来切换.
| 归档时间: |
|
| 查看次数: |
27565 次 |
| 最近记录: |