layer/layerRec/wmsRecord.js

  1. 'use strict';
  2. const wmsFC = require('./wmsFC.js')();
  3. const placeholderFC = require('./placeholderFC.js')();
  4. const layerRecord = require('./layerRecord.js')();
  5. const shared = require('./shared.js')();
  6. /**
  7. * @class WmsRecord
  8. */
  9. class WmsRecord extends layerRecord.LayerRecord {
  10. /**
  11. * Create a layer record with the appropriate geoApi layer type. Layer config
  12. * should be fully merged with all layer options defined (i.e. this constructor
  13. * will not apply any defaults).
  14. * @param {Object} layerClass the ESRI api object for wms layers
  15. * @param {Object} apiRef object pointing to the geoApi. allows us to call other geoApi functions.
  16. * @param {Object} config layer config values
  17. * @param {Object} esriLayer an optional pre-constructed layer
  18. * @param {Function} epsgLookup an optional lookup function for EPSG codes (see geoService for signature)
  19. */
  20. constructor (layerClass, apiRef, config, esriLayer, epsgLookup) {
  21. super(layerClass, apiRef, config, esriLayer, epsgLookup);
  22. // handles placeholder symbol, possibly other things
  23. this._defaultFC = '0';
  24. this._featClasses['0'] = new placeholderFC.PlaceholderFC(this, this.name);
  25. }
  26. get layerType () { return shared.clientLayerType.OGC_WMS; }
  27. makeLayerConfig () {
  28. const cfg = super.makeLayerConfig();
  29. cfg.visibleLayers = this.config.layerEntries.map(le => le.id);
  30. return cfg;
  31. }
  32. /**
  33. * Triggers when the layer loads.
  34. *
  35. * @function onLoad
  36. */
  37. onLoad () {
  38. const loadPromises = super.onLoad();
  39. const fc = new wmsFC.WmsFC(this, '0', this.config);
  40. this._featClasses['0'] = fc;
  41. loadPromises.push(fc.loadSymbology());
  42. Promise.all(loadPromises).then(() => {
  43. this._stateChange(shared.states.LOADED);
  44. });
  45. }
  46. /**
  47. * Run a getFeatureInfo on a WMS layer, return the result as a promise. Fills the panelData array on resolution.
  48. *
  49. * @param {Object} opts additional argumets like map object, clickEvent, etc.
  50. * @returns {Object} an object with identify results array and identify promise resolving when identify is complete; if an empty object is returned, it will be skipped
  51. */
  52. identify (opts) {
  53. // TODO add full documentation for options parameter
  54. // TODO consider having a constants area in geoApi / better place for this definition
  55. const infoMap = {
  56. 'text/html;fgpv=summary': 'HTML',
  57. 'text/html': 'HTML',
  58. 'text/plain': 'Text',
  59. 'application/json': 'EsriFeature'
  60. };
  61. // ignore layers with no mime type
  62. if (!infoMap.hasOwnProperty(this.config.featureInfoMimeType)) {
  63. return {};
  64. }
  65. // TODO fix these params
  66. // TODO legendEntry.name, legendEntry.symbology appear to be fast links to populate the left side of the results
  67. // view. perhaps it should not be in this object anymore?
  68. // TODO see how the client is consuming the internal pointer to layerRecord. this may also now be
  69. // directly available via the legend object.
  70. const identifyResult =
  71. new shared.IdentifyResult('legendEntry.name', 'legendEntry.symbology',
  72. infoMap[this.config.featureInfoMimeType], this);
  73. const identifyPromise = this._apiRef.layer.ogc
  74. .getFeatureInfo(
  75. this._layer,
  76. opts.clickEvent,
  77. this.config.layerEntries.map(le => le.id),
  78. this.config.featureInfoMimeType)
  79. .then(data => {
  80. identifyResult.isLoading = false;
  81. // TODO: check for French service
  82. // check if a result is returned by the service. If not, do not add to the array of data
  83. if (data.indexOf('Search returned no results') === -1 && data !== '') {
  84. identifyResult.data.push(data);
  85. }
  86. // console.info(data);
  87. });
  88. return { identifyResults: [identifyResult], identifyPromise };
  89. }
  90. }
  91. module.exports = () => ({
  92. WmsRecord
  93. });