Question

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 comes 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);
                        }
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top