Mercurial > pub > ImplabJs
comparison src/djol/VectorStoreQuery.js @ 8:f0035923ff3e
добавлена библиотека для работы с openlayers 3+
author | cin |
---|---|
date | Mon, 21 Aug 2017 17:47:00 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:9c0943c68a90 | 8:f0035923ff3e |
---|---|
1 define([ "ol" ], function(ol) { | |
2 | |
3 function buildFilter(filter) { | |
4 if (filter instanceof Function) | |
5 return filter; | |
6 if (filter) { | |
7 var match = function(str) { | |
8 return { | |
9 test : function(x) { | |
10 if (x === null || x === undefined) | |
11 return false; | |
12 return x.toString().startsWith(str); | |
13 } | |
14 }; | |
15 }; | |
16 | |
17 for ( var p in filter) { | |
18 if (typeof (filter[p]) == "string" && filter[p].endsWith("*")) | |
19 filter[p] = match(filter[p].substr(0, filter[p].length)); | |
20 } | |
21 return function(ft) { | |
22 for ( var p in filter) { | |
23 if (filter[p] && filter[p].test ? !filter[p] | |
24 .test(ft.get(p)) : ft.get(p) != filter[p]) | |
25 return false; | |
26 } | |
27 return true; | |
28 }; | |
29 } | |
30 throw new Error("Unsupported filter"); | |
31 } | |
32 | |
33 /** | |
34 * @constructor | |
35 * @example | |
36 * | |
37 * <pre> | |
38 * var store = new VectorStore({ | |
39 * source : vectorSource | |
40 * }); | |
41 * | |
42 * var req = new VectorStoreQuery({ | |
43 * city : "Moscow" | |
44 * }, [ 30, 50, 40, 60 ]); | |
45 * | |
46 * store.query(req).then(showResults); | |
47 * </pre> | |
48 */ | |
49 return function(filter, extent) { | |
50 var match = filter && buildFilter(filter); | |
51 | |
52 var query = function(ft) { | |
53 if (extent) { | |
54 var g = gt.getGeometry(); | |
55 if (!g || !ol.extent.intersects(extent, g.getExtent())) | |
56 return false; | |
57 } | |
58 | |
59 return !match || match(ft); | |
60 }; | |
61 | |
62 query.extent = extent; | |
63 query.predicate = match; | |
64 | |
65 return query; | |
66 }; | |
67 }); |