@@ -2,6 +2,7 @@ import 'dart:convert';
2
2
import 'package:dart_hydrologis_utils/dart_hydrologis_utils.dart' ;
3
3
import 'package:http/http.dart' ;
4
4
import 'package:smash_import_export_plugins/smash_import_export_plugins.dart' ;
5
+ import 'package:smashlibs/com/hydrologis/flutterlibs/utils/logging.dart' ;
5
6
import 'dart:typed_data' ;
6
7
7
8
import 'package:smashlibs/smashlibs.dart' ;
@@ -232,6 +233,82 @@ class ServerApi {
232
233
throw new StateError (response.body);
233
234
}
234
235
}
236
+
237
+ static const LAYERSKEY_URL = 'url' ;
238
+ static const LAYERSKEY_TYPE = 'type' ;
239
+ static const LAYERSKEY_FORMAT = 'format' ;
240
+ static const LAYERSKEY_LABEL = 'label' ;
241
+ static const LAYERSKEY_SRID = 'srid' ;
242
+ static const LAYERSKEY_ISVISIBLE = 'isvisible' ;
243
+ static const LAYERSKEY_OPACITY = 'opacity' ;
244
+ static const LAYERSKEY_WMSVERSION = 'wmsversion' ;
245
+ static const LAYERSKEY_ATTRIBUTION = 'attribution' ;
246
+ static const LAYERSKEY_SUBDOMAINS = 'subdomains' ;
247
+ static const LAYERSKEY_MINZOOM = 'minzoom' ;
248
+ static const LAYERSKEY_MAXZOOM = 'maxzoom' ;
249
+
250
+ static Future <Map <String , List <String >>> getBackGroundLayers () async {
251
+ var tokenHeader = getTokenHeader ();
252
+ Project ? project = getCurrentGssProject ();
253
+ if (project == null ) {
254
+ throw StateError ("No project was selected." );
255
+ }
256
+ Map <String , List <String >> layers = {"WMS" : [], "TMS" : []};
257
+
258
+ try {
259
+ var uri = Uri .parse (
260
+ getBaseUrl () + API_WMSSOURCES + "?$API_PROJECT_PARAM ${project .id }" );
261
+ var response = await get (uri, headers: tokenHeader);
262
+ if (response.statusCode == 200 ) {
263
+ var list = jsonDecode (response.body);
264
+ for (var item in list) {
265
+ var json = '''
266
+ {
267
+ "$LAYERSKEY_LABEL ": "${item ['layername' ]}",
268
+ "$LAYERSKEY_URL ":"${item ['getcapabilities' ]}",
269
+ "$LAYERSKEY_ISVISIBLE ": true,
270
+ "$LAYERSKEY_OPACITY ": ${item ['opacity' ] * 100 },
271
+ "$LAYERSKEY_FORMAT ": "${item ['imageformat' ]}",
272
+ "$LAYERSKEY_ATTRIBUTION ": "${item ['attribution' ]}",
273
+ "$LAYERSKEY_SRID ": ${item ['epsg' ]},
274
+ "$LAYERSKEY_WMSVERSION ": "${item ['version' ]}",
275
+ "$LAYERSKEY_TYPE ": "wms"
276
+ }
277
+ ''' ;
278
+ layers['WMS' ]! .add (json);
279
+ }
280
+ }
281
+ uri = Uri .parse (
282
+ getBaseUrl () + API_TMSSOURCES + "?$API_PROJECT_PARAM ${project .id }" );
283
+ response = await get (uri, headers: tokenHeader);
284
+ if (response.statusCode == 200 ) {
285
+ var list = jsonDecode (response.body);
286
+ for (var item in list) {
287
+ var subdomains = item['subdomains' ];
288
+ var json = '''
289
+ {
290
+ "$LAYERSKEY_LABEL ": "${item ['label' ]}",
291
+ "$LAYERSKEY_URL ": "${item ['urltemplate' ]}",
292
+ "$LAYERSKEY_MINZOOM ": 1,
293
+ "$LAYERSKEY_MAXZOOM ": ${item ['maxzoom' ]},
294
+ "$LAYERSKEY_OPACITY ": ${item ['opacity' ] * 100 },
295
+ "$LAYERSKEY_ATTRIBUTION ": "${item ['attribution' ]}",
296
+ "$LAYERSKEY_TYPE ": "tms",
297
+ "$LAYERSKEY_ISVISIBLE ": true ${subdomains != null && subdomains .isNotEmpty ? "," : "" }
298
+ ${subdomains != null ? "\" subdomains\" : \" ${subdomains .join (',' )}\" " : "" }
299
+ }
300
+ ''' ;
301
+ layers['TMS' ]! .add (json);
302
+ }
303
+ }
304
+ } catch (e) {
305
+ if (e is Exception ) {
306
+ SMLogger ().e ("ERROR" , e, null );
307
+ }
308
+ print (e);
309
+ }
310
+ return layers;
311
+ }
235
312
}
236
313
237
314
class Project {
0 commit comments