summaryrefslogtreecommitdiffstats
path: root/friendfinder/map/smart_map_priv.h
blob: d40e8477fad2a65a6269cd16832bc0fba56c2109 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifndef _SMART_MAP_PRIV_H_
#define _SMART_MAP_PRIV_H_

struct map_level_info
{
	int min_x;
	int max_x;
	int min_y;
	int max_y;

	double north, south, west, east;
	double dx, dy, e0, n0;
};

struct map_info
{
	char *path;
	struct map_level_info *level;
	int min_level;
	int max_level;
	int tile_size;
};

#include <Evas.h>

struct smart_map;
struct controls
{
	Evas_Object *bt;
	Evas_Object *bx;
	Evas_Object *vkbd;
	Evas_Object *ctrl;
};

struct overlay_level_data
{
	int ox, oy;
	int visible:1;
};

struct overlay_object
{
	Evas_Object *obj;
	int ox;
	int oy;
	int sw, sh;
};

struct overlay_item 
{
	struct overlay_object *obj;
	double lat, lon;
	unsigned int level_mask;
	struct overlay_level_data level_data;
};

#define OSM_LEVEL_COUNT 19

#include "e_smart_tile.h"
struct smart_map
{
	Evas_Object *obj;
	Evas_Object *clip;
	Evas_Object *theme;
	Evas_Coord x, y, w, h;

	Evas *evas;
	Evas_Object *win;
	struct controls c;
	Eina_Array *overlays;
	Eina_Array *paths;

	struct map_info *mi;
	struct map_level_info *li;
	int current_level;

	struct tile_array ta;
	double lat;
	double lon;

	int moved;	
	int drag;
};

enum {
	OVERLAY_HIDDEN,
	OVERLAY_VISIBLE
};

struct map_overlay
{
	struct smart_map *parent;
	char *name;
	Eina_Hash *hash;
	Eina_Array *pois[OSM_LEVEL_COUNT];
	int current_level;
	int state;
};

enum {
	POSITION_WORLD,
	POSITION_PX,
	NUM_POSITION,
};

struct map_info *map_info_read(const char *path);
int map_object_update(struct smart_map *smart);
int controls_init(struct smart_map *smart);

struct map_overlay *overlay_create(struct smart_map *smart, char *name);
void overlay_update(struct smart_map *smart, struct osm_data *, int xoff, int yoff);
void overlay_unload(struct smart_map *smart, struct osm_data *osm);
void overlay_change_level(struct smart_map *smart, int level);
void overlay_add(struct smart_map *smart, struct map_overlay *ov, struct overlay_item *poi);
struct map_overlay *overlay_find_by_name(struct smart_map *smart, char *name);
void overlay_hide(struct smart_map *smart, char *name);
void overlay_hide_all(struct smart_map *smart);

static inline struct map_level_info *
map_info_get_level(struct map_info *map, int* z)
{
	if(*z < map->min_level || *z > map->max_level)
		*z = (map->min_level + map->max_level) / 2 ;

	return &map->level[*z - map->min_level];
}

#include <limits.h>
#include "../util/projection.h"
static inline int
latlon_to_map(struct map_level_info *level, double lat, double lon, int *x, int *y)
{
	if(level == NULL)
		return -1;

	int e = INT_MAX, n = INT_MAX;
	double e0 = level->e0;
	double n0 = level->n0;
	double dx = level->dx;
	double dy = level->dy;
			
	project_latlon(lat, lon, &e, &n, PROJECTION_MERC); 
	*x = (e - e0) / dx;
	*y = (n0 - n) / dy;
	return 0;
}

static inline int
map_to_latlon(struct map_level_info *level, int x, int y, double *lat, double *lon)
{
	int e, n;

	if(level == NULL)
		return -1;

	double e0 = level->e0;
	double n0 = level->n0;
	double dx = level->dx;
	double dy = level->dy;
	
	e = e0 + x * dx;
	n = -(y * dy - n0);
	project_latlon_inv(e, n, lat, lon, PROJECTION_MERC);
	return 0;
}
#endif