【发布时间】:2021-08-14 12:49:59
【问题描述】:
我正在使用<GoogleMapReact> 项目,在我在地图上渲染的东西中,有一个叫做geoFences 的圆圈。
问题是我有时想改变圆圈,但不是改变它们,而是地图将它们呈现在彼此之上。
function renderGeoFences(map, maps) {
const geoFencesSites = settings.geoFenceSites.filter((site) => !site.deleted);
_.map(geoFencesSites, (site) => {
let circle = new maps.Circle({
strokeColor: tag.id!=='all-jobs' ? "orange":'#1aba8b26',
strokeOpacity: 1,
strokeWeight: 4,
fillColor: '#1aba8b1f',
fillOpacity: 1,
map,
center: { lat: Number(site.location.latitude), lng: Number(site.location.longitude) },
radius: site.fenceSize,
});
});
}
每次更改标签(状态)的值时都会调用此函数。它们不是像函数显示的那样仅仅改变描边颜色,而是在彼此之上渲染,您可以通过填充颜色来判断哪个应该具有不透明度,但它变得越来越暗。
我尝试使用此处的说明删除它https://developers.google.com/maps/documentation/javascript/shapes#maps_circle_simple-typescript 但它没有用。
在这次尝试中,我创建了一个列表,而不是一次只推送一个,最后按名为showJobsLocations 的状态。好像第一次运行,当状态为true时,圆圈不会渲染,这很好,但是在第二次运行时,他们会这样做,然后越来越暗,这意味着他们不会渲染如果我不想要它们,但一旦它们被删除,它们就不会被删除。
function renderGeoFences(map, maps) {
const geoFencesSites = punchClockStore.settings.geoFenceSites.filter((site) => !site.deleted);
const circles = []
_.map(geoFencesSites, (site) => {
circles.push(new maps.Circle({
strokeColor: '#1aba8b26',
strokeOpacity: 1,
strokeWeight: 4,
fillColor: '#1aba8b1f',
fillOpacity: 1,
map,
center: {lat: Number(site.location.latitude), lng: Number(site.location.longitude)},
radius: site.fenceSize,
}));
if (showJobsLocations){
// circle.setMap(null)
if (circles.length) circles.map((circle) => circle.setMap(null));
}
});
}
有人知道如何从<GoogleMapReact> 中删除Circles 吗?
【问题讨论】:
标签: javascript reactjs google-maps google-maps-react