Fix:data_binfile:Fixed a few search bugs
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 31 May 2008 18:50:32 +0000 (18:50 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 31 May 2008 18:50:32 +0000 (18:50 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@1092 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/data/binfile/binfile.c
navit/navit/map.c
navit/navit/map.h
navit/navit/mapset.c

index 51508cc..96cb3a1 100644 (file)
@@ -471,6 +471,10 @@ binmap_search_new(struct map_priv *map, struct item *item, struct attr *search,
                case attr_town_postal:
                        break;
                case attr_street_name:
+                       if (! item->map)
+                               break;
+                       if (!map_priv_is(item->map, map))
+                               break;
                        ms = g_new(struct map_selection, 1);
                        ms->next = NULL;
                        for (i = 0; i < layer_end; i++)
@@ -488,10 +492,10 @@ binmap_search_new(struct map_priv *map, struct item *item, struct attr *search,
                                                size = 10000;
                                                break;
                                        case type_town_label_2e4:
-                                               size = 2500;
+                                               size = 5000;
                                                break;
                                        case type_town_label_2e3:
-                                               size = 1000;
+                                               size = 2500;
                                                break;
                                        case type_town_label_2e2:
                                                size = 1000;
@@ -547,9 +551,11 @@ binmap_search_get_item(struct map_search_priv *map_search)
                } else if (map_search->search->type == attr_street_name) {
                        if ((it->type == type_street_3_city) || (it->type == type_street_2_city) || (it->type == type_street_1_city)) {
                                struct attr at;
-                               if (binfile_attr_get(it->priv_data, attr_label, &at)) {
+                               if (map_selection_contains_item_rect(map_search->mr->sel, it) && binfile_attr_get(it->priv_data, attr_label, &at)) {
                                        if (!ascii_cmp(at.u.str, map_search->search->u.str, map_search->partial)) {
                                                if (!g_hash_table_lookup(map_search->search_results, at.u.str)) {
+                                                       item_coord_rewind(it);
+                                                       item_attr_rewind(it);
                                                        g_hash_table_insert(map_search->search_results, g_strdup(at.u.str), "");
                                                        return it;
                                                }
index a5198df..5c58132 100644 (file)
@@ -184,6 +184,10 @@ map_search_new(struct map *m, struct item *item, struct attr *search_attr, int p
                        if (m->meth.charset) 
                                this_->search_attr.u.str=g_convert(this_->search_attr.u.str, -1,m->meth.charset,"utf-8",NULL,NULL,NULL);
                        this_->priv=m->meth.map_search_new(m->priv, item, &this_->search_attr, partial);
+                       if (! this_->priv) {
+                               g_free(this_);
+                               this_=NULL;
+                       }
                } else {
                        g_free(this_);
                        this_=NULL;
@@ -248,3 +252,30 @@ map_selection_destroy(struct map_selection *sel)
                sel = next;
        }
 }
+
+int
+map_selection_contains_item_rect(struct map_selection *sel, struct item *item)
+{
+       struct coord c;
+       struct coord_rect r;
+       int count=0;
+       while (item_coord_get(item, &c, 1)) {
+               if (! count) {
+                       r.lu=c;
+                       r.rl=c;
+               } else 
+                       coord_rect_extend(&r, &c);
+               count++;
+       }
+       if (! count)
+               return 0;
+       return map_selection_contains_rect(sel, &r);
+       
+}
+
+
+int
+map_priv_is(struct map *map, struct map_priv *priv)
+{
+       return (map->priv == priv);
+}
index 1dcc28b..3cf5d6d 100644 (file)
@@ -152,6 +152,8 @@ struct item *map_search_get_item(struct map_search *this_);
 void map_search_destroy(struct map_search *this_);
 struct map_selection *map_selection_dup(struct map_selection *sel);
 void map_selection_destroy(struct map_selection *sel);
+int map_selection_contains_item_rect(struct map_selection *sel, struct item *item);
+int map_priv_is(struct map *map, struct map_priv *priv);
 /* end of prototypes */
 
 #endif
index 5c805cb..1d610e0 100644 (file)
@@ -97,8 +97,8 @@ mapset_search_new(struct mapset *ms, struct item *item, struct attr *search_attr
 struct item *
 mapset_search_get_item(struct mapset_search *this)
 {
-       struct item *ret;
-       while (!(ret=map_search_get_item(this->ms))) {
+       struct item *ret=NULL;
+       while (!this->ms || !(ret=map_search_get_item(this->ms))) {
                if (this->search_attr->type >= attr_country_all && this->search_attr->type <= attr_country_name)
                        break;
                do {
@@ -115,6 +115,8 @@ mapset_search_get_item(struct mapset_search *this)
 void
 mapset_search_destroy(struct mapset_search *this)
 {
-       map_search_destroy(this->ms);
-       g_free(this);
+       if (this) {
+               map_search_destroy(this->ms);
+               g_free(this);
+       }
 }