我在db中有一个庞大的GIS数据。我在查看地图之前获取此数据并将其转换为geoJson文件。我正在获取所有数据以满足要求,这需要花费大量时间。有没有办法为用户正在查看的特定地图窗口加载数据,并且只使用传单库为同一窗口加载相应的GIS数据?
在我的情况下,我使用谷歌地图在地图上显示一个国家的停车位(GIS数据)。
答案 0 :(得分:0)
是的,您需要编写一些代码才能从服务器获取特定数据。看看下面的行是否可以帮助你
//whenever a drag or zoom finish, trigger the function to get new data
map.on('dragend', getData);//leaflet event
map.on('zoomend', getData);//leaflet event
function getData(){
//get the extent of your window
var minx = map.getBounds().getEast();
var miny = map.getBounds().getSouth();
var maxx = map.getBounds().getWest();
var maxy = map.getBounds().getNorth();
//trigger an ajax call to get data as per your extent
$.ajax({
url: 'url_like_a_php_service',
type: "get",
dataType: 'json',
async: false,
//send your extent to service to get specific data, like below
data: 'minx=' + minx + '&miny='+miny+ '&maxx='+maxx+ '&maxy='+maxy,
beforeSend: function () {
//you may write code here like showing a gif on map
},
complete: function (response) {
//pass data to another function to render on map
renderDataonMap();
}
});
}