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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
14 if (arguments.length == 1) {
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
15 featurePrefix = wfs.featurePrefix;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
16 featureType = wfs.featureType;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
17 featureNS = wfs.featureNS;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
18 wfs = wfs.wfsURL;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
19 queryArgs = wfs.queryArgs;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
20 }
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
21
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
22 safe.argumentNotNull(wfs, "wfsURL");
11
67a5de7581ad fixed typo in djol/WFSSource
cin
parents: 8
diff changeset
23 safe.argumentNotEmptyString(featurePrefix, "featurePrefix");
67a5de7581ad fixed typo in djol/WFSSource
cin
parents: 8
diff changeset
24 safe.argumentNotEmptyString(featureNS, "featureNS");
67a5de7581ad fixed typo in djol/WFSSource
cin
parents: 8
diff changeset
25 safe.argumentNotEmptyString(featureType, "featureType");
8
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
26
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
30 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
31
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
32 var layerName = featurePrefix + ":" + featureType;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
33
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
34 function loader(extent, resolution, projection) {
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
41 };
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
44 if (extent && isFinite(extent[0]))
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
51 // в загрузчике нельзя вызывать метод source.clear() поскольку
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
52 // это приводит к рекурсии
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
53 var features = format.readFeatures(data);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
60 // HACK исправляем идентификаторы, чтобы они совпадали с
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
61 // реальными
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
62
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
63 var id = x.get("id");
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
64 if (id)
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
65 x.setId(id);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
66 else
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
67 id = x.getId();
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
68
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
69 map[id] = x;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
70
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
71 // нужно проверить, была ли фича на карте
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
72 var prev = source.getFeatureById(id);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
73 if (prev) {
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
74 // если да, то обновить ее.
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
75 var data = x.getProperties();
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
76 prev.setProperties(data);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
77 } else {
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
78 // иначе добавить
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
79 add.push(x);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
80 }
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
81 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
84 if (!(x.getId() in map))
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
85 del.push(x);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
86 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
87
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
88 source.addFeatures(add);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
91 source.removeFeature(x);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
92 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
93
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
94 //revision = revision + 1;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
95
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
96 source.set("revision", ++revision);
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
97
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
98 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
99 }
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
100
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
101 var cls = ol.source.ServerVector || ol.source.Vector;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
102 var revision = 0;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
110 });
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
113 if (arguments.length >= 4)
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
114 queryArgs = q;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
115 if (!extent)
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
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
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
121 return source;
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
122 };
f0035923ff3e добавлена библиотека для работы с openlayers 3+
cin
parents:
diff changeset
123 });