擅长:python、mysql、java
<p>您可以设置某种计时器,使用javascript函数自动更新数据。在这里,我使用一个名为“STI”的源代码和层,它只是geoJSON行数据</p>
<p>该函数将首先添加数据源和图层:</p>
<pre><code>var STI_SOURCE = 'json/sti/STI.json'; // declare URL for data
map.addSource('sti', { type: 'geojson', data: STI1 }); // Add source using URL
// Add the actual layer using the source
map.addLayer({
"id": "sti",
"type": "line",
"source": "sti",
"layout": {
"line-join": "miter",
"line-cap": "round"
},
"paint": {
"line-color": "#fff",
"line-width": 1,
"line-dasharray": [6, 2]
}
});
</code></pre>
<p>然后,当您要刷新数据时,请删除它们:</p>
<pre><code> map.removeLayer('sti');
map.removeSource('sti');
</code></pre>
<p>然后,您可以从头开始重新添加它们。还有其他方法(更好)可以做到这一点,但这只是一种有效的方法。我认为有一个setData()函数可以做得更好。但希望这能让你开始</p>