Google Fusion Map: Circle blocking layer click events, javascript - Stack Overflow

admin2025-04-10  1

The following code queries a Google fusion table based on a circular map region.

The center of the circular map region is determined by where a user clicks and the radius is determined by selection from a from a drop down menu. I have a listener set so that when a user clicks on a mapped point an info box es up displaying information from the corresponding fusion table row.

This all works fine until I add a circle to my map (to illustrate to the user what region they have selected), it seems that the presence of the circle is blocking the layer's click event listener. I've tried altering z-index to no avail. Could anyone please suggest a way around this issue?

function initialize() {     

        tableid = xxxxxxx;

              // Initialize the Google Map
        var map = new google.maps.Map(document.getElementById('map_canvas'), {
          center: new google.maps.LatLng(37.3, -122.3),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP   
                                                                               });                                                                        
        var layer = new google.maps.FusionTablesLayer({     
          query: {
            select: 'Address',
            from: tableid,
            where: 'ST_INTERSECTS(Address, CIRCLE(LATLNG(37.3, -122.3), 5000))'
                  }
                                                      });
        layer.setMap(map);
        layer.index = 1;
        map.index =2;
        var meters = 5000;
        var center = map.getCenter();

        // Update the radius when the user makes a selection.
        google.maps.event.addDomListener(document.getElementById('radius'), 'change', function() {  
          meters = parseInt(this.value, 10);
          circle.setRadius(meters);
          searchStr = 'ST_INTERSECTS(Address, ' +'CIRCLE(LATLNG'+center+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
            layer.setOptions({
              query: {
                select: 'Address',
                from: tableid,
                where: searchStr 
                      }
                              }); 
                                                                                                  });                                                                                                                                                                                                                                       //Update the filter when the user makes a selection.
        google.maps.event.addDomListener(document.getElementById('filter'),'change', function() {
          filterSelection = this.value;
          searchStr = 'ST_INTERSECTS(Address, ' + 'CIRCLE(LATLNG'+center+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
            layer.setOptions({
              query: {
                select: 'Address',
                from: tableid,
                where: searchStr
                      } 
                              });
                                                                                                    });  

        //Info Box Populate click handler
        google.maps.event.addListener(layer, 'click', function(e) {
          alert("Info Click");
          e.infoWindowHtml = e.row['Title'].value + "<br>";  
                                                                   });
        //Click Handler
        google.maps.event.addListener(map, 'click', function(e) {
          circle.setCenter(e.latLng);
          center = e.latLng;
          searchStr = 'ST_INTERSECTS(Address, ' + 'CIRCLE(LATLNG'+e.latLng+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
             layer.setOptions({
               query: {
                 select: 'Address',
                 from: tableid,
                 where: searchStr
                        }
                               });
                                                                   });    
        // Create a map circle object to visually show the radius.
        var circle = new google.maps.Circle({
          center: new google.maps.LatLng(37.3, -122.3),
          radius: 5000,
          map: map,
          fillOpacity: 0.1,
          strokeOpacity: 0.5,
          strokeWeight: 1
                                             });
        circle.index = 0;
        circle.setmap(map);
                        }

The following code queries a Google fusion table based on a circular map region.

The center of the circular map region is determined by where a user clicks and the radius is determined by selection from a from a drop down menu. I have a listener set so that when a user clicks on a mapped point an info box es up displaying information from the corresponding fusion table row.

This all works fine until I add a circle to my map (to illustrate to the user what region they have selected), it seems that the presence of the circle is blocking the layer's click event listener. I've tried altering z-index to no avail. Could anyone please suggest a way around this issue?

function initialize() {     

        tableid = xxxxxxx;

              // Initialize the Google Map
        var map = new google.maps.Map(document.getElementById('map_canvas'), {
          center: new google.maps.LatLng(37.3, -122.3),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP   
                                                                               });                                                                        
        var layer = new google.maps.FusionTablesLayer({     
          query: {
            select: 'Address',
            from: tableid,
            where: 'ST_INTERSECTS(Address, CIRCLE(LATLNG(37.3, -122.3), 5000))'
                  }
                                                      });
        layer.setMap(map);
        layer.index = 1;
        map.index =2;
        var meters = 5000;
        var center = map.getCenter();

        // Update the radius when the user makes a selection.
        google.maps.event.addDomListener(document.getElementById('radius'), 'change', function() {  
          meters = parseInt(this.value, 10);
          circle.setRadius(meters);
          searchStr = 'ST_INTERSECTS(Address, ' +'CIRCLE(LATLNG'+center+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
            layer.setOptions({
              query: {
                select: 'Address',
                from: tableid,
                where: searchStr 
                      }
                              }); 
                                                                                                  });                                                                                                                                                                                                                                       //Update the filter when the user makes a selection.
        google.maps.event.addDomListener(document.getElementById('filter'),'change', function() {
          filterSelection = this.value;
          searchStr = 'ST_INTERSECTS(Address, ' + 'CIRCLE(LATLNG'+center+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
            layer.setOptions({
              query: {
                select: 'Address',
                from: tableid,
                where: searchStr
                      } 
                              });
                                                                                                    });  

        //Info Box Populate click handler
        google.maps.event.addListener(layer, 'click', function(e) {
          alert("Info Click");
          e.infoWindowHtml = e.row['Title'].value + "<br>";  
                                                                   });
        //Click Handler
        google.maps.event.addListener(map, 'click', function(e) {
          circle.setCenter(e.latLng);
          center = e.latLng;
          searchStr = 'ST_INTERSECTS(Address, ' + 'CIRCLE(LATLNG'+e.latLng+', ' + meters + '))'
          searchStr += " AND " + "filter_1 IN ("+filterSelection+")";
             layer.setOptions({
               query: {
                 select: 'Address',
                 from: tableid,
                 where: searchStr
                        }
                               });
                                                                   });    
        // Create a map circle object to visually show the radius.
        var circle = new google.maps.Circle({
          center: new google.maps.LatLng(37.3, -122.3),
          radius: 5000,
          map: map,
          fillOpacity: 0.1,
          strokeOpacity: 0.5,
          strokeWeight: 1
                                             });
        circle.index = 0;
        circle.setmap(map);
                        }
Share Improve this question edited Feb 2, 2012 at 6:07 Brock Adams 93.7k23 gold badges241 silver badges305 bronze badges asked Jan 25, 2012 at 23:02 Ben PearceBen Pearce 7,09419 gold badges76 silver badges129 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

When you create the circle, try adding to the CircleOptions object clickable: false

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744221876a236739.html

最新回复(0)