* @return
*/
private NativeObject prepConfig(NativeObject config) {
Scriptable scope = config.getParentScope();
Object propertiesObj = getOptionalMember(config, "properties", NativeObject.class, "Object");
NativeObject properties = null;
if (propertiesObj != null) {
properties = (NativeObject) propertiesObj;
}
Geometry geometry = null;
if (config.has("geometry", config)) {
// GeoJSON config
Object geometryObj = config.get("geometry", config);
if (!(geometryObj instanceof NativeObject)) {
throw ScriptRuntime.constructError("Error",
"Expected geometry member to be an object, got: " + Context.toString(geometryObj));
}
geometryObj = JSON.readObj((NativeObject) geometryObj);
if (!(geometryObj instanceof Geometry)) {
throw ScriptRuntime.constructError("Error", "Expected geometry memeber to be a valid geometry, got: " + Context.toString(geometryObj));
}
geometry = (Geometry) geometryObj;
config.delete("geometry");
// allow passing a geometry only with no other properties
if (properties == null) {
Context cx = Context.enter();
try {
properties = (NativeObject) cx.newObject(scope);
} finally {
Context.exit();
}
config.put("properties", config, properties);
}
}
if (geometry != null && properties != null) {
properties.put("geometry", properties, geometry);
}
return config;
}