gpt4 book ai didi

javascript - 动画热图图层

转载 作者:行者123 更新时间:2023-12-03 10:55:29 24 4
gpt4 key购买 nike

我稍后需要制作热图动画。到目前为止我有这个代码:

HTML

<div id="filteredMap" style="margin-top:15px;" class="col-md-8 col-md-offset-0 col-sm-5 col-sm-offset-3 col-xs-10 col-xs-offset-2 form-group center-block">
<span class="label label-warning">Google map can not be loaded, or you have not filtered the full map.</span>
</div>

JavaScript

$(document).ready(function () {
var heatMapDataFiltered = [];
var heatmapFiltered;
var mapFiltered;
var mapOptionsFiltered;

function initialize() {
mapOptionsFiltered = {
center: { lat: @ViewBag.lat, lng: @ViewBag.lng },
zoom: 15,
maxZoom: 18,
minZoom:14
};

mapFiltered = new google.maps.Map(document.getElementById('filteredMap'),
mapOptionsFiltered);

heatmapFiltered = new google.maps.visualization.HeatmapLayer({
data: heatMapDataFiltered
});

heatmapFiltered.setMap(mapFiltered);
heatmapFiltered.set('gradient', heatmapFiltered.get('gradient') ? null : gradient);
}

$('#btnShowPulse').click(function(){
heatmapFiltered.setMap(null);
heatMapDataFiltered = [];
var noDate = "no";

if($('#NoDate').is(':checked')){
noDate = "yes";
}

var venueCategoryName = $('#venueCategoryName').val();
var venueStartingDate = $('#venueStartingDate').val();
var venueEndingDate = $('#venueEndingDate').val();
var URL = "/Map/FilterJSON?venueCategoryName=" + venueCategoryName + "&venueStartingDate=" + venueStartingDate + "&venueEndingDate=" + venueEndingDate + "&NoDate=" + noDate;

$.ajax({
type: 'get',
dataType: 'json',
cache: false,
url: URL,
success: function (data) {
$.each(data, function (index, data) {
heatMapDataFiltered.push({
location: new google.maps.LatLng(data.lat, data.lng),
weight: data.weight
});

heatmapFiltered = new google.maps.visualization.HeatmapLayer({
data: heatMapDataFiltered
});

heatmapFiltered.setMap(mapFiltered);
heatmapFiltered.set('gradient', heatmapFiltered.get('gradient') ? null : gradient);

setTimeout(2000);
});
},
error: function (request, status, error) {
alert(request.responseText);
}
});
});

google.maps.event.addDomListener(window, 'load', initialize);
});

问题是,这段代码运行成功,但我在 map 上看不到一个点。它将显示所有点,而不是一个一个地显示。我不知道为什么setTimeout不能正常工作?

最佳答案

setTimeout(2000) 不会执行任何操作。

setTimeout(callback, 2000) 将等待两秒,然后执行 callback 函数。

这是一个带有匿名函数的版本:

$.each(data, function (index, data) {
setTimeout(function() {
heatMapDataFiltered.push({
location: new google.maps.LatLng(data.lat, data.lng),
weight: data.weight
});

heatmapFiltered = new google.maps.visualization.HeatmapLayer({
data: heatMapDataFiltered
});

heatmapFiltered.setMap(mapFiltered);
heatmapFiltered.set('gradient', heatmapFiltered.get('gradient') ? null : gradient);

}, 2000 * index)
});

关于javascript - 动画热图图层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28278248/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com