I have function for map updating
Here is code
function update() {
ajaxLoader.removeClass('mc-warning-noConnection');
ajaxLoader.show();
$.ajax({
url: '/Mobile/Map/GetMapData',
type: 'GET',
timeout: 10000,
success: function (data) {
if (data.redirectUrl) window.location.replace(data.redirectUrl);
else if (data.error) alert(data.error);
else {
setTimeout(function () { ajaxLoader.hide() }, 300);
data.forEach(function (vehicleData) {
mapWrapper.getEntity(vehicleData.Imei).update(vehicleData);
});
}
},
error: function () {
ajaxLoader.addClass('mc-warning-noConnection');
},
complete: function () {
timeout = setTimeout(update, 10000);
}
});
}
It need to get values from db via controller
Here is controller code.
public async Task<ActionResult> GetMapData()
{
var mapData = await repository.GetVehicleMapData(15, null).ConfigureAwait(false);
Session["PreviousMapQueryTime"] = DateTime.Now.AddMinutes(-5); //5 minutes offset because tables aren't always up-to-date
return CreateJsonDataResult(mapData);
}
And than pass them to map and update markers.
Here is MapWrapper script
With markers all okay, but zoom when updating not works.
When I reload map all okay. But not from updating without reloading whole page.
Where is problem and how I can fix it?
You should use mapWrapper.zoomToLayer(layerID)
function after update entities, where Layerid is ID of layer where your entities placed.
success: function (data) {
if (data.redirectUrl) window.location.replace(data.redirectUrl);
else if (data.error) alert(data.error);
else {
setTimeout(function () { ajaxLoader.hide() }, 300);
data.forEach(function (vehicleData) {
mapWrapper.getEntity(vehicleData.Imei).update(vehicleData);
});
mapWrapper.zoomToLayer(layerID);
}
},
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.