2013-05-03 88 views
15

我希望有人能指引我走向正確的方向。谷歌地圖工具準確定位圖像疊加?

我有一個從XML文件加載標記的Google Map,以及其他各種地圖元素,效果很好。不過,我現在需要將PNG圖像疊加到地圖上。

我已經嘗試了幾個小時來正確對齊網站頂部的PNG,但是找不到我需要的確切兩個座標(西南和東北)。有沒有一個工具可以做到這一點?理想情況下,上傳圖片並拖動角落以適應,並輸出您需要的兩個座標(lat/lng)?

我試過使用這個工具:http://overlay-tiler.googlecode.com/svn/trunk/upload.html - 但它有三個接觸點。

我也嘗試過使用這個工具:http://www.birdtheme.org/useful/customoverlay.html - 但是一旦上傳到地圖就不能調整圖片大小,點擊西南地圖就有機會!

我也可以使用谷歌地球完美對齊PNG,但我看不到輸出經緯度的方法。

任何意見將不勝感激。

+0

目前尚不清楚,上傳/拖拽能力是否用於開發目的或最終用戶功能? – 2013-07-03 04:43:55

+0

@ Beetroot-Beetroot我認爲它是一次性的最終用戶功能,比如將圖片對齊一次,然後保存所需的數據,並在每次旋轉或縮放時顯示圖像 – 2013-07-04 12:23:16

+0

「使用Google地球調整PNG完美,但我看不出輸出經緯度的方法。「我相信你輸出爲KML,並從中提取數字。請參閱Keyhole標記語言地面疊加層教程:https://developers.google.com/kml/documentation/kml_tut?hl = it – ToolmakerSteve 2014-09-17 05:32:34

回答

7

不久前,我不得不爲客戶解決這個確切的問題。我的解決方案是簡單地創建兩個標記;其中每個LatLng覆蓋的LatLngBounds,移動時,將更新覆蓋並記錄LatLndBoundsconsole供我參考。我還添加了在拖動標記時顯示的網格線(垂直線和水平線),以便更容易在視覺上定位疊加層。

我無法與您共享解決方案中的代碼,但它涉及使用OverlayView進行工作,以便通過MapCanvasProjectionLatLng座標轉換爲像素以及從像素轉換像素。

像你一樣,我們不需要終端用戶的這個功能,所以我添加了一個「創作模式」,通過爲解決方案的查詢字符串提供debug參數來切換。

+0

是的,我也有一種模式,只有當用戶有足夠的權限執行時纔會觸發一次動作 所以挑選你的大腦一點點 您創建左下標記 然後用戶添加右上標記 用戶看到圖像是3/10/20度關閉,所以他們拖動左下角標記向上,然後在此之後您只需重新繪製圖像 – 2013-07-08 07:09:02

+1

通過移動NE或SW標記,可以扭曲圖像疊加層。我忘記提到,作爲先決條件,用於疊加的圖像需要與地圖處於相同的方向(即圖像的頂部爲北)。 – 2013-07-08 19:12:14

+0

你可能是建立[appnotmap上的thannmap](http://thannmap.appspot.com/)的同一個人嗎? 您是否也必須在此解決方案中執行多少Trig? 我也想知道構建這個解決方案是否類似於[google/overlays#CustomOverlays](https://developers.google.com/maps/documentation/javascript/overlays#CustomOverlays)解決方案?你可以用你的用戶指定的標記符號替換左側/右上角的硬編碼合作伙伴嗎? – 2013-07-09 07:49:26

2

試試這個工具。只需雙擊第一點上的地圖。一個可調整大小的矩形框將出現。將其跨度到終點,並獲取所需的LatLngBounds。

jsfiddle.net/yV6xv/16/embedded/result/ 

http://jsfiddle.net/yV6xv/16/embedded/result/

+0

這是一個非常酷的小工具,用於視覺化Overlay,但它不提供旋轉,有時您可能會看到覆蓋層可能是3/4度 – 2013-07-08 07:01:25

15

繼承人是AndréDion的解釋的實例。

http://jsfiddle.net/4cWCW/3/

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(); 
+0

Finnaly我在找什麼!但是OSM和Google地圖之間的座標有所不同...我需要與OSM一樣的.. – Weedoze 2016-08-04 12:36:05