public async Task <IActionResult> GetTypesMapData(int poiTypeId) { MapDataJson dataJson = new MapDataJson(); var poiType = await _mappingService.GetTypeByIdAsync(poiTypeId); if (poiType == null || poiType.DepartmentId != DepartmentId) { Unauthorized(); } foreach (var poi in poiType.Pois) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = poiType.Image; info.Marker = poiType.Marker; info.Title = poiType.Name; info.InfoWindowContent = ""; info.Latitude = poi.Latitude; info.Longitude = poi.Longitude; info.Color = poiType.Color; dataJson.Pois.Add(info); } return(Json(dataJson)); }
public async Task <ActionResult <List <MapMakerInfo> > > GetAllLinkedCallMapMarkers() { var result = new List <MapMakerInfo>(); var links = await _departmentLinksService.GetAllLinksForDepartmentAsync(DepartmentId); foreach (var link in links.Where(x => x.LinkEnabled && x.LinkedDepartmentId == DepartmentId)) { var calls = (await _callsService.GetActiveCallsByDepartmentAsync(link.DepartmentId)).OrderByDescending(x => x.LoggedOn); var department = await _departmentsService.GetDepartmentByIdAsync(link.DepartmentId, false); foreach (var call in calls) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Call"; info.Title = call.Name; info.InfoWindowContent = call.NatureOfCall; info.Color = link.DepartmentColor; if (!String.IsNullOrEmpty(call.GeoLocationData)) { try { info.Latitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[0]); info.Longitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[1]); } catch { } } else if (!String.IsNullOrEmpty(call.Address)) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(call.Address); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); } } result.Add(info); } } return(Ok(result)); }
public async Task <IActionResult> GetMapData(MapSettingsInput input) { MapDataJson dataJson = new MapDataJson(); var calls = await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId); var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId); var lastUserActionlogs = await _actionLogsService.GetLastActionLogsForDepartmentAsync(DepartmentId); var personnelNames = await _departmentsService.GetAllPersonnelNamesForDepartmentAsync(DepartmentId); var unitStates = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var userLocationPermission = await _permissionsService.GetPermissionByDepartmentTypeAsync(DepartmentId, PermissionTypes.CanSeePersonnelLocations); if (userLocationPermission != null) { var userGroup = await _departmentGroupsService.GetGroupForUserAsync(UserId, DepartmentId); int?groupId = null; if (userGroup != null) { groupId = userGroup.DepartmentGroupId; } var roles = await _personnelRolesService.GetRolesForUserAsync(UserId, DepartmentId); var allowedUsers = _permissionsService.GetAllowedUsers(userLocationPermission, DepartmentId, groupId, ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), ClaimsAuthorizationHelper.IsUserDepartmentAdmin(), roles); lastUserActionlogs.RemoveAll(x => !allowedUsers.Contains(x.UserId)); } if (input.ShowDistricts) { foreach (var station in stations) { if (!String.IsNullOrWhiteSpace(station.Geofence)) { GeofenceJson geofence = new GeofenceJson(); geofence.Name = station.Name; geofence.Color = station.GeofenceColor; geofence.Fence = station.Geofence; dataJson.Geofences.Add(geofence); } } } if (input.ShowStations) { foreach (var station in stations) { try { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Station"; info.Title = station.Name; info.InfoWindowContent = station.Name; if (station.Address != null) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", station.Address.Address1, station.Address.City, station.Address.State, station.Address.PostalCode)); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); dataJson.Markers.Add(info); } } else if (!String.IsNullOrWhiteSpace(station.Latitude) && !String.IsNullOrWhiteSpace(station.Longitude)) { info.Latitude = double.Parse(station.Latitude); info.Longitude = double.Parse(station.Longitude); dataJson.Markers.Add(info); } } catch (Exception ex) { //Logging.LogException(ex); } } } if (input.ShowCalls) { foreach (var call in calls) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Call"; info.Title = call.Name; info.InfoWindowContent = call.NatureOfCall; if (!String.IsNullOrEmpty(call.GeoLocationData)) { try { info.Latitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[0]); info.Longitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[1]); dataJson.Markers.Add(info); } catch { } } else if (!String.IsNullOrEmpty(call.Address)) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(call.Address); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); } dataJson.Markers.Add(info); } } } if (input.ShowUnits) { foreach (var unit in unitStates) { if (unit.Latitude.HasValue && unit.Latitude.Value != 0 && unit.Longitude.HasValue && unit.Longitude.Value != 0) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Engine_Responding"; info.Title = unit.Unit.Name; info.InfoWindowContent = ""; info.Latitude = double.Parse(unit.Latitude.Value.ToString()); info.Longitude = double.Parse(unit.Longitude.Value.ToString()); dataJson.Markers.Add(info); } } } if (input.ShowPersonnel) { foreach (var person in lastUserActionlogs) { if (!String.IsNullOrWhiteSpace(person.GeoLocationData)) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Person"; var name = personnelNames.FirstOrDefault(x => x.UserId == person.UserId); if (name != null) { info.Title = name.Name; info.InfoWindowContent = ""; } else { info.Title = ""; info.InfoWindowContent = ""; } var infos = person.GeoLocationData.Split(char.Parse(",")); if (infos != null && infos.Length == 2) { info.Latitude = double.Parse(infos[0]); info.Longitude = double.Parse(infos[1]); dataJson.Markers.Add(info); } } } } if (input.ShowPOIs) { var poiTypes = await _mappingService.GetPOITypesForDepartmentAsync(DepartmentId); foreach (var poiType in poiTypes) { foreach (var poi in poiType.Pois) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = poiType.Image; info.Marker = poiType.Marker; info.Title = poiType.Name; info.InfoWindowContent = ""; info.Latitude = poi.Latitude; info.Longitude = poi.Longitude; info.Color = poiType.Color; dataJson.Pois.Add(info); } } } return(Json(dataJson)); }
public async Task <ActionResult <BigBoardMapModel> > GetMap() { var department = await _departmentsService.GetDepartmentByIdAsync(DepartmentId, false); var stations = await _departmentGroupsService.GetAllStationGroupsForDepartmentAsync(DepartmentId); var address = await _departmentSettingsService.GetBigBoardCenterAddressDepartmentAsync(DepartmentId); var gpsCoordinates = await _departmentSettingsService.GetBigBoardCenterGpsCoordinatesDepartmentAsync(DepartmentId); var calls = await _callsService.GetActiveCallsByDepartmentAsync(DepartmentId); var units = await _unitsService.GetUnitsForDepartmentAsync(DepartmentId); var unitStates = await _unitsService.GetAllLatestStatusForUnitsByDepartmentIdAsync(DepartmentId); var personnelViewModels = (await GetPersonnelStatuses()).Value; string weatherUnits = ""; double?centerLat = null; double?centerLon = null; if (address != null && !String.IsNullOrWhiteSpace(address.Country)) { if (address.Country == "Canada") { weatherUnits = "ca"; } else if (address.Country == "United Kingdom") { weatherUnits = "uk"; } else if (address.Country == "Australia") { weatherUnits = "uk"; } else { weatherUnits = "us"; } } else if (department.Address != null && !String.IsNullOrWhiteSpace(department.Address.Country)) { if (department.Address.Country == "Canada") { weatherUnits = "ca"; } else if (department.Address.Country == "United Kingdom") { weatherUnits = "uk"; } else if (department.Address.Country == "Australia") { weatherUnits = "uk"; } else { weatherUnits = "us"; } } if (!String.IsNullOrWhiteSpace(gpsCoordinates)) { string[] coordinates = gpsCoordinates.Split(char.Parse(",")); if (coordinates.Count() == 2) { double newLat; double newLon; if (double.TryParse(coordinates[0], out newLat) && double.TryParse(coordinates[1], out newLon)) { centerLat = newLat; centerLon = newLon; } } } if (!centerLat.HasValue && !centerLon.HasValue && address != null) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", address.Address1, address.City, address.State, address.PostalCode)); if (!String.IsNullOrEmpty(coordinates)) { double newLat; double newLon; var coordinatesArr = coordinates.Split(char.Parse(",")); if (double.TryParse(coordinatesArr[0], out newLat) && double.TryParse(coordinatesArr[1], out newLon)) { centerLat = newLat; centerLon = newLon; } } } if (!centerLat.HasValue && !centerLon.HasValue && department.Address != null) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", department.Address.Address1, department.Address.City, department.Address.State, department.Address.PostalCode)); if (!String.IsNullOrEmpty(coordinates)) { double newLat; double newLon; var coordinatesArr = coordinates.Split(char.Parse(",")); if (double.TryParse(coordinatesArr[0], out newLat) && double.TryParse(coordinatesArr[1], out newLon)) { centerLat = newLat; centerLon = newLon; } } } if (!centerLat.HasValue || !centerLon.HasValue) { centerLat = 39.14086268299356; centerLon = -119.7583809782715; } var zoomLevel = await _departmentSettingsService.GetBigBoardMapZoomLevelForDepartmentAsync(department.DepartmentId); var mapModel = new BigBoardMapModel { CenterLat = centerLat.Value, CenterLon = centerLon.Value, ZoomLevel = zoomLevel.HasValue ? zoomLevel.Value : 9, }; foreach (var station in stations) { MapMakerInfo info = new MapMakerInfo(); info.Id = $"s{station.DepartmentGroupId}"; info.ImagePath = "Station"; info.Title = station.Name; info.InfoWindowContent = station.Name; if (station.Address != null) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(string.Format("{0} {1} {2} {3}", station.Address.Address1, station.Address.City, station.Address.State, station.Address.PostalCode)); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); mapModel.MapMakerInfos.Add(info); } } else if (!String.IsNullOrWhiteSpace(station.Latitude) && !String.IsNullOrWhiteSpace(station.Longitude)) { info.Latitude = double.Parse(station.Latitude); info.Longitude = double.Parse(station.Longitude); mapModel.MapMakerInfos.Add(info); } } foreach (var call in calls) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Call"; info.Id = $"c{call.CallId}"; info.Title = call.Name; info.InfoWindowContent = call.NatureOfCall; if (!String.IsNullOrEmpty(call.GeoLocationData)) { try { info.Latitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[0]); info.Longitude = double.Parse(call.GeoLocationData.Split(char.Parse(","))[1]); mapModel.MapMakerInfos.Add(info); } catch { } } else if (!String.IsNullOrEmpty(call.Address)) { string coordinates = await _geoLocationProvider.GetLatLonFromAddress(call.Address); if (!String.IsNullOrEmpty(coordinates)) { info.Latitude = double.Parse(coordinates.Split(char.Parse(","))[0]); info.Longitude = double.Parse(coordinates.Split(char.Parse(","))[1]); } mapModel.MapMakerInfos.Add(info); } } foreach (var unit in unitStates) { if (unit.Latitude.HasValue && unit.Latitude.Value != 0 && unit.Longitude.HasValue && unit.Longitude.Value != 0) { MapMakerInfo info = new MapMakerInfo(); info.ImagePath = "Engine_Responding"; info.Id = $"u{unit.UnitId}"; info.Title = unit.Unit.Name; info.InfoWindowContent = ""; info.Latitude = double.Parse(unit.Latitude.Value.ToString()); info.Longitude = double.Parse(unit.Longitude.Value.ToString()); mapModel.MapMakerInfos.Add(info); } } foreach (var person in personnelViewModels) { if (person.Latitude.HasValue && person.Latitude.Value != 0 && person.Longitude.HasValue && person.Longitude.Value != 0) { MapMakerInfo info = new MapMakerInfo(); if (person.StatusValue <= 25) { if (person.StatusValue == 5) { info.ImagePath = "Person_RespondingStation"; } else if (person.StatusValue == 6) { info.ImagePath = "Person_RespondingCall"; } else if (person.StatusValue == 3) { info.ImagePath = "Person_OnScene"; } else { info.ImagePath = "Person_RespondingCall"; } } else if (person.DestinationType > 0) { if (person.DestinationType == 1) { info.ImagePath = "Person_RespondingStation"; } else if (person.DestinationType == 2) { info.ImagePath = "Person_RespondingCall"; } else { info.ImagePath = "Person_RespondingCall"; } } else { info.ImagePath = "Person_RespondingCall"; } //info.Id = $"p{person.}"; info.Title = person.Name; info.InfoWindowContent = ""; info.Latitude = double.Parse(person.Latitude.Value.ToString()); info.Longitude = double.Parse(person.Longitude.Value.ToString()); mapModel.MapMakerInfos.Add(info); } } return(Ok(mapModel)); }