techiva / jquery-ui-map

Automatically exported from code.google.com/p/jquery-ui-map
0 stars 0 forks source link

feature request: search for multiple values at once #37

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Right now you can search for a single value, or a single value appearing in a 
list of values:

 $('#map_canvas').gmap('find', 'markers', { 'property': 'tags', 'value': 'foo', 'delimiter': ', '}, function(marker, isFound) { ... })

I would like to have an ability to search for multiple values in a single call. 
something like this:

 $('#map_canvas').gmap('find', 'markers', { 'property': 'tags', 'values': ['foo','bar','baz'] }, function(marker, isFound) { ... })

note that in my example call i set 'values' no 'value', also i provide an array 
of values which means i dont need to provide a delimiter. 

Also, the current code could benefit from using arrays instead of splitting a 
string. When you split a string, you get an array of strings back. but what if 
your tag was an integer? You could also drop the need for a delimiter if arrays 
were used.

Original issue reported on code.google.com by mi...@openmile.com on 15 Feb 2012 at 7:27

GoogleCodeExporter commented 8 years ago
I've been thinking of supporting multiple values but just haven't got the time 
to implement it. If you have time I could add you to the project :). 

Let's say you enter addMarker( {'foo': 'a|b|c' }), I would need to delimit that 
string to find e.g. *a* (find, markers, { property:foo, value:b, delimiter: | 
}). If you'd enter an array you would have to check that the property is an 
instance of array and skip the split. I guess you could expand that method more 
with other types. 

Original comment by johansalllarsson on 15 Feb 2012 at 8:00

GoogleCodeExporter commented 8 years ago
I wouldnt mind being a committer, if you want to add me use koryak at gmail - 
thats my personal email.

Also, what are your plans for replacing a,b,c,d,e with normal variable names? 
It will be much easier for me to add stuff if i can read the code faster ;)

Original comment by mi...@openmile.com on 15 Feb 2012 at 8:17

GoogleCodeExporter commented 8 years ago
Added. The trunk is updated with maintainable code :)

Original comment by johansalllarsson on 15 Feb 2012 at 8:21

GoogleCodeExporter commented 8 years ago
I did some rough coding 
find: function(ctx, options, callback) {
            var obj = this.get(ctx);

            for ( var property in obj ) {
                if ( obj.hasOwnProperty(property) ) {
                        console.log(options.values);
                        var isFound = false;
                        for ( var value in options.values ) {
                            var items = ( options.delimiter && typeof obj[property][options.property] === 'string' ) ? obj[property][options.property].split(options.delimiter) : obj[property][options.property];

                            if ( $.inArray(options.values[value], items) > -1 ) {
                                isFound = true;
                            }
                        }
                        if (isFound) {
                        console.log(obj[property][options.property]);
                        }
                        callback(obj[property], isFound, obj[property][options.property]);
                    //callback(obj[property], (( options.delimiter && obj[property][options.property] ) ? ( $.inArray(options.value, obj[property][options.property].split(options.delimiter)) > -1 ) : ( obj[property][options.property] === options.value )));
                }
            };
            return this;
        }
I guess you could start with that and see where you can refactor and make better

Original comment by johansalllarsson on 15 Feb 2012 at 8:33

GoogleCodeExporter commented 8 years ago

Original comment by johansalllarsson on 15 Feb 2012 at 8:44

GoogleCodeExporter commented 8 years ago

Original comment by johansalllarsson on 27 Mar 2012 at 8:33