marker
  • google-visualization
  • 2012-11-16 109 views 2 likes 
    2

    我正在使用google geochart在地圖上放置標記。我希望能夠動態添加和刪除地圖上的標記,而不必每次都重繪地圖。有沒有辦法做到這一點?在Google可視化地圖上動態添加標記

    感謝 這裏是我的代碼:

    <div align="center"> 
        <div id="chart_div"> 
        <div id="loadingDiv"></div> 
        </div> 
    </div> 
    
    <script type='text/javascript' src='https://www.google.com/jsapi'></script> 
    <script type="text/javascript"> 
        //Load the Google Maps stuff 
        google.load('visualization', '1', {'packages': ['geochart']}); 
        google.setOnLoadCallback(drawRegionsMap); 
    
        //Load the Google Maps stuff 
        google.load('visualization', '1', {'packages': ['geochart']}); 
        google.setOnLoadCallback(drawRegionsMap); 
    
    
        function drawRegionsMap() { 
        var data = new google.visualization.DataTable(); 
        data.addColumn('number', 'latitude'); 
        data.addColumn('number', 'longitude'); 
        data.addColumn('string', 'Location'); 
        data.addColumn('number', 'Size'); 
    
        //While iterating thru clients flag if user is in list, If not flagged add user to map. 
        //Firefox doesn't seem to be including user in list 
        var inList = false; 
        for (i in clientInfo){ client = clientInfo[i]; 
    
         //Because new clients are creating with this connection, we don't want to add them to map. 
         //Their clientInfo won't have an ipAddress. Only want to map one client per session 
         if (client.ipAddress){ 
         //Flag if user is in client list 
         if(client.ipAddress == userInfo.ipAddress){ 
          inList = true; 
         } 
         data.addRow([parseFloat(client.latitude), parseFloat(client.longitude), client.cityName, 4]); 
         } 
        } 
    
        //If user is not in client list add him now. 
        if(!inList){ 
         if(userInfo.ipAddress){ 
         data.addRow([parseFloat(userInfo.latitude), parseFloat(userInfo.longitude), userInfo.cityName, 4]); 
         } 
        } 
    
    
        var options = { 
         displayMode: 'markers', 
         colorAxis: {colors: ['red', 'blue']}, 
         sizeAxis: {minValue: 0, maxValue: 5, minSize: 1, maxSize: 4}, 
         enableRegionInteractivity: true, 
         legend: 'none' 
        }; 
    
        var chart = new google.visualization.GeoChart(document.getElementById('chart_div')); 
        google.visualization.events.addListener(chart, 'regionClick', function (eventData) { 
         alert('You clicked: ' + eventData.region); 
        }); 
        chart.draw(data, options); 
        } 
    </script> 
    

    回答

    0

    您可以創建一個dashboard和控件綁定到它 - 例如CategoryFilter。該圖表將在控件的過濾器被修改時自動更新。

    但是,這是有限的,考慮到您的用例,您可能必須自己調用繪圖函數。

    相關問題