admin管理员组文章数量:1130349
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
1 Answer
Reset to default 12When you create the circle, try adding to the CircleOptions object clickable: false
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
1 Answer
Reset to default 12When you create the circle, try adding to the CircleOptions object clickable: false
本文标签: Google Fusion Map Circle blocking layer click eventsJavaScriptStack Overflow
版权声明:本文标题:Google Fusion Map: Circle blocking layer click events, javascript - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1744221873a2086732.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论