WorkspaceInfo ws = findWorkspace(wsName, cat);
String name = obj.str("name");
if (name == null) {
throw new BadRequestException("Map object requires name");
}
try {
findMap(wsName, name, cat);
throw new BadRequestException("Map named '" + name + "' already exists");
}
catch(NotFoundException e) {
// good!
}
String title = obj.str("title");
String description = obj.str("abstract");
Date created = new Date();
CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84;
JSONObj proj = obj.object("proj");
if (proj != null) {
try {
crs = IO.crs(proj);
} catch (Exception e) {
throw new BadRequestException("Error parsing proj: " + proj.toString());
}
}
else {
throw new BadRequestException("Map object requires projection");
}
ReferencedEnvelope bounds = null;
boolean updateBounds = false;
if (obj.has("bbox")) {
Envelope envelope = IO.bounds(obj.object("bbox"));
bounds = new ReferencedEnvelope( envelope, crs );
}
else {
bounds = new ReferencedEnvelope(crs);
updateBounds = true;
}
if (!obj.has("layers")) {
throw new BadRequestException("Map object requires layers array");
}
LayerGroupInfo map = cat.getFactory().createLayerGroup();
map.setName( name );
map.setAbstract( description );