Repository: yagoferrer/map-tools
Pull request #189 (2015-02-28 20:46:22)

Fixes: #185


Patch:
diff --git a/examples/code.snippet/update.marker.snippet.html b/examples/code.snippet/update.marker.snippet.html
index acfcc72..7474d99 100644
--- a/examples/code.snippet/update.marker.snippet.html
+++ b/examples/code.snippet/update.marker.snippet.html
@@ -10,7 +10,7 @@
   }, {filters: ['cityName']});
 
   // Update Marker Using Crossfilter
-	var marker = map.markers.filter.cityName.filterExact('barcelona').top(1);
+  var marker = map.filterMarker({cityName: 'barcelona'}, {limit: 1});
 	map.updateMarker(marker, {move: 'drop'});
 
   // Using instance
diff --git a/examples/update.marker.html b/examples/update.marker.html
index 684e93e..ff6b98e 100644
--- a/examples/update.marker.html
+++ b/examples/update.marker.html
@@ -33,7 +33,7 @@
 				position: 'right center',
 				events: {
 					'.update-crossfilter click': function (e) {
-						var marker = map.markers.filter.cityName.filterExact('barcelona').top(1);
+						var marker = map.filterMarker({cityName: 'barcelona'}, {limit: 1});
 						map.updateMarker(marker, {move: 'drop'});
 						e.preventDefault();
 					},
diff --git a/lib/map-tools/filterFeature.js b/lib/map-tools/filter.js
similarity index 68%
rename from lib/map-tools/filterFeature.js
rename to lib/map-tools/filter.js
index 5f81f9a..5cbc939 100644
--- a/lib/map-tools/filterFeature.js
+++ b/lib/map-tools/filter.js
@@ -1,19 +1,18 @@
-'use strict';
-module.exports = function(global, that) {
 
+module.exports = function(global, that, type) {
 
   var orderLookup = {
     ASC: 'top',
     DESC: 'bottom'
   };
 
-  function filterFeature(args, options) {
+  function filter(args, options) {
 
     var order, limit;
     var dimension = Object.keys(args)[0];
     var query = args[dimension];
 
-    if (that.json.filter[dimension]) {
+    if (that[type].filter[dimension]) {
 
       order = (options && options.order && orderLookup[options.order]) ?
         orderLookup[options.order]
@@ -21,7 +20,7 @@ module.exports = function(global, that) {
 
       limit = (options && options.limit) ? options.limit : Infinity;
 
-      var result = that.json.filter[dimension].filter(query)[order](limit);
+      var result = that[type].filter[dimension].filter(query)[order](limit);
 
       if (limit == 1) {
         return result[0];
@@ -34,5 +33,5 @@ module.exports = function(global, that) {
 
   }
 
-  return filterFeature;
+  return filter;
 }
diff --git a/lib/map-tools/index.js b/lib/map-tools/index.js
index 93fb544..46ac050 100644
--- a/lib/map-tools/index.js
+++ b/lib/map-tools/index.js
@@ -16,7 +16,8 @@ module.exports = function (global) {
     this.updateFeature = require('map-tools/updateFeature')(global, that);
     this.addPanel = require('map-tools/addPanel')(global, that);
     this.updateMarker = require('map-tools/updateMarker')(global, that);
-    this.filterFeature = require('map-tools/filterFeature')(global, that);
+    this.filterFeature = require('map-tools/filter')(global, that, 'json');
+    this.filterMarker = require('map-tools/filter')(global, that, 'markers');
     this.addGroup = require('map-tools/groups')(global, that).addGroup;
     this.updateGroup = require('map-tools/groups')(global, that).updateGroup;
     this.updateMap = require('map-tools/updateMap')(global, that);


Test patch:
diff --git a/test/unit/filterFeature.Spec.js b/test/unit/filter.Spec.js
similarity index 91%
rename from test/unit/filterFeature.Spec.js
rename to test/unit/filter.Spec.js
index 658ac71..43320e9 100644
--- a/test/unit/filterFeature.Spec.js
+++ b/test/unit/filter.Spec.js
@@ -15,7 +15,7 @@ describe('Given the filterFeature Module', function () {
       }
     };
 
-    filterFeature = require('map-tools/filterFeature')({}, that);
+    filterFeature = require('map-tools/filter')({}, that, 'json');
   });
 
   it('should filter exact values', function () {