Example #1
0
double getTileNumberX(float zoom, double longitude) {
    if (longitude == 180.) {
        return getPowZoom(zoom) - 1;
    }
    longitude = checkLongitude(longitude);
    return (longitude + 180.) / 360. * getPowZoom(zoom);
}
Example #2
0
double getTileNumberY(float zoom, double latitude) {
    latitude = checkLatitude(latitude);
    double eval = log(tan(toRadians(latitude)) + 1 / cos(toRadians(latitude)));
    if (isinf(eval) || isnan(eval)) {
        latitude = latitude < 0 ? -89.9 : 89.9;
        eval = log(tan(toRadians(latitude)) + 1 / cos(toRadians(latitude)));
    }
    double result = (1 - eval / M_PI) / 2 * getPowZoom(zoom);
    return result;
}
Example #3
0
double getLongitudeFromTile(float zoom, double x) {
    return x / getPowZoom(zoom) * 360.0 - 180.0;
}
Example #4
0
double getLatitudeFromTile(float zoom, double y) {
    int sign = y < 0 ? -1 : 1;
    double result = atan(sign*sinh(M_PI * (1 - 2 * y / getPowZoom(zoom)))) * 180. / M_PI;
    return result;
}
Example #5
0
void runSimpleRendering( string renderingFileName, string resourceDir, RenderingInfo* info) {
	SkColor defaultMapColor = SK_ColorLTGRAY;

	if (info->width > 10000 || info->height > 10000) {
		osmand_log_print(LOG_ERROR, "We don't rendering images more than 10000x10000 ");
		return;
	}

	osmand_log_print(LOG_INFO, "Rendering info bounds(%d, %d, %d, %d) zoom(%d), width/height(%d/%d) tilewidth/tileheight(%d/%d) fileName(%s)",
			info->left, info->top, info->right, info->bottom, info->zoom, info->width, info->height, info->tileWX, info->tileHY, info->tileFileName.c_str());
	RenderingRulesStorage* st = new RenderingRulesStorage(renderingFileName.c_str());
	st->parseRulesFromXmlInputStream(renderingFileName.c_str(), NULL);
	RenderingRuleSearchRequest* searchRequest = new RenderingRuleSearchRequest(st);
	ResultPublisher* publisher = new ResultPublisher();
	SearchQuery q(floor(info->left), floor(info->right), ceil(info->top), ceil(info->bottom), searchRequest, publisher);
	q.zoom = info->zoom;

	ResultPublisher* res = searchObjectsForRendering(&q, true, "Nothing found");
	osmand_log_print(LOG_INFO, "Found %d objects", res->result.size());

	SkBitmap* bitmap = new SkBitmap();
	bitmap->setConfig(SkBitmap::kRGB_565_Config, info->width, info->height);

	size_t bitmapDataSize = bitmap->getSize();
	void* bitmapData = malloc(bitmapDataSize);
	bitmap->setPixels(bitmapData);

	osmand_log_print(LOG_INFO, "Initializing rendering style and rendering context");
	ElapsedTimer initObjects;
	initObjects.start();

	RenderingContext rc;
	rc.setDefaultIconsDir(resourceDir);
	searchRequest->clearState();
	searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
	if (searchRequest->searchRenderingAttribute(A_DEFAULT_COLOR)) {
		defaultMapColor = searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_COLOR_VALUE);
	}
	searchRequest->clearState();
	searchRequest->setIntFilter(st->PROPS.R_MINZOOM, info->zoom);
	if (searchRequest->searchRenderingAttribute(A_SHADOW_RENDERING)) {
		rc.setShadowRenderingMode(searchRequest->getIntPropertyValue(searchRequest->props()->R_ATTR_INT_VALUE));
		//rc.setShadowRenderingColor(searchRequest->getIntPropertyValue(searchRequest->props()->R_SHADOW_COLOR));
	}
	rc.setLocation(
			((double)info->left)/getPowZoom(31-info->zoom),
			((double)info->top)/getPowZoom(31-info->zoom)
			);
	rc.setDimension(info->width, info->height);
	rc.setZoom(info->zoom);
	rc.setRotate(0);
	rc.setDensityScale(1);
	osmand_log_print(LOG_INFO, "Rendering image");
	initObjects.pause();
	SkCanvas* canvas = new SkCanvas(*bitmap);
	canvas->drawColor(defaultMapColor);
	doRendering(res->result, canvas, searchRequest, &rc);
	osmand_log_print(LOG_INFO, "End Rendering image");
	osmand_log_print(LOG_INFO, "Native ok (init %d, rendering %d) ", initObjects.getElapsedTime(),
			rc.nativeOperations.getElapsedTime());
	SkImageEncoder* enc = SkImageEncoder::Create(SkImageEncoder::kPNG_Type);
	if (enc != NULL && !enc->encodeFile(info->tileFileName.c_str(), *bitmap, 100)) {
		osmand_log_print(LOG_ERROR, "FAIL to save tile to %s", info->tileFileName.c_str());
	} else {
		osmand_log_print(LOG_INFO, "Tile successfully saved to %s", info->tileFileName.c_str());
	}
	delete enc;
	delete publisher;
	delete searchRequest;
	delete st;
	delete canvas;
	delete bitmap;
	free(bitmapData);
	return;
}