Mercurial > pub > ImplabJs
view src/djol/VectorStoreQuery.js @ 23:1d72fddc319a
make eslint happy
author | cin |
---|---|
date | Wed, 06 Dec 2017 14:19:45 +0300 |
parents | f0035923ff3e |
children |
line wrap: on
line source
define([ "ol" ], function(ol) { function buildFilter(filter) { if (filter instanceof Function) return filter; if (filter) { var match = function(str) { return { test : function(x) { if (x === null || x === undefined) return false; return x.toString().startsWith(str); } }; }; for ( var p in filter) { if (typeof (filter[p]) == "string" && filter[p].endsWith("*")) filter[p] = match(filter[p].substr(0, filter[p].length)); } return function(ft) { for ( var p in filter) { if (filter[p] && filter[p].test ? !filter[p] .test(ft.get(p)) : ft.get(p) != filter[p]) return false; } return true; }; } throw new Error("Unsupported filter"); } /** * @constructor * @example * * <pre> * var store = new VectorStore({ * source : vectorSource * }); * * var req = new VectorStoreQuery({ * city : "Moscow" * }, [ 30, 50, 40, 60 ]); * * store.query(req).then(showResults); * </pre> */ return function(filter, extent) { var match = filter && buildFilter(filter); var query = function(ft) { if (extent) { var g = gt.getGeometry(); if (!g || !ol.extent.intersects(extent, g.getExtent())) return false; } return !match || match(ft); }; query.extent = extent; query.predicate = match; return query; }; });