Exemplo n.º 1
0
IDrawingImage *AndroidMapDevice::cloneImage(IDrawingImage *image)
{
    RHO_MAP_TRACE1("cloneImage: image=%p", image);
    IDrawingImage *cloned = image ? ((AndroidImage *)image)->clone() : NULL;
    RHO_MAP_TRACE1("cloneImage: return image=%p", cloned);
    return cloned;
}
Exemplo n.º 2
0
static bool parse_json(const char *data, double *plat, double *plon, String* adress, bool* coord_ok, bool* adress_ok)
{
    RHO_MAP_TRACE1("parse_json: data=%s", data);
    json::CJSONEntry json(data);
    const char *status = json.getString("status");
    RHO_MAP_TRACE1("parse_json: status=%s", status);
    if (strcasecmp(status, "OK") != 0)
        return false;
    bool params_founded = false;
    if (adress_ok != NULL) {
        *adress_ok = false;
    }
    if (coord_ok != NULL) {
        *coord_ok = false;
    }
    for (json::CJSONArrayIterator results = json.getEntry("results"); !results.isEnd(); results.next())
    {
        json::CJSONEntry item = results.getCurItem();
        
        
        if (item.hasName("formatted_address")) {
            json::CJSONEntry formatted_address = item.getEntry("formatted_address");
            if (adress != NULL) {
                *adress = formatted_address.getString();
            }
            params_founded = true;
            if (adress_ok != NULL) {
                *adress_ok = true;
            }
        }
        
        if (item.hasName("geometry")) {
            json::CJSONEntry geometry = item.getEntry("geometry");
            json::CJSONEntry location = geometry.getEntry("location");
            *plat = location.getDouble("lat");
            *plon = location.getDouble("lng");
            params_founded = true;
            if (coord_ok != NULL) {
                *coord_ok = true;
            }
        }
        
        if (params_founded) {
            return true;
        }
    }

    return false;
}
Exemplo n.º 3
0
DrawingImageImpl::~DrawingImageImpl() {
	RHO_MAP_TRACE1("DrawingImage destroy with ID = %d", mID);
	if (mBitmap != NULL) {
		mBitmap->release();
		mBitmap = NULL;
	}
}
Exemplo n.º 4
0
IDrawingImage *AndroidMapDevice::createImage(String const &path, bool useAlpha)
{
    RHO_MAP_TRACE1("createImage: %s", path.c_str());

    JNIEnv *env = jnienv();
    jclass cls = getJNIClass(RHODES_JAVA_CLASS_MAPVIEW);
    if (!cls) return NULL;
    jmethodID mid = getJNIClassStaticMethod(env, cls, "createImage", "(Ljava/lang/String;)Landroid/graphics/Bitmap;");
    if (!mid) return NULL;

    jobject bitmap = env->CallStaticObjectMethod(cls, mid, rho_cast<jhstring>(path).get());
    IDrawingImage *image = new AndroidImage(bitmap);
    
    RHO_MAP_TRACE1("createImage: return image=%p", image);
    return image;
}
Exemplo n.º 5
0
LRESULT CRhoMapViewDlg::OnZoomOut(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) {
	if (ourMapView != NULL	) {
		int nz = ourMapView->zoom()-1;
		RHO_MAP_TRACE1("MapView->setZoom( %d)", nz);
		ourMapView->setZoom(nz);
		int dwPos = ourMapView->zoom();
		dwPos = ourMapView->maxZoom() - (dwPos - ourMapView->minZoom());
		::SendMessage(GetDlgItem(IDC_SLIDER_ZOOM).m_hWnd, TBM_SETPOS, TRUE, dwPos); 
		requestRedraw();
	}
	return 0;
}
Exemplo n.º 6
0
void AndroidMapDevice::paint(jobject canvas)
{
    RHO_MAP_TRACE1("paint: m_jdevice=%p", m_jdevice);

    if (m_mapview)
    {
        std::auto_ptr<AndroidDrawingContext> context(new AndroidDrawingContext(m_jdevice, canvas));
        m_mapview->paint(context.get());
    }

    RHO_MAP_TRACE("paint done");
}
Exemplo n.º 7
0
bool GoogleGeoCoding::fetchData(String const &url, void **data, size_t *datasize)
{
    RHO_MAP_TRACE1("GoogleGeoCoding: fetchData: url=%s", url.c_str());
    NetResponse resp = getNet().doRequest("GET", url, "", 0, 0);
    if (!resp.isOK())
        return false;
    *datasize = resp.getDataSize();
    *data = malloc(*datasize);
    if (!*data)
        return false;
    memcpy(*data, resp.getCharData(), *datasize);
    return true;
}
Exemplo n.º 8
0
LRESULT CRhoMapViewDlg::OnSliderScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
	//if (wParam == TB_THUMBTRACK) {
		
		int dwPos = ::SendMessage(GetDlgItem(IDC_SLIDER_ZOOM).m_hWnd, TBM_GETPOS, 0, 0); 
		if (ourMapView != NULL) {
			dwPos = ourMapView->maxZoom() - (dwPos - ourMapView->minZoom());
			RHO_MAP_TRACE1("MapView->setZoom( %d)", dwPos);
			ourMapView->setZoom(dwPos);
		}
		requestRedraw();

	//}
	return 0;
}
Exemplo n.º 9
0
static bool parse_json(const char *data, double *plat, double *plon)
{
    RHO_MAP_TRACE1("parse_json: data=%s", data);
    json::CJSONEntry json(data);
    const char *status = json.getString("status");
    RHO_MAP_TRACE1("parse_json: status=%s", status);
    if (strcasecmp(status, "OK") != 0)
        return false;
    for (json::CJSONArrayIterator results = json.getEntry("results"); !results.isEnd(); results.next())
    {
        json::CJSONEntry item = results.getCurItem();
        if (!item.hasName("geometry"))
            continue;

        json::CJSONEntry geometry = item.getEntry("geometry");
        json::CJSONEntry location = geometry.getEntry("location");
        *plat = location.getDouble("lat");
        *plon = location.getDouble("lng");
        return true;
    }

    return false;
}
Exemplo n.º 10
0
void AndroidMapDevice::requestRedraw()
{
    RHO_MAP_TRACE1("requestRedraw: m_jdevice=%p", m_jdevice);

    if (m_jdevice)
    {
        JNIEnv *env = jnienv();
        jclass cls = getJNIClass(RHODES_JAVA_CLASS_MAPVIEW);
        if (!cls) return;
        jmethodID mid = getJNIClassMethod(env, cls, "redraw", "()V");
        if (!mid) return;
        env->CallVoidMethod(m_jdevice, mid);
    }

    RHO_MAP_TRACE("requestRedraw done");
}
Exemplo n.º 11
0
 IDrawingImage *AndroidMapDevice::createImageEx(void const *p, size_t size, int x, int y, int w, int h, bool useAlpha) {
     RHO_MAP_TRACE2("createImageEx: p=%p, size=%llu", p, (unsigned long long)size);
     
     JNIEnv *env = jnienv();
     jclass cls = getJNIClass(RHODES_JAVA_CLASS_MAPVIEW);
     if (!cls) return NULL;
     jmethodID mid = getJNIClassStaticMethod(env, cls, "createImageEx", "([BIIII)Landroid/graphics/Bitmap;");
     if (!mid) return NULL;
     
     jholder<jbyteArray> data = jholder<jbyteArray>(env->NewByteArray(size));
     if (!data) return NULL;
     env->SetByteArrayRegion(data.get(), 0, size, (jbyte const *)p);
     
     jobject bitmap = env->CallStaticObjectMethod(cls, mid, data.get(), x, y, w, h);
     IDrawingImage *image = new AndroidImage(bitmap);
     
     RHO_MAP_TRACE1("createImage: return image=%p", image);
     return image;
 }
Exemplo n.º 12
0
bool GoogleGeoCoding::fetchData(String const &url, void **data, size_t *datasize)
{
    RHO_MAP_TRACE1("GoogleGeoCoding: fetchData: url=%s", url.c_str());
#ifdef ENABLE_ANDROID_NET_REQUEST
    mNetRequestID = mapengine_request_make();
    int s = 0;
    int res = 0;
    res = mapengine_request_data(mNetRequestID, url.c_str(), data, &s);
    *datasize = s;
    return res > 0;
#else
 NetResponse resp = getNet().doRequest("GET", url, "", 0, 0);
    if (!resp.isOK())
        return false;
    *datasize = resp.getDataSize();
    *data = malloc(*datasize);
    if (!*data)
        return false;
    memcpy(*data, resp.getCharData(), *datasize);
    return true;
#endif
 }
Exemplo n.º 13
0
void AndroidMapDevice::destroyImage(IDrawingImage *image)
{
    RHO_MAP_TRACE1("destroyImage: image=%p", image);
    delete image;
    RHO_MAP_TRACE("destroyImage done");
}
Exemplo n.º 14
0
void DrawingImageImpl::init(const char* path, void const *p, int size, WMBitmap* bitmap, bool useAlpha) {
	mID = ++ourDrawingImageID;
	RHO_MAP_TRACE1("DrawingImage create with ID = %d", mID);

#if defined(_WIN32_WCE)
	IImagingFactory *pImgFactory = NULL;
	IImage *pImage = NULL;

	mWidth = 0;
	mHeight = 0;
	mBitmap = NULL;

	if (bitmap != NULL) {
		mBitmap = bitmap;
		mBitmap->addRef();
		mWidth = bitmap->width();
		mHeight = bitmap->height();
		return;
	}

	HRESULT co_init_result = CoInitializeEx(NULL, 0/*COINIT_APARTMENTTHREADED*/);
	if ( (co_init_result == S_OK) || (co_init_result == S_FALSE)  ) {
		msg_out("CoInitializeEx OK");
		if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,
			NULL,
			CLSCTX_INPROC_SERVER,
			IID_IImagingFactory,
			(void **)&pImgFactory)))
		{
			HRESULT res = 0;
			if (p != NULL) {
				// from buf
				res = pImgFactory->CreateImageFromBuffer(
															p,
															size,
															BufferDisposalFlagNone,
															&pImage);
			}
			else {
				// from file
				msg_out("Create Image Factory OK");
				wchar_t wc_filename[2048];
				mbstowcs(wc_filename, path, 2048);
				res = pImgFactory->CreateImageFromFile(
														wc_filename,
														&pImage);
			}
			if (SUCCEEDED(res))
			{
				IImage* mimage = pImage;
				ImageInfo imgInfo;
				mimage->GetImageInfo(&imgInfo);
				mWidth = imgInfo.Width;
				mHeight = imgInfo.Height;
				RHO_MAP_TRACE2("Drawing Image was created with WIDTH = %d, HEIGHT = %d", mWidth, mHeight);
				mBitmap = new WMBitmap(mimage, useAlpha);
				mimage->Release();
			}
			else {
				err_out("Image not created !");
			}
			pImgFactory->Release();
		}
		else {
			err_out("ImageFactory not created !");
		}
		CoUninitialize();
	}
	else {
		err_out("CoInitializeEx not initialized !");
	}
#endif //#if defined(_WIN32_WCE)
}
Exemplo n.º 15
0
void GoogleGeoCoding::resolve(String const &address, GeoCodingCallback *cb)
{
    RHO_MAP_TRACE1("GoogleGeoCoding: resolve address=%s", address.c_str());
    addQueueCommand(new Command(address, cb));
}
Exemplo n.º 16
0
void GoogleGeoCoding::processCommand(IQueueCommand *pCmd)
{
    Command *cmd = (Command*)pCmd;
    GeoCodingCallback &cb = *(cmd->callback);

    String url = "http://maps.googleapis.com/maps/api/geocode/json?address=";
    url += net::URI::urlEncode(cmd->address);
    url += "&sensor=false";

    RHO_MAP_TRACE1("GoogleGeoCoding: processCommand: url=%s", url.c_str());

    void *data;
    size_t datasize;
    if (!fetchData(url, &data, &datasize))
    {
        RAWLOG_ERROR1("Can not fetch data by url=%s", url.c_str());
        return;
    }

    RHO_MAP_TRACE("GoogleGeoCoding: processCommand: Parse received json...");

    double latitude, longitude;
    if (parse_json((const char *)data, &latitude, &longitude))
    {
        RHO_MAP_TRACE("GoogleGeoCoding: processCommand: json parsed successfully");
        cb.onSuccess(latitude, longitude);
    }
    else
    {
        RHO_MAP_TRACE("GoogleGeoCoding: processCommand: can't parse json");
        cb.onError("Can not parse JSON response");
    }
    /*
    char *error = 0;
    unsigned long json = rjson_tokener_parse((char const *)data, &error);
    if (!rho_ruby_is_NIL(json))
    {
        RHO_MAP_TRACE("GoogleGeoCoding: processCommand: extract coordinates from json...");
        unsigned long coords = rho_ruby_google_geocoding_get_coordinates(json);
        if (rho_ruby_is_NIL(coords))
        {
            RHO_MAP_TRACE("GoogleGeoCoding: processCommand: rho_ruby_google_geocoding_get_coordinates return nil");
            cb.onError("Cannot parse received JSON object");
        }
        else
        {
            RHO_MAP_TRACE("GoogleGeoCoding: processCommand: rho_ruby_google_geocoding_get_coordinates return coordinates");
            double latitude = rho_ruby_google_geocoding_get_latitude(coords);
            double longitude = rho_ruby_google_geocoding_get_longitude(coords);
            RHO_MAP_TRACE2("GoogleGeoCoding: processCommand: latitude=%lf, longitude=%lf", latitude, longitude);
            cb.onSuccess(latitude, longitude);
        }
    }
    else
    {
        RHO_MAP_TRACE("GoogleGeoCoding: processCommand: rjson_tokener_parse return nil");
        cb.onError(error);
    }

    if (error)
        free (error);
    */

    free(data);
}
Exemplo n.º 17
0
DrawingImageImpl::DrawingImageImpl(const char* path, bool useAlpha) {
	RHO_MAP_TRACE1("create DrawingImage with filename = %s", path);
	init(path, NULL, 0, NULL, useAlpha);
}
Exemplo n.º 18
0
DrawingImageImpl::DrawingImageImpl(void const *p, int size, bool useAlpha) {
	RHO_MAP_TRACE1("create DrawingImage with buffer length = %d", size);
	init(NULL, p, size, NULL, useAlpha);
}
Exemplo n.º 19
0
IDrawingImage* DrawingImageImpl::clone() {
	RHO_MAP_TRACE1("clone DrawingImage from ID = %d", mID);
	return new DrawingImageImpl(mBitmap);
}