2011-08-29 135 views
0

Goog day!谷歌地圖APi3:折線段沒有出現在地圖上

我有一個非常簡單的谷歌地圖的實現,它允許我的用戶在地圖畫布的任何地方繪製多段線。

當重新開始時,折線段在地圖上可見,折線存儲在使用PHP的mySql數據庫中。

//當編輯與折線的地圖:

如果用戶決定改變折線,我從數據庫裝載以前的折線,這是對用戶可見。當他們點擊按鈕繪製多段線時,它將清除地圖上的前一個多段線,並允許它們重新開始,但是,一旦它們開始在地圖上點擊,新的多段線段在地圖上不可見,但是正確保存到數據庫。

這裏是我到目前爲止已經完成:

var map; 
var polyline = null; 
var polylinePath = null; 

// HERE I INITIALIZE MY MAP ETC ETC ... 
// IN EDIT MODE I ALLOW THE FOLLOWING FUNCTION TO BE CALLED FIRST TO LOAD ANY EXISITNG POLYLINES FOR THE USER 
// THIS WORKS FINE, IT SHOWS THE PREVIOUS POLYLINE ON THE MAP. 
function loadBasePolylines($mapGuid) 
     { 
      var loadUrl = 'classes/Ajax_System.php'; 
      $.getJSON(loadUrl+"?action=loadMapPolylines&mapId="+mapGuid, function(json) { 
       if(json[0]['hasPolylines'] == 'yes'){ 

        var polylinesArray = []; 
        var prepath = polylinePath; 
        if(prepath){ 
         prepath.setMap(null); 
        } 
        var points = json[0].Points; 
        for (i=0; i<points.length; i++) { 
         polylinesArray.push(new google.maps.LatLng(points[i].lat,points[i].lon)); 
         bounds.extend(new google.maps.LatLng(points[i].lat,points[i].lon)); 
        } 
        polyline = new google.maps.Polyline({ 
         strokeColor: json[0]['lineColour'], 
         strokeOpacity: 0.5, 
         strokeWeight: json[0]['lineThickness'], 
         clickable: false, 
         path: polylinesArray 
        }); 

        polylinePath = polyline.getPath(); 
        polyline.setMap(map);       
        map.fitBounds(bounds); 
       } 
      }); 
     } 

// WHEN THE USER PRESS THE "DRAW PATH" BUTTON, THE FOLLOWING FUNCTION IN QUESTION IS CALLED: 
function startPolyline() 
     { 
      if(polyline != null){ 
       var answer = confirm("This will clear the current polyline from the map. Are you sure you want to continue?"); 
       if(answer){ 
        polyline.setMap(null); 
        if (tempMarkers) { 
         for (i in tempMarkers) { 
          tempMarkers[i].setMap(null); 
         } 
         tempMarkers.length = 0; 
        } 
       } else { 
        return; 
       } 
      } 
      var polyOptions = { 
       strokeColor: polylineColor, 
       strokeOpacity: polyLineOpacity, 
       strokeWeight: polyLineWidth, 
       clickable: false 
      } 
      polyline = new google.maps.Polyline(polyOptions); 
      polyline.setMap(map); 

      // Add a listener for the click event 
      google.maps.event.addListener(map, 'click', addPolylinePoint); 
     } 

     function addPolylinePoint(event) 
     { 
      var path = polyline.getPath(); 
      path.push(event.latLng); 
      var marker = new google.maps.Marker({ 
       position: event.latLng, 
       title: '#' + path.getLength(), 
       icon: '<?php echo URL; ?>public/mapIcons/mm_20_red.png', 
       map: map 
      }); 
      tempMarkers.push(marker); 
     } 

我試過到目前爲止:

  1. 檢查顏色代碼是在正確的格式:是
  2. 檢查緯度Lon order and values:是的

任何幫助將真誠地被讚賞。先謝謝你。

回答

1

哇,我已經解決了消失折線問題,通過我的問題重讀。希望這將有助於有人出來第一天:

在我的代碼,我從數據庫中加載的折線:

function loadBasePolylines($mapGuid) 
    { 
. 
. 
. 

polyline = new google.maps.Polyline({ 
        strokeColor: json[0]['lineColour'], 
        strokeOpacity: 0.5, 
        strokeWeight: json[0]['lineThickness'], 
        clickable: false, 
        path: polylinesArray 
       }); 

} 

我的行程不透明度設置爲0.5(等於50%)的權利......

然而,正當我在...

function startPolyline() 

var polyOptions = { 
      strokeColor: polylineColor, 
      strokeOpacity: polyLineOpacity, 
      strokeWeight: polyLineWidth, 
      clickable: false 
     } 

開始折線工具......我不透明度設置爲所謂的polyLineOpacity未設定變量。

一旦我加入了全局變量和...

function loadBasePolylines($mapGuid) 
    { 
. 
. 
. 
strokeOpacity = json[0]['lineOpacity'] * 100; 

polyline = new google.maps.Polyline({ 
        strokeColor: json[0]['lineColour'], 
        strokeOpacity: strokeOpacity, 
        strokeWeight: json[0]['lineThickness'], 
        clickable: false, 
        path: polylinesArray 
       }); 

} 

應用的負載值...用正確的不透明度的折線再次顯示正確!

我把這個開發者叫做腦凍結。 Tkx!

0

嘗試重新開始在地圖變量在startPolyline功能

map = new google.maps.Map(document.getElementById('id of your map')): 
+0

謝謝,但是,重新啓動地圖變量會返回灰色地圖區域,並且不會聽取點擊事件。再次設置地圖選項也無濟於事。 – ALPHp