bool rho_map_check_param(rho_param *p) { if (!p || p->type != RHO_PARAM_HASH) rho_ruby_raise_argerror("Wrong input parameter (expect Hash)"); rho_param *provider = NULL; for (int i = 0, lim = p->v.hash->size; i < lim; ++i) { char *name = p->v.hash->name[i]; rho_param *value = p->v.hash->value[i]; if (!name || !value) continue; if (strcasecmp(name, "provider") == 0) provider = value; } std::string providerId = "google"; if (provider) { if (provider->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'provider' value (expect String)"); providerId = provider->v.string; } std::transform(providerId.begin(), providerId.end(), providerId.begin(), &::tolower); return RHOMAPPROVIDER().isRegisteredMapEngine(providerId); }
rhomap::IMapView *rho_map_create(rho_param *p, rhomap::IDrawingDevice *device, int width, int height) { if (!p || p->type != RHO_PARAM_HASH) rho_ruby_raise_argerror("Wrong input parameter (expect Hash)"); rho_param *provider = NULL; rho_param *settings = NULL; rho_param *annotations = NULL; for (int i = 0, lim = p->v.hash->size; i < lim; ++i) { char *name = p->v.hash->name[i]; rho_param *value = p->v.hash->value[i]; if (!name || !value) continue; if (strcasecmp(name, "provider") == 0) provider = value; else if (strcasecmp(name, "settings") == 0) settings = value; else if (strcasecmp(name, "annotations") == 0) annotations = value; } std::string providerId = "google"; if (provider) { if (provider->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'provider' value (expect String)"); providerId = provider->v.string; } std::transform(providerId.begin(), providerId.end(), providerId.begin(), &::tolower); char *map_type = "roadmap"; bool use_center_radius = false; double latitude = 0; double longitude = 0; double latitudeSpan = 0; double longitudeSpan = 0; char *center = NULL; double radius = 0; bool zoom_enabled = true; bool scroll_enabled = true; if (settings) { if (settings->type != RHO_PARAM_HASH) rho_ruby_raise_argerror("Wrong 'settings' value (expect Hash)"); for (int i = 0, lim = settings->v.hash->size; i < lim; ++i) { char *name = settings->v.hash->name[i]; rho_param *value = settings->v.hash->value[i]; if (!name || !value) continue; if (strcasecmp(name, "map_type") == 0) { if (value->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'map_type' value (expect String)"); map_type = value->v.string; if (strcasecmp(map_type,"standard") == 0) { map_type = "roadmap"; } } else if (strcasecmp(name, "region") == 0) { if (value->type == RHO_PARAM_ARRAY) { if (value->v.array->size != 4) rho_ruby_raise_argerror("'region' array should contain exactly 4 items"); rho_param *lat = value->v.array->value[0]; if (!lat) continue; rho_param *lon = value->v.array->value[1]; if (!lon) continue; rho_param *latSpan = value->v.array->value[2]; if (!latSpan) continue; rho_param *lonSpan = value->v.array->value[3]; if (!lonSpan) continue; latitude = lat->type == RHO_PARAM_STRING ? strtod(lat->v.string, NULL) : 0; longitude = lon->type == RHO_PARAM_STRING ? strtod(lon->v.string, NULL) : 0; latitudeSpan = latSpan->type == RHO_PARAM_STRING ? strtod(latSpan->v.string, NULL) : 0; longitudeSpan = lonSpan->type == RHO_PARAM_STRING ? strtod(lonSpan->v.string, NULL) : 0; use_center_radius = false; } else if (value->type == RHO_PARAM_HASH) { for (int j = 0, limm = value->v.hash->size; j < limm; ++j) { char *rname = value->v.hash->name[j]; rho_param *rvalue = value->v.hash->value[j]; if (!rname || !rvalue) continue; if (strcasecmp(rname, "center") == 0) { if (rvalue->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'center' value (expect String)"); center = rvalue->v.string; } else if (strcasecmp(rname, "radius") == 0) { if (rvalue->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'radius' value (expect String or Float)"); radius = strtod(rvalue->v.string, NULL); } } use_center_radius = true; } else rho_ruby_raise_argerror("Wrong 'region' value (expect Array or Hash"); } else if (strcasecmp(name, "zoom_enabled") == 0) { if (value->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'zoom_enabled' value (expect boolean)"); zoom_enabled = strcasecmp(value->v.string, "true") == 0; } else if (strcasecmp(name, "scroll_enabled") == 0) { if (value->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong 'scroll_enabled' value (expect boolean)"); scroll_enabled = strcasecmp(value->v.string, "true") == 0; } } } typedef rhomap::Annotation ann_t; typedef std::vector<ann_t> ann_list_t; ann_list_t ann_list; if (annotations) { if (annotations->type != RHO_PARAM_ARRAY) rho_ruby_raise_argerror("Wrong 'annotations' value (expect Array)"); for (int i = 0, lim = annotations->v.array->size; i < lim; ++i) { rho_param *ann = annotations->v.array->value[i]; if (!ann) continue; if (ann->type != RHO_PARAM_HASH) rho_ruby_raise_argerror("Wrong annotation value found (expect Hash)"); bool latitude_set = false; double latitude = 0; bool longitude_set = false; double longitude = 0; char const *address = ""; char const *title = ""; char const *subtitle = ""; char const *url = ""; char const *image = NULL; int x_off = 0; int y_off = 0; for (int j = 0, limm = ann->v.hash->size; j < limm; ++j) { char *name = ann->v.hash->name[j]; rho_param *value = ann->v.hash->value[j]; if (!name || !value) continue; if (value->type != RHO_PARAM_STRING) rho_ruby_raise_argerror("Wrong annotation value"); char *v = value->v.string; if (strcasecmp(name, "latitude") == 0) { latitude = strtod(v, NULL); latitude_set = true; } else if (strcasecmp(name, "longitude") == 0) { longitude = strtod(v, NULL); longitude_set = true; } else if (strcasecmp(name, "street_address") == 0) address = v; else if (strcasecmp(name, "title") == 0) title = v; else if (strcasecmp(name, "subtitle") == 0) subtitle = v; else if (strcasecmp(name, "url") == 0) url = v; else if (strcasecmp(name, "image") == 0) image = v; else if (strcasecmp(name, "image_x_offset") == 0) { x_off = (int)strtod(v, NULL); } else if (strcasecmp(name, "image_y_offset") == 0) { y_off = (int)strtod(v, NULL); } } if (latitude_set && longitude_set) { ann_t ann(title, subtitle, latitude, longitude, url); if (image != NULL) { ann.setImageFileName(image, x_off, y_off); } ann_list.push_back(ann); } else { ann_t ann(title, subtitle, address, url); if (image != NULL) { ann.setImageFileName(image, x_off, y_off); } ann_list.push_back(ann); } } } rhomap::IMapView *mapview = RHOMAPPROVIDER().createMapView(providerId, device); if (!mapview) return NULL; mapview->setSize(width, height); if (map_type) mapview->setMapType(map_type); if (use_center_radius) { mapview->moveTo(center); mapview->setZoom(radius, radius); } else { mapview->moveTo(latitude, longitude); mapview->setZoom(latitudeSpan, longitudeSpan); } mapview->setZoomEnabled(zoom_enabled); mapview->setScrollEnabled(scroll_enabled); for (ann_list_t::iterator it = ann_list.begin(), lim = ann_list.end(); it != lim; ++it) mapview->addAnnotation(*it); return mapview; }
VALUE MethodResultJni::toRuby() { RAWTRACE("toRuby"); VALUE res = Qnil; JNIEnv *env = jniInit(); if (!env) { RAWLOG_FATAL("JNI initialization failed"); rb_raise(rb_eRuntimeError,"JNI initialization failed"); return Qnil; } int type = getResultType(env); switch(type) { case typeNone: break; case typeBoolean: { bool booleanResult = static_cast<bool>(getBooleanResult(env)); res = booleanResult ? Qtrue : Qfalse; } break; case typeInteger: { int intResult = static_cast<int>(getIntegerResult(env)); res = rho_ruby_create_integer(intResult); } break; case typeDouble: { double doubleResult = static_cast<double>(getDoubleResult(env)); res = rho_ruby_create_double(doubleResult); } break; case typeString: { jhstring jhStrResult = getStringResult(env); res = rho_cast<VALUE>(env, jhStrResult); } break; case typeList: { jhobject jhListResult = getListResult(env); res = rho_cast<VALUE>(env, jhListResult); } break; case typeMap: { jhobject jhMapResult = getMapResult(env); res = rho_cast<VALUE>(env, jhMapResult); } break; case typeArgError: rho_ruby_raise_argerror(getErrorMessage(env).c_str()); break; case typeError: rb_raise(rb_eRuntimeError, getErrorMessage(env).c_str()); break; default: RAWLOG_FATAL("Unknown runtime error in MethodResultJni class"); rb_raise(rb_eRuntimeError,"Unknown runtime error in MethodResultJni class"); } reset(env); return res; }