Mercurial > pub > ImplabJs
annotate src/djol/WFSSource.js @ 24:f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
author | cin |
---|---|
date | Thu, 07 Dec 2017 19:19:29 +0300 |
parents | 67a5de7581ad |
children |
rev | line source |
---|---|
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
1 define([ |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
2 "ol", |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
3 "dojo/request", |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
4 "dojo/_base/array", |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
5 "implab/safe", |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
6 "implab/log/trace!" |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
7 ], function (ol, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
8 request, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
9 array, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
10 safe, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
11 trace |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
12 ) { |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
13 return function (wfs, featurePrefix, featureType, featureNS, queryArgs) { |
8 | 14 if (arguments.length == 1) { |
15 featurePrefix = wfs.featurePrefix; | |
16 featureType = wfs.featureType; | |
17 featureNS = wfs.featureNS; | |
18 wfs = wfs.wfsURL; | |
19 queryArgs = wfs.queryArgs; | |
20 } | |
21 | |
22 safe.argumentNotNull(wfs, "wfsURL"); | |
11 | 23 safe.argumentNotEmptyString(featurePrefix, "featurePrefix"); |
24 safe.argumentNotEmptyString(featureNS, "featureNS"); | |
25 safe.argumentNotEmptyString(featureType, "featureType"); | |
8 | 26 |
27 var format = new ol.format.WFS({ | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
28 featureNS: featureNS, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
29 featureType: featureType |
8 | 30 }); |
31 | |
32 var layerName = featurePrefix + ":" + featureType; | |
33 | |
34 function loader(extent, resolution, projection) { | |
35 var query = { | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
36 service: 'WFS', |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
37 version: '1.1.0', |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
38 request: 'GetFeature', |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
39 typename: layerName, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
40 srsname: projection.getCode() |
8 | 41 }; |
42 safe.mixin(query, queryArgs); | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
43 |
8 | 44 if (extent && isFinite(extent[0])) |
45 query.bbox = extent.join(',') + "," + projection.getCode(); | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
46 |
8 | 47 return request(wfs, { |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
48 query: query, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
49 handleAs: 'xml' |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
50 }).then(function (data) { |
8 | 51 // в загрузчике нельзя вызывать метод source.clear() поскольку |
52 // это приводит к рекурсии | |
53 var features = format.readFeatures(data); | |
54 | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
55 var map = {}, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
56 del = [], |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
57 add = []; |
8 | 58 |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
59 array.forEach(features, function (x) { |
8 | 60 // HACK исправляем идентификаторы, чтобы они совпадали с |
61 // реальными | |
62 | |
63 var id = x.get("id"); | |
64 if (id) | |
65 x.setId(id); | |
66 else | |
67 id = x.getId(); | |
68 | |
69 map[id] = x; | |
70 | |
71 // нужно проверить, была ли фича на карте | |
72 var prev = source.getFeatureById(id); | |
73 if (prev) { | |
74 // если да, то обновить ее. | |
75 var data = x.getProperties(); | |
76 prev.setProperties(data); | |
77 } else { | |
78 // иначе добавить | |
79 add.push(x); | |
80 } | |
81 }); | |
82 | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
83 source.forEachFeatureInExtent(extent, function (x) { |
8 | 84 if (!(x.getId() in map)) |
85 del.push(x); | |
86 }); | |
87 | |
88 source.addFeatures(add); | |
89 | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
90 array.forEach(del, function (x) { |
8 | 91 source.removeFeature(x); |
92 }); | |
93 | |
94 //revision = revision + 1; | |
95 | |
96 source.set("revision", ++revision); | |
97 | |
98 }); | |
99 } | |
100 | |
101 var cls = ol.source.ServerVector || ol.source.Vector; | |
102 var revision = 0; | |
103 var source = new cls({ | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
104 loader: loader, |
8 | 105 //revision: revision |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
106 wrapX: false |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
107 // , |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
108 // strategy : options.strategy || ol.loadingstrategy.all, |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
109 // projection : options.projection |
8 | 110 }); |
111 source.set("revision", revision); | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
112 source.reload = function (extent, resolution, projection, q) { |
8 | 113 if (arguments.length >= 4) |
114 queryArgs = q; | |
115 if (!extent) | |
116 extent = [-Infinity, -Infinity, Infinity, Infinity]; | |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
117 return loader(extent, resolution, projection); |
8 | 118 }; |
24
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
119 |
f750c89976d3
Added trace tools, implab/log/trace!<channel-name>, <channel-name> is optional
cin
parents:
11
diff
changeset
|
120 trace.log("{0} -> {1}", layerName, wfs); |
8 | 121 return source; |
122 }; | |
123 }); |