0

v2に従ってスクリプトを編集しました。154行目に添付されているスクリプトの写真を使用すると、このエラーが発生します。

GEvent.addListener(window.polyline, 'click', function() {
                                    window.polyline.setOptions(options: { strokeColor: 'blue' });

v2に従ってスクリプトを編集しました。添付されているスクリプトの写真を使用すると、このエラーが発生します。実行中のアプリケーションをクリックして、アイコンとポリラインの色を変更するにはどうすればよいですか?私のコードは次のとおりです。エラーはありません。これどうやってするの?

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace GoogleMap
{
    // A sample project by Ghaffar khan

    public partial class Map : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataSet1TableAdapters.LocationsTableAdapter da = new GoogleMap.DataSet1TableAdapters.LocationsTableAdapter();
            DataSet1.LocationsDataTable table = new DataSet1.LocationsDataTable();
            da.Fill(table);
            BuildScript(table);
            //GooglePolyline PL1 = new GooglePolyline();

        }
        private void BuildScript(DataTable tbl)
        {
            String Locations = "";
            foreach (DataRow r in tbl.Rows)
            {
                // bypass empty rows        
                if (r["Latitude"].ToString().Trim().Length == 0)
                    continue;

                string Latitude = r["Latitude"].ToString();
                string Longitude = r["Longitude"].ToString();
                // create a line of JavaScript for marker on map for this record    
                Locations += Environment.NewLine + " map.addOverlay(new GMarker(new GLatLng(" + Latitude + "," + Longitude + ")));";

            }

            // construct the final script
            js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2); 
                                map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                " + Locations + @"
                                map.setUIToDefault();

// Create an array with points  
var points = [  
   new GLatLng(24.85229, 67.01703),  
   new GLatLng(24.914463, 67.0965958),  
   new GLatLng(24.86588, 67.06089),  
new GLatLng(24.9726753, 67.06638),
new GLatLng(24.840023, 67.24285),
new GLatLng(24.85229, 67.01703)
];  

// Create a new polyline  
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

// Add the polyline to the map using map.addOverlay()  
map.addOverlay(polyline);
var marker = new GMarker(new GLatLng(45.05,7.6667))  
// 

                              }
                            }


                            </script> ";
        }       

    }
}

////// GergLによると、スクリプトは///////

           js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                window.polyline = new GPolyline(points, '#ff0000', 5, 0.7); 
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2); 
                                map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                " + Locations + @"
                                map.setUIToDefault();
google.maps.event.addListener(window.polyline, 'click', function() {
    window.polyline.setOptions(options: { strokeColor: 'blue' });
});
// Create an array with points  
var points = [  
   new GLatLng(24.85229, 67.01703),  
   new GLatLng(24.914463, 67.0965958),  
   new GLatLng(24.86588, 67.06089),  
new GLatLng(24.9726753, 67.06638),
new GLatLng(24.840023, 67.24285),
new GLatLng(24.85229, 67.01703)
];  

// Create a new polyline  
var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

// Add the polyline to the map using map.addOverlay()  
map.addOverlay(polyline);                          
                              }
                            }
google.maps.event.addListener(window.polyline, 'click', function() {
    window.polyline.setOptions(options: { strokeColor: 'blue' });
});
                            </script> ";

しかし、エラーが発生しています.. .Objectスクリプトの47行目で、その行でclickメソッドを使用すると、あなたの助けを期待しています。

v2に従ってスクリプトを編集しました。添付されているスクリプトの写真を使用すると、このエラーが発生します。

4

1 に答える 1

1

polyline関数内の変数をinitialize()グローバルにアクセス可能な変数に割り当ててから、その変数のsetOptions()メソッドを使用して、クリックイベントハンドラー(javascript)で新しい色を設定する必要があります。

たとえば、これから行を変更した場合initialise()

var polyline = new GPolyline(points, '#ff0000', 5, 0.7);  

これに:

window.polyline = new GPolyline(points, '#ff0000', 5, 0.7); 

そして、クリックすると青に変わるようにしたい場合は、次のようなコードを追加します。

GEvent.addListener(window.polyline, 'click', function() {
    window.polyline.setOptions(options: { strokeColor: 'blue' });
});

ところで、私はこれをテストしていません。しかし、それはあなたが正しい軌道に乗るのを助けるはずです。

編集:スクリプトは次のようになります。
編集2:API v2で動作するように更新されましたが、GoogleはV2ドキュメントページV3ドキュメントページの両方で新しいV3に移行することを強くお勧めします。

js.Text = @"<script type='text/javascript'>
                            function initialize() {
                              if (GBrowserIsCompatible()) {
                                var map = new GMap2(document.getElementById('map_canvas'));
                                map.setCenter(new GLatLng(45.05,7.6667), 2);
                                map.openInfoWindowHtml ( new GLatLng(45.05,7.6667), 'Serif<br>Pakistan');
                                " + Locations + @"
                                map.setUIToDefault();
                                // Create an array with points  
                                var points = [  
                                   new GLatLng(24.85229, 67.01703),  
                                   new GLatLng(24.914463, 67.0965958),  
                                   new GLatLng(24.86588, 67.06089),  
                                   new GLatLng(24.9726753, 67.06638),
                                   new GLatLng(24.840023, 67.24285),
                                   new GLatLng(24.85229, 67.01703)
                                ];  

                                // Create a new polyline  
                                window.polyline = new GPolyline(points, '#ff0000', 5, 0.7);  
                                GEvent.addListener(window.polyline, 'click', function() {
                                    window.polyline.setOptions(options: { strokeColor: 'blue' });
                                });
                                // Add the polyline to the map using map.addOverlay()  
                                map.addOverlay(window.polyline);                          
                              }
                            }
                        </script> ";
于 2011-08-15T07:49:24.590 に答える