Skip to content

Commit

Permalink
#366 additional work for handling HERE map in the admin
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Dec 1, 2017
1 parent e563a39 commit 8cf93b0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package alfio.controller.api.admin;

import alfio.manager.system.ConfigurationManager;
import alfio.model.modification.support.LocationDescriptor;
import alfio.model.system.Configuration;
import alfio.model.system.ConfigurationKeys;
import com.moodysalem.TimezoneMapper;
Expand All @@ -25,9 +26,8 @@
import org.springframework.web.bind.annotation.*;

import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.function.Function;

@RestController
@RequestMapping("/admin/api")
Expand Down Expand Up @@ -63,4 +63,23 @@ public String getTimezone(@RequestParam("lat") double lat, @RequestParam("lng")
String tzId = TimezoneMapper.tzNameAt(lat, lng);
return getTimezones().contains(tzId) ? tzId : null;
}

@RequestMapping(value = "/location/static-map-image")
public String getMapImage(
@RequestParam("lat") String lat,
@RequestParam("lng") String lng,
@RequestParam("orgId") int orgId,
@RequestParam(value = "eventId", required = false) Integer eventId) {

Function<ConfigurationKeys, Configuration.ConfigurationPathKey> pathKeyBuilder = (key) ->
eventId == null ? Configuration.from(orgId, key) : Configuration.from(orgId, eventId, key);

Map<ConfigurationKeys, Optional<String>> geoInfoConfiguration = configurationManager.getStringConfigValueFrom(
pathKeyBuilder.apply(ConfigurationKeys.MAPS_PROVIDER),
pathKeyBuilder.apply(ConfigurationKeys.MAPS_CLIENT_API_KEY),
pathKeyBuilder.apply(ConfigurationKeys.MAPS_HERE_APP_ID),
pathKeyBuilder.apply(ConfigurationKeys.MAPS_HERE_APP_CODE));

return LocationDescriptor.getMapUrl(lat, lng, geoInfoConfiguration);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,25 @@ public LocationDescriptor(@JsonProperty("timeZone") String timeZone,

public static LocationDescriptor fromGeoData(Pair<String, String> coordinates, TimeZone timeZone, Map<ConfigurationKeys, Optional<String>> geoConf) {
Map<String, String> params = new HashMap<>();
params.put("latitude", coordinates.getLeft());
params.put("longitude", coordinates.getRight());
String lat = coordinates.getLeft();
String lng = coordinates.getRight();
params.put("latitude", lat);
params.put("longitude", lng);

return new LocationDescriptor(timeZone.getID(), coordinates.getLeft(), coordinates.getRight(), getMapUrl(lat, lng, geoConf));
}

public static String getMapUrl(String lat, String lng, Map<ConfigurationKeys, Optional<String>> geoConf) {
Map<String, String> params = new HashMap<>();
params.put("latitude", lat);
params.put("longitude", lng);

ConfigurationKeys.GeoInfoProvider provider = getProvider(geoConf);
String mapUrl = mapUrl(provider);

fillParams(provider, geoConf, params);

return new LocationDescriptor(timeZone.getID(), coordinates.getLeft(), coordinates.getRight(), new StrSubstitutor(params).replace(mapUrl));
return new StrSubstitutor(params).replace(mapUrl);
}

// for backward compatibility reason, the logic is not straightforward
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@

$scope.loading = false;
$scope.loadingMap = true;
LocationService.getMapUrl(result.event.latitude, result.event.longitude).then(function(mapUrl) {
LocationService.getMapUrl(result.event.latitude, result.event.longitude, result.event.organizationId, result.event.id).then(function(mapUrl) {
$scope.event.geolocation = {
latitude: result.event.latitude,
longitude: result.event.longitude,
Expand Down
8 changes: 4 additions & 4 deletions src/main/webapp/resources/js/admin/service/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@
getTimezones: function() {
return $http.get('/admin/api/location/timezones');
},
getMapUrl : function(latitude, longitude) {
return this.mapApiKey().then(function(key) {
return mapUrl(latitude, longitude, key);
}, HttpErrorHandler.handle);
getMapUrl : function(latitude, longitude, orgId, eventId) {
return $http.get('/admin/api/location/static-map-image', {params: {lat: latitude, lng: longitude, orgId : orgId, eventId: eventId}}).then(function(res) {
return res.data;
});
}
};
});
Expand Down

0 comments on commit 8cf93b0

Please sign in to comment.