mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
examples: GoogleMaps now using Core instead of Web
git-svn-id: svn://ultimatepp.org/upp/trunk@5384 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
7ed497eae9
commit
2581fcf102
2 changed files with 216 additions and 214 deletions
|
|
@ -1,177 +1,181 @@
|
||||||
#include "GoogleMaps.h"
|
#include "GoogleMaps.h"
|
||||||
|
|
||||||
using namespace Upp;
|
using namespace Upp;
|
||||||
|
|
||||||
#define LLOG(x) // LOG(x)
|
#define LLOG(x) // LOG(x)
|
||||||
|
|
||||||
String apikey = "";
|
String apikey = "";
|
||||||
|
|
||||||
void SetGoogleMapsKey(const char *key)
|
void SetGoogleMapsKey(const char *key)
|
||||||
{
|
{
|
||||||
apikey = key;
|
apikey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
String GetGoogleMap(double center_x, double center_y, int zoom, int cx, int cy,
|
String GetGoogleMap(double center_x, double center_y, int zoom, int cx, int cy,
|
||||||
const char *format, String *error)
|
const char *format, String *error)
|
||||||
{
|
{
|
||||||
String request;
|
String request;
|
||||||
request << "http://maps.google.com/maps/api/staticmap?center=" <<
|
request << "http://maps.google.com/maps/api/staticmap?center=" <<
|
||||||
AsString(center_y) << ',' << AsString(center_x) <<
|
AsString(center_y) << ',' << AsString(center_x) <<
|
||||||
"&zoom=" << zoom <<
|
"&zoom=" << zoom <<
|
||||||
"&size=" << cx << 'x' << cy <<
|
"&size=" << cx << 'x' << cy <<
|
||||||
"&format=" << format <<
|
"&format=" << format <<
|
||||||
"&sensor=false&key=" << apikey;
|
"&sensor=false&key=" << apikey;
|
||||||
return HttpClientGet(request, NULL, error);
|
HttpRequest r(request);
|
||||||
}
|
String h = r.Execute();
|
||||||
|
if(r.IsFailure())
|
||||||
Image GetGoogleMapImage(double center_x, double center_y, int zoom, int cx, int cy,
|
*error = r.GetErrorDesc();
|
||||||
const char *format, String *error)
|
return h;
|
||||||
{
|
}
|
||||||
return StreamRaster::LoadStringAny(GetGoogleMap(center_x, center_y, zoom, cx, cy, format, error));
|
|
||||||
}
|
Image GetGoogleMapImage(double center_x, double center_y, int zoom, int cx, int cy,
|
||||||
|
const char *format, String *error)
|
||||||
double CvDeg(double deg, double minutes, double seconds)
|
{
|
||||||
{
|
return StreamRaster::LoadStringAny(GetGoogleMap(center_x, center_y, zoom, cx, cy, format, error));
|
||||||
return deg + (double)minutes / 60 + seconds / 3600;
|
}
|
||||||
}
|
|
||||||
|
double CvDeg(double deg, double minutes, double seconds)
|
||||||
static void sFetch(double& a, double *x, int& ii)
|
{
|
||||||
{
|
return deg + (double)minutes / 60 + seconds / 3600;
|
||||||
a = CvDeg(x[0], x[1], x[2]);
|
}
|
||||||
ii = 0;
|
|
||||||
}
|
static void sFetch(double& a, double *x, int& ii)
|
||||||
|
{
|
||||||
int CharFilterH(int c)
|
a = CvDeg(x[0], x[1], x[2]);
|
||||||
{
|
ii = 0;
|
||||||
return c == 'e' || c == 'E' ? 'r' : c == '\'' || c == '\"' ? '@' : c;
|
}
|
||||||
}
|
|
||||||
|
int CharFilterH(int c)
|
||||||
Pointf ScanGPS(const char *s)
|
{
|
||||||
{
|
return c == 'e' || c == 'E' ? 'r' : c == '\'' || c == '\"' ? '@' : c;
|
||||||
String h = Filter(s, CharFilterH);
|
}
|
||||||
Pointf r = Null;
|
|
||||||
double x[3];
|
Pointf ScanGPS(const char *s)
|
||||||
CParser p(h);
|
{
|
||||||
x[0] = x[1] = x[2] = 0;
|
String h = Filter(s, CharFilterH);
|
||||||
int ii = 0;
|
Pointf r = Null;
|
||||||
while(!p.IsEof()) {
|
double x[3];
|
||||||
if(p.IsDouble()) {
|
CParser p(h);
|
||||||
if(ii < 3)
|
x[0] = x[1] = x[2] = 0;
|
||||||
x[ii++] = p.ReadDouble();
|
int ii = 0;
|
||||||
else {
|
while(!p.IsEof()) {
|
||||||
if(IsNull(r.y))
|
if(p.IsDouble()) {
|
||||||
sFetch(r.y, x, ii);
|
if(ii < 3)
|
||||||
else {
|
x[ii++] = p.ReadDouble();
|
||||||
sFetch(r.x, x, ii);
|
else {
|
||||||
break;
|
if(IsNull(r.y))
|
||||||
}
|
sFetch(r.y, x, ii);
|
||||||
x[ii++] = p.ReadDouble();
|
else {
|
||||||
}
|
sFetch(r.x, x, ii);
|
||||||
}
|
break;
|
||||||
else
|
}
|
||||||
if(p.Char('W') || p.Char('w')) {
|
x[ii++] = p.ReadDouble();
|
||||||
if(x[0] > 0)
|
}
|
||||||
x[0] = -x[0];
|
}
|
||||||
sFetch(r.x, x, ii);
|
else
|
||||||
}
|
if(p.Char('W') || p.Char('w')) {
|
||||||
else
|
if(x[0] > 0)
|
||||||
if(p.Char('r'))
|
x[0] = -x[0];
|
||||||
sFetch(r.x, x, ii);
|
sFetch(r.x, x, ii);
|
||||||
else
|
}
|
||||||
if(p.Char('S') || p.Char('s')) {
|
else
|
||||||
if(x[0] > 0)
|
if(p.Char('r'))
|
||||||
x[0] = -x[0];
|
sFetch(r.x, x, ii);
|
||||||
sFetch(r.y, x, ii);
|
else
|
||||||
}
|
if(p.Char('S') || p.Char('s')) {
|
||||||
else
|
if(x[0] > 0)
|
||||||
if(p.Char('N') || p.Char('n'))
|
x[0] = -x[0];
|
||||||
sFetch(r.y, x, ii);
|
sFetch(r.y, x, ii);
|
||||||
else
|
}
|
||||||
p.SkipTerm();
|
else
|
||||||
}
|
if(p.Char('N') || p.Char('n'))
|
||||||
if(!IsNull(r.y) && IsNull(r.x))
|
sFetch(r.y, x, ii);
|
||||||
sFetch(r.x, x, ii);
|
else
|
||||||
return r;
|
p.SkipTerm();
|
||||||
}
|
}
|
||||||
|
if(!IsNull(r.y) && IsNull(r.x))
|
||||||
String FormatDegree(double d, int decimals)
|
sFetch(r.x, x, ii);
|
||||||
{
|
return r;
|
||||||
if(IsNull(d))
|
}
|
||||||
return Null;
|
|
||||||
d = modulo(d + 180, 360) - 180;
|
String FormatDegree(double d, int decimals)
|
||||||
char sign = (d < 0 ? '-' : '+');
|
{
|
||||||
if(d < 0) d = -d;
|
if(IsNull(d))
|
||||||
int deg = ffloor(d);
|
return Null;
|
||||||
String cd = ToCharset(CHARSET_DEFAULT, "%c%d°", CHARSET_UTF8);
|
d = modulo(d + 180, 360) - 180;
|
||||||
if(decimals <= -2)
|
char sign = (d < 0 ? '-' : '+');
|
||||||
return NFormat(cd, sign, deg);
|
if(d < 0) d = -d;
|
||||||
d = (d - deg) * 60;
|
int deg = ffloor(d);
|
||||||
int min = ffloor(d);
|
String cd = ToCharset(CHARSET_DEFAULT, "%c%d°", CHARSET_UTF8);
|
||||||
if(decimals <= -1)
|
if(decimals <= -2)
|
||||||
return NFormat(cd + " %02d\'", sign, deg, min);
|
return NFormat(cd, sign, deg);
|
||||||
d = (d - min) * 60;
|
d = (d - deg) * 60;
|
||||||
String sec = FormatDoubleFix(d, decimals);
|
int min = ffloor(d);
|
||||||
if(!IsDigit(sec[1]))
|
if(decimals <= -1)
|
||||||
sec.Insert(0, '0');
|
return NFormat(cd + " %02d\'", sign, deg, min);
|
||||||
return NFormat(cd + " %02d\' %s\"", sign, deg, min, sec);
|
d = (d - min) * 60;
|
||||||
}
|
String sec = FormatDoubleFix(d, decimals);
|
||||||
|
if(!IsDigit(sec[1]))
|
||||||
String FormatGPSX(double x)
|
sec.Insert(0, '0');
|
||||||
{
|
return NFormat(cd + " %02d\' %s\"", sign, deg, min, sec);
|
||||||
return IsNull(x) ? String() : FormatDegree(x, 2) + (x < 0 ? "W" : "E");
|
}
|
||||||
}
|
|
||||||
|
String FormatGPSX(double x)
|
||||||
String FormatGPSY(double y)
|
{
|
||||||
{
|
return IsNull(x) ? String() : FormatDegree(x, 2) + (x < 0 ? "W" : "E");
|
||||||
return IsNull(y) ? String() : FormatDegree(y, 2) + (y < 0 ? "S" : "N");
|
}
|
||||||
}
|
|
||||||
|
String FormatGPSY(double y)
|
||||||
String FormatGPS(Pointf p)
|
{
|
||||||
{
|
return IsNull(y) ? String() : FormatDegree(y, 2) + (y < 0 ? "S" : "N");
|
||||||
return FormatGPSY(p.y) + ' ' + FormatGPSX(p.x);
|
}
|
||||||
}
|
|
||||||
|
String FormatGPS(Pointf p)
|
||||||
static const double sOffset = 268435456;
|
{
|
||||||
static const double sRadius = sOffset / M_PI;
|
return FormatGPSY(p.y) + ' ' + FormatGPSX(p.x);
|
||||||
|
}
|
||||||
static int LToX_(double x)
|
|
||||||
{
|
static const double sOffset = 268435456;
|
||||||
return int(sOffset + sRadius * x * M_PI / 180);
|
static const double sRadius = sOffset / M_PI;
|
||||||
}
|
|
||||||
|
static int LToX_(double x)
|
||||||
static int LToY_(double y)
|
{
|
||||||
{
|
return int(sOffset + sRadius * x * M_PI / 180);
|
||||||
return int(sOffset - sRadius * log((1 + sin(y * M_PI / 180))/(1 - sin( y * M_PI / 180))) / 2);
|
}
|
||||||
}
|
|
||||||
|
static int LToY_(double y)
|
||||||
static double XToL_(int x)
|
{
|
||||||
{
|
return int(sOffset - sRadius * log((1 + sin(y * M_PI / 180))/(1 - sin( y * M_PI / 180))) / 2);
|
||||||
return ((x - sOffset) / sRadius) * 180 / M_PI;
|
}
|
||||||
}
|
|
||||||
|
static double XToL_(int x)
|
||||||
static double YToL_(int y)
|
{
|
||||||
{
|
return ((x - sOffset) / sRadius) * 180 / M_PI;
|
||||||
return (M_PI / 2 - 2 * atan(exp((y - sOffset) / sRadius))) * 180 / M_PI;
|
}
|
||||||
}
|
|
||||||
|
static double YToL_(int y)
|
||||||
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Point diff)
|
{
|
||||||
{
|
return (M_PI / 2 - 2 * atan(exp((y - sOffset) / sRadius))) * 180 / M_PI;
|
||||||
return Pointf(XToL_(LToX_(center.x) + (diff.x << (21 - zoom))),
|
}
|
||||||
YToL_(LToY_(center.y) + (diff.y << (21 - zoom))));
|
|
||||||
}
|
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Point diff)
|
||||||
|
{
|
||||||
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Size sz, Point p)
|
return Pointf(XToL_(LToX_(center.x) + (diff.x << (21 - zoom))),
|
||||||
{
|
YToL_(LToY_(center.y) + (diff.y << (21 - zoom))));
|
||||||
return GoogleMapsPixelToGps(center, zoom, p - sz / 2);
|
}
|
||||||
}
|
|
||||||
|
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Size sz, Point p)
|
||||||
Pointf GoogleMapsGpsToPixelDiff(Pointf center, int zoom, Pointf gps)
|
{
|
||||||
{
|
return GoogleMapsPixelToGps(center, zoom, p - sz / 2);
|
||||||
return Pointf((LToX_(center.x) - LToX_(gps.x)) >> (21 - zoom),
|
}
|
||||||
(LToY_(center.y) - LToY_(gps.y)) >> (21 - zoom));
|
|
||||||
}
|
Pointf GoogleMapsGpsToPixelDiff(Pointf center, int zoom, Pointf gps)
|
||||||
|
{
|
||||||
Pointf GoogleMapsGpsToPixel(Pointf center, int zoom, Size sz, Pointf gps)
|
return Pointf((LToX_(center.x) - LToX_(gps.x)) >> (21 - zoom),
|
||||||
{
|
(LToY_(center.y) - LToY_(gps.y)) >> (21 - zoom));
|
||||||
return sz / 2 - GoogleMapsGpsToPixelDiff(center, zoom, gps);
|
}
|
||||||
}
|
|
||||||
|
Pointf GoogleMapsGpsToPixel(Pointf center, int zoom, Size sz, Pointf gps)
|
||||||
|
{
|
||||||
|
return sz / 2 - GoogleMapsGpsToPixelDiff(center, zoom, gps);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,35 @@
|
||||||
#ifndef _GoogleMaps_GoogleMaps_h
|
#ifndef _GoogleMaps_GoogleMaps_h
|
||||||
#define _GoogleMaps_GoogleMaps_h
|
#define _GoogleMaps_GoogleMaps_h
|
||||||
|
|
||||||
#include <CtrlLib/CtrlLib.h>
|
#include <CtrlLib/CtrlLib.h>
|
||||||
#include <Web/Web.h>
|
|
||||||
|
using namespace Upp;
|
||||||
|
|
||||||
using namespace Upp;
|
#define LAYOUTFILE <GoogleMaps/GoogleMaps.lay>
|
||||||
|
#include <CtrlCore/lay.h>
|
||||||
#define LAYOUTFILE <GoogleMaps/GoogleMaps.lay>
|
|
||||||
#include <CtrlCore/lay.h>
|
#define IMAGECLASS GoogleMapsImg
|
||||||
|
#define IMAGEFILE <GoogleMaps/GoogleMaps.iml>
|
||||||
#define IMAGECLASS GoogleMapsImg
|
#include <Draw/iml_header.h>
|
||||||
#define IMAGEFILE <GoogleMaps/GoogleMaps.iml>
|
|
||||||
#include <Draw/iml_header.h>
|
void SetGoogleMapsKey(const char *key);
|
||||||
|
String GetGoogleMap(double center_x, double center_y, int zoom, int cx, int cy,
|
||||||
void SetGoogleMapsKey(const char *key);
|
const char *format = "png", String *error = NULL);
|
||||||
String GetGoogleMap(double center_x, double center_y, int zoom, int cx, int cy,
|
Image GetGoogleMapImage(double center_x, double center_y, int zoom, int cx, int cy,
|
||||||
const char *format = "png", String *error = NULL);
|
const char *format = "png", String *error = NULL);
|
||||||
Image GetGoogleMapImage(double center_x, double center_y, int zoom, int cx, int cy,
|
double CvDeg(double deg, double minutes, double seconds);
|
||||||
const char *format = "png", String *error = NULL);
|
|
||||||
double CvDeg(double deg, double minutes, double seconds);
|
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Point diff);
|
||||||
|
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Size sz, Point p);
|
||||||
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Point diff);
|
Pointf GoogleMapsGpsToPixelDiff(Pointf center, int zoom, Pointf gps);
|
||||||
Pointf GoogleMapsPixelToGps(Pointf center, int zoom, Size sz, Point p);
|
Pointf GoogleMapsGpsToPixel(Pointf center, int zoom, Size sz, Pointf gps);
|
||||||
Pointf GoogleMapsGpsToPixelDiff(Pointf center, int zoom, Pointf gps);
|
|
||||||
Pointf GoogleMapsGpsToPixel(Pointf center, int zoom, Size sz, Pointf gps);
|
Pointf ScanGPS(const char *s);
|
||||||
|
|
||||||
Pointf ScanGPS(const char *s);
|
String FormatGPSX(double x);
|
||||||
|
String FormatGPSY(double y);
|
||||||
String FormatGPSX(double x);
|
String FormatGPS(Pointf p);
|
||||||
String FormatGPSY(double y);
|
|
||||||
String FormatGPS(Pointf p);
|
bool MapDlg(Pointf& p);
|
||||||
|
|
||||||
bool MapDlg(Pointf& p);
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue