以下是我切换地理围栏的代码, 单击按钮时,我需要显示多个路线的地理围栏 我的意思是onclick显示所有数据,而另一单击隐藏此,即切换
var beforeAnnCircleVisible
button().text('Show geofence').click(function () {
_.each(route.routeStop, function (routeStop) {
var stop = db.index.stop[routeStop.stopId]
var location = new google.maps.LatLng(+stop.latitude, +stop.longitude)
var routeStopMarker = renderRouteStopMarker({map: map, location: location, routeStop: routeStop, showEta: false, showPosition: true})
map.overlays.push(routeStopMarker)
var beforeAnnCircle = new google.maps.Circle({
strokeColor: 'green',
strokeOpacity: 0.8,
strokeWeight: 1,
fillColor: 'green',
fillOpacity: 0.35,
map: map,
center: location,
radius: routeStop.beforeAnnRadius || 0,
visible: false,
editable: true,
draggable: false,
zIndex: 1,
hide: false
})
if (beforeAnnCircleVisible) {
beforeAnnCircleVisible = true
beforeAnnCircle.setVisible(true)
$(this).text('Hide geofence')
}
else {
beforeAnnCircleVisible = false
beforeAnnCircle.setVisible(false)
$(this).text('show geofence')
}
})
return false
})
但是这里不起作用。我在这里想念什么。请建议