Skip to content

Commit

Permalink
Merge pull request fgpv-vpgf#39 from james-rae/feature/common
Browse files Browse the repository at this point in the history
refactor(geoApi): create common function module
  • Loading branch information
alyec committed Jan 6, 2016
2 parents 34ab273 + e657099 commit ec2dd4a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/attribute.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

const shared = require('./shared.js');

// Attribute Loader related functions
//TODO consider re-writing all the asynch stuff with the ECMA-7 style of asynch keywords
module.exports = function (esriBundle) {
module.exports = esriBundle => {

/**
* Will generate an empty object structure to store attributes for a single layer of features
Expand Down Expand Up @@ -44,28 +46,6 @@ module.exports = function (esriBundle) {
});
}

/**
* Will return a string indicating the type of layer a layer object is.
* @private
* @param {Object} layer an ESRI API layer object
* @return {String} layer type
*/
function getLayerType(layer) {
//TODO should this function be part of the layer bundle instead? what is best way to have shared functions in geoApi
if (layer instanceof esriBundle.FeatureLayer) {
return 'FeatureLayer';
} else if (layer instanceof esriBundle.WmsLayer) {
return 'WmsLayer';
} else if (layer instanceof esriBundle.ArcGISDynamicMapServiceLayer) {
return 'ArcGISDynamicMapServiceLayer';
} else if (layer instanceof esriBundle.ArcGISTiledMapServiceLayer) {
return 'ArcGISTiledMapServiceLayer';
} else {
//Can add more types above as we support them
return 'UNKNOWN';
}
}

//skim the last number off the Url
//TODO apply more edge case tests to this function
function getLayerIndex(layerUrl) {
Expand Down Expand Up @@ -393,8 +373,8 @@ module.exports = function (esriBundle) {
let resultProm = new Promise(

function (resolve, reject) {

switch (getLayerType(layer)) {
let shr = shared(esriBundle);
switch (shr.getLayerType(layer)) {
case 'FeatureLayer':

processFeatureLayer(layer, options, resolve, reject);
Expand All @@ -421,6 +401,6 @@ module.exports = function (esriBundle) {
}

return {
loadLayerAttribs: loadLayerAttribs
loadLayerAttribs
};
};
30 changes: 30 additions & 0 deletions src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

// Common functions for use across other geoApi modules
module.exports = esriBundle => {

/**
* Will return a string indicating the type of layer a layer object is.
* @private
* @param {Object} layer an ESRI API layer object
* @return {String} layer type
*/
function getLayerType(layer) {
if (layer instanceof esriBundle.FeatureLayer) {
return 'FeatureLayer';
} else if (layer instanceof esriBundle.WmsLayer) {
return 'WmsLayer';
} else if (layer instanceof esriBundle.ArcGISDynamicMapServiceLayer) {
return 'ArcGISDynamicMapServiceLayer';
} else if (layer instanceof esriBundle.ArcGISTiledMapServiceLayer) {
return 'ArcGISTiledMapServiceLayer';
} else {
//Can add more types above as we support them
return 'UNKNOWN';
}
}

return {
getLayerType
};
};

0 comments on commit ec2dd4a

Please sign in to comment.