Diff of /trunk/src/project.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 221 by harbaum, Mon Jul 13 14:29:58 2009 UTC revision 222 by harbaum, Mon Jul 13 20:13:07 2009 UTC
# Line 57  static gboolean project_edit(appdata_t * Line 57  static gboolean project_edit(appdata_t *
57    
58  /* ------------ project file io ------------- */  /* ------------ project file io ------------- */
59    
60    /* Limit a proposed zoom factor to sane ranges.
61     * Specifically the map is allowed to be no smaller than the viewport.
62     * This function has a counterpart in map_limit_zoom()
63    */
64    
65    static gdouble project_limit_zoom(project_t *project, map_t *map) {
66      bounds_t bounds;
67    
68      gdouble zoom = 0.25;
69    
70      /* calculate map zone which will be used as a reference for all */
71      /* drawing/projection later on */
72      pos_t center = { (project->max.lat + project->min.lat)/2,
73                       (project->max.lon + project->min.lon)/2 };
74    
75      pos2lpos_center(&center, &bounds.center);
76    
77      /* the scale is needed to accomodate for "streching" */
78      /* by the mercartor projection */
79      bounds.scale = cos(DEG2RAD(center.lat));
80    
81      pos2lpos_center(&project->min, &bounds.min);
82      bounds.min.x -= bounds.center.x;
83      bounds.min.y -= bounds.center.y;
84      bounds.min.x *= bounds.scale;
85      bounds.min.y *= bounds.scale;
86    
87      pos2lpos_center(&project->max, &bounds.max);
88      bounds.max.x -= bounds.center.x;
89      bounds.max.y -= bounds.center.y;
90      bounds.max.x *= bounds.scale;
91      bounds.max.y *= bounds.scale;
92    
93      // Data rect minimum and maximum
94      gint min_x, min_y, max_x, max_y;
95      min_y = bounds.min.y;
96      max_y = bounds.max.y;
97    
98      printf("min %d %d max %d %d\n", min_x, min_y, max_x, max_y);
99    
100      /* get size of visible area in pixels and convert to meters of intended */
101      /* zoom by deviding by zoom (which is basically pix/m) */
102      gint aw_cu =
103        canvas_get_viewport_width(map->canvas, CANVAS_UNIT_PIXEL) / zoom;
104      gint ah_cu =
105        canvas_get_viewport_height(map->canvas, CANVAS_UNIT_PIXEL) / zoom;
106    
107      if (ah_cu < aw_cu) {
108        gint lim_h = ah_cu*0.95;
109        if (max_y-min_y < lim_h) {
110          gdouble corr = ((gdouble)max_y-min_y) / (gdouble)lim_h;
111          zoom /= corr;
112        }
113      }
114      else {
115        gint lim_w = aw_cu*0.95;
116        if (bounds.max.x-bounds.min.x < lim_w) {
117          gdouble corr = ((gdouble)bounds.max.x-bounds.min.x) / (gdouble)lim_w;
118          zoom /= corr;
119        }
120      }
121      return zoom;
122    }
123    
124  static gboolean project_read(appdata_t *appdata,  static gboolean project_read(appdata_t *appdata,
125               char *project_file, project_t *project) {               char *project_file, project_t *project) {
126      gboolean found_map_entry = FALSE;
127    
128    LIBXML_TEST_VERSION;    LIBXML_TEST_VERSION;
129    
# Line 105  static gboolean project_read(appdata_t * Line 170  static gboolean project_read(appdata_t *
170    
171              } else if(project->map_state &&              } else if(project->map_state &&
172                        strcasecmp((char*)node->name, "map") == 0) {                        strcasecmp((char*)node->name, "map") == 0) {
173                  found_map_entry = TRUE;
174    
175                if((str = (char*)xmlGetProp(node, BAD_CAST "zoom"))) {                if((str = (char*)xmlGetProp(node, BAD_CAST "zoom"))) {
176                  project->map_state->zoom = g_ascii_strtod(str, NULL);                  project->map_state->zoom = g_ascii_strtod(str, NULL);
177                  xmlFree(str);                  xmlFree(str);
# Line 185  static gboolean project_read(appdata_t * Line 252  static gboolean project_read(appdata_t *
252        }        }
253      }      }
254    }    }
255    
256      if(!found_map_entry && project->map_state) {
257        printf("loaded project w/o map entry\n");
258    
259        printf("map size = %d x %d\n",
260               appdata->map->canvas->widget->allocation.width/2,
261               appdata->map->canvas->widget->allocation.height/2);
262    
263        gdouble pix_per_meter = project_limit_zoom(project, appdata->map);
264        printf("pix per meter = %f\n", pix_per_meter);
265    
266        //    printf("scroll = %f x %f\n",
267        //     appdata->map->canvas->widget->allocation.width/2/pix_per_meter,
268        //     appdata->map->canvas->widget->allocation.height/2/pix_per_meter);
269    
270        // scroll-offset-x="-1089" scroll-offset-y="-802"/>
271    
272        project->map_state->scroll_offset.x = 1000;
273        project->map_state->scroll_offset.y = 1000;
274      }
275    
276    xmlFreeDoc(doc);    xmlFreeDoc(doc);
277    xmlCleanupParser();    xmlCleanupParser();
278    

Legend:
Removed from v.221  
changed lines
  Added in v.222