use of com.axelor.apps.base.service.MapService in project axelor-open-suite by axelor.
the class AddressController method viewDirection.
public void viewDirection(ActionRequest request, ActionResponse response) {
AddressRepository addressRepository = Beans.get(AddressRepository.class);
try {
MapService mapService = Beans.get(MapService.class);
String key = null;
if (Beans.get(AppBaseService.class).getAppBase().getMapApiSelect() == AppBaseRepository.MAP_API_GOOGLE) {
key = mapService.getGoogleMapsApiKey();
}
Company company = Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null);
if (company == null) {
response.setFlash(I18n.get(IExceptionMessage.PRODUCT_NO_ACTIVE_COMPANY));
return;
}
Address departureAddress = company.getAddress();
if (departureAddress == null) {
response.setFlash(I18n.get(IExceptionMessage.ADDRESS_7));
return;
}
departureAddress = addressRepository.find(departureAddress.getId());
Optional<Pair<BigDecimal, BigDecimal>> departureLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(departureAddress);
if (!departureLatLong.isPresent()) {
response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), departureAddress.getFullName()));
return;
}
Address arrivalAddress = request.getContext().asType(Address.class);
arrivalAddress = addressRepository.find(arrivalAddress.getId());
Optional<Pair<BigDecimal, BigDecimal>> arrivalLatLong = Beans.get(AddressService.class).getOrUpdateLatLong(arrivalAddress);
if (!arrivalLatLong.isPresent()) {
response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), arrivalAddress.getFullName()));
return;
}
Map<String, Object> mapView = new HashMap<>();
mapView.put("title", "Map");
mapView.put("resource", mapService.getDirectionUrl(key, departureLatLong.get(), arrivalLatLong.get()));
mapView.put("viewType", "html");
response.setView(mapView);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.service.MapService in project axelor-open-suite by axelor.
the class AddressController method viewMap.
public void viewMap(ActionRequest request, ActionResponse response) {
try {
Address address = request.getContext().asType(Address.class);
address = Beans.get(AddressRepository.class).find(address.getId());
Optional<Pair<BigDecimal, BigDecimal>> latLong = Beans.get(AddressService.class).getOrUpdateLatLong(address);
if (latLong.isPresent()) {
MapService mapService = Beans.get(MapService.class);
Map<String, Object> mapView = new HashMap<>();
mapView.put("title", "Map");
mapView.put("resource", mapService.getMapUrl(latLong.get(), address.getFullName()));
mapView.put("viewType", "html");
response.setView(mapView);
} else {
response.setFlash(String.format(I18n.get(IExceptionMessage.ADDRESS_5), address.getFullName()));
}
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations