forked from Esri/node-geoservices-adaptor
-
Notifications
You must be signed in to change notification settings - Fork 1
/
simple-data-source.js
192 lines (181 loc) · 7.18 KB
/
simple-data-source.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
var dataproviderbase = require('../lib/dataproviderbase'),
UTIL = require('util'),
FILE = require('fs')
SimpleDataSource = function() {
SimpleDataSource.super_.call(this)
this._isReady = true
this._devMode = true
}
UTIL.inherits(SimpleDataSource, dataproviderbase.DataProviderBase)
Object.defineProperties(SimpleDataSource.prototype, {
name: {
// SimpleDataSource.getName()
// Each DataProvider will be mounted on a route with this name
get: function() {
// Override the service name - every data provider should override this.
return "simple-data-server";
}
},
isReady: {
// SimpleDataSource.getIsReady()
// For a data provider with a long-running startup process, isReady
// is used to defer any requests until the startup is complete.
get: function() {
return this._isReady;
}
},
getServiceIds: {
// SimpleDataSource.getServiceIds()
// Pass an array of your Service Names to the callback
// The service name is used to describe each ArcGIS Feature Service
// and will produce an endpoint such as /rest/services/<ServiceName>
value: function(callback) {
callback(['MyFirstService', 'MySecondService'])
}
},
getServiceName: {
// SimpleDataSource.getServiceName(serviceId)
// Returns the Friendly Name corresponing to the serviceId
// Typically the name is the same as the serviceId
value: function(serviceId) {
return serviceId;
}
},
getLayerIds: {
// SimpleDataSource.getLayerIds()
// Pass an array of your Layer IDs to the callback.
// The LayerIds are typically a numeric list of layers in the services
// The layer id is used to describe each ArcGIS Feature Service's Layer
// and will produce an endpoint such as /rest/services/<ServiceName>/FeatureServer/<LayerID>
value: function(serviceId, callback) {
callback([0,1])
}
},
getLayerName: {
// SimpleDataSource.getLayerName()
// Returns the Friendly Name corresponding to the LayerId
value: function(serviceId, layerId) {
return ['Simple Layer','The Same Simple Layer'][layerId]
}
},
idField: {
// SimpleDataSource.idField()
// Each feature must have an attribute that corresponds to a
// unique key for the feature. Return the name of the field that
// will be used as the ID for this layer.
value: function(serviceId, layerId) {
return "id";
}
},
nameField: {
// SimpleDataSource.nameField()
// Each feature must have an attribute that corresponds to a
// friendly name for the feature. Return the name of the field that
// will be used as the feature name for this layer.
value: function(serviceId, layerId) {
return "name";
}
},
fields: {
// SimpleDataSource.fields()
// The list of attribute names and types that exist on this layer.
value: function(serviceId, layerId) {
return [
{"name" : "id", "type" : "esriFieldTypeInteger", "alias" : "ID", "nullable" : "true"},
{"name" : "name", "type" : "esriFieldTypeString", "alias" : "Name", "length" : "255", "nullable" : "true"}
]
}
},
geometryType: {
// SimpleDataSource.geometryType()
// The geometry type for this layer. Must be one of: -
// esriGeometryPolygon
// esriGeometryPolyline
// esriGeometryPoint
value: function(serviceId, layerId) {
return "esriGeometryPolygon"
}
},
featuresForQuery: {
// SimpleDataSource.featuresForQuery()
// This is where the FeatureServer data for this layer gets
// returned to the API.
//
// The callback requires the following parameters: -
// . array of feature objects
// . name of the unique ID attribute for the layer
// . array of the attribute definitions for this layer
//
// The 'query' parameter will contain the definition for which
// features should be returned. The query object has the following
// attributes, all of which are optional. It is up to the developer
// of the DataProvider whether these are respected by the call.
// . where - an SQL where clauses
// . objectIds - an array of IDs
// . inSR - input spatial reference for query by geometry
// . outSR - output spatial reference for returned features
// . geometry - provides an area to return features
// . geometryType - only supports esriGeometryEnvelope and esriGeometryPoint
// . spatialRel - the relationship for the geometry query
// . time - time for the data
// . outFields - an array of attribute names to return or '*'
// . returnGeometry - boolean should return the geometry with each feature
// . returnIdsOnly - boolean to only return array of ID of matching features
// . returnCountOnly - boolean to only retun the count of matching features
value: function(serviceId, layerId, query, callback) {
console.log('NOTE: This example does not use query where clause, outFields etc')
return callback(require('./simple-data-features.json').features,
this.idField(serviceId, layerId),
this.fields(serviceId, layerId))
}
},
getFeatureServiceDetails: {
// SimpleDataSource.getFeatureServiceDetails
// The callback requires a list of all layer IDs and Names
// Can also optionally add attributes to the detailsTemplate object
// . detailsTemplate.initialExtent
// . detailsTemplate.serviceDescription
// . detailsTemplate.supportedQueryFormats
// . detailsTemplate.maxRecordCount
// . detailsTemplate.description
// . detailsTemplate.copyrightText
// . detailsTemplate.fullExtent
value: function(detailsTemplate, serviceId, callback) {
detailsTemplate.initialExtent = require('./simple-data-features.json').extent
detailsTemplate.fullExtent = detailsTemplate.initialExtent
this.getLayerIds(serviceId, (function(layerIds, err) {
callback(layerIds, this.getLayerNamesForIds(serviceId, layerIds), err);
}).bind(this));
}
},
getFeatureServiceLayerDetails: {
// SimpleDataSource.getFeatureServiceLayerDetails
// The callback takes an object with the following attributes: -
// {
// layerName: "friendly name of this layer",
// idField: "name of the ID attribute for this layer",
// nameField: "name of the Name attribute for this layer",
// fields: [ "array of field definitions" ],
// geometryType: "theGeometryType"
// }
// Can also optionally add attributes to the detailsTemplate object
// . detailsTemplate.displayField
// . detailsTemplate.description
// . detailsTemplate.minScale
// . detailsTemplate.maxScale
// . detailsTemplate.maxRecordCount
// . detailsTemplate.copyrightText
// . detailsTemplate.extent
value: function(detailsTemplate, serviceId, layerId, callback) {
detailsTemplate.extent = require('./simple-data-features.json').extent
callback({
layerName: this.getLayerName(serviceId, layerId),
idField: this.idField(serviceId, layerId),
nameField: this.nameField(serviceId, layerId),
fields: this.fields(serviceId, layerId),
geometryType: this.geometryType()
}, null);
}
}
});
exports.SimpleDataSource = SimpleDataSource