Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #140 from Esri/eslint
Browse files Browse the repository at this point in the history
replace jshint with eslint

resolves #138
  • Loading branch information
tomwayson committed Nov 8, 2015
2 parents 1706d47 + 551ed90 commit 30ccdbe
Show file tree
Hide file tree
Showing 21 changed files with 412 additions and 416 deletions.
23 changes: 23 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"rules": {
"indent": [
2,
4
],
"quotes": [
2,
"single"
],
"semi": [
2,
"always"
]
},
"env": {
"browser": true
},
"globals": {
"angular": false
},
"extends": "eslint:recommended"
}
24 changes: 0 additions & 24 deletions .jshintrc

This file was deleted.

5 changes: 5 additions & 0 deletions docs/app/examples/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-console": 0
}
}
2 changes: 1 addition & 1 deletion docs/app/examples/map-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('esri-map-docs')
lat: 37.75
},
zoom: 13,
loaded: false,
loaded: false
};
// one way to get a reference to the map is to
// set a handler for the map directive's load attribute
Expand Down
2 changes: 1 addition & 1 deletion docs/app/examples/registry-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ angular.module('esri-map-docs')
lat: 37.75
},
zoom: 13,
point: null,
point: null
};
// another way to get a reference to the map is to
// set the register-as attribute on the directive
Expand Down
2 changes: 1 addition & 1 deletion docs/app/examples/set-basemap.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

angular.module('esri-map-docs')
.controller('BasemapCtrl', function($scope, $route) {
.controller('BasemapCtrl', function($scope) {
$scope.map = {
center: {
lng: -31.036,
Expand Down
20 changes: 15 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*eslint-env node*/
/*eslint indent:0*/
'use strict';
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var eslint = require('gulp-eslint');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var ngAnnotate = require('gulp-ng-annotate');
Expand All @@ -15,12 +17,20 @@ var angularProtractor = require('gulp-angular-protractor');

// source directives and services
var srcJsFiles = 'src/**/*.js';
var docsJsFiles = 'docs/app/**/*.js';

// lint source javascript files
gulp.task('lint', function() {
return gulp.src(srcJsFiles)
.pipe(jshint())
.pipe(jshint.reporter('default'));
return gulp.src([srcJsFiles, docsJsFiles])
// eslint() attaches the lint output to the eslint property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failOnError last.
.pipe(eslint.failOnError());
});

// clean built copies of javascript files
Expand Down Expand Up @@ -97,7 +107,7 @@ gulp.task('serve', ['build'], function() {
notify: false
});

gulp.watch([srcJsFiles,'./docs/**.*.html', './docs/app/**/*.js', './docs/styles/*.css'], ['build', browserSync.reload ]);
gulp.watch([srcJsFiles,'./docs/**.*.html', docsJsFiles, './docs/styles/*.css'], ['build', browserSync.reload ]);
});

// serve tests on local web server
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
"dependencies": {},
"devDependencies": {
"browser-sync": "~1.6.1",
"eslint": "^1.9.0",
"gh-release": "^2.0.1",
"gulp": "^3.8.9",
"gulp-angular-protractor": "~0.0.2",
"gulp-clean": "~0.3.0",
"gulp-concat": "~2.2.0",
"gulp-eslint": "^1.0.0",
"gulp-gh-pages": "^0.4.0",
"gulp-jshint": "^1.8.5",
"gulp-ng-annotate": "^0.3.3",
"gulp-rename": "~1.2.0",
"gulp-strip-debug": "~0.3.0",
"gulp-uglify": "~0.3.0",
"gulp-util": "~2.2.16",
"run-sequence": "~0.3.6",
"protractor": "~2.2.0",
"gulp-angular-protractor": "~0.0.2"
"run-sequence": "~0.3.6"
},
"repository": {
"type": "git",
Expand Down
210 changes: 105 additions & 105 deletions src/core/esriLayerUtils.js
Original file line number Diff line number Diff line change
@@ -1,124 +1,124 @@
(function (angular) {
'use strict';

angular.module('esri.core').factory('esriLayerUtils', function (esriLoader) {

// parse array of visible layer ids from a string
function parseVisibleLayers(val) {
var visibleLayers;
if (typeof val === 'string') {
visibleLayers = [];
val.split(',').forEach(function(layerId) {
var n = parseInt(layerId);
if(!isNaN(n)) {
visibleLayers.push(n);
}
});
(function(angular) {
'use strict';

angular.module('esri.core').factory('esriLayerUtils', function(esriLoader) {

// parse array of visible layer ids from a string
function parseVisibleLayers(val) {
var visibleLayers;
if (typeof val === 'string') {
visibleLayers = [];
val.split(',').forEach(function(layerId) {
var n = parseInt(layerId);
if (!isNaN(n)) {
visibleLayers.push(n);
}
});
}
return visibleLayers;
}
return visibleLayers;
}

// layerOptions.infoTemplate expects one of the following:
// 1. [title <String | Function>, content <String | Function>]
// 2. {title: <String | Function>, content: <String | Function>}
// 3. a valid Esri JSAPI InfoTemplate
function objectToInfoTemplate(infoTemplate, InfoTemplate) {
// only attempt to construct if a valid InfoTemplate wasn't already passed in
if (infoTemplate.declaredClass === 'esri.InfoTemplate') {
return infoTemplate;
} else {
// construct infoTemplate from object, using 2 args style:
// https://developers.arcgis.com/javascript/jsapi/infotemplate-amd.html#infotemplate2
if (angular.isArray(infoTemplate) && infoTemplate.length === 2) {
return new InfoTemplate(infoTemplate[0], infoTemplate[1]);

// layerOptions.infoTemplate expects one of the following:
// 1. [title <String | Function>, content <String | Function>]
// 2. {title: <String | Function>, content: <String | Function>}
// 3. a valid Esri JSAPI InfoTemplate
function objectToInfoTemplate(infoTemplate, InfoTemplate) {
// only attempt to construct if a valid InfoTemplate wasn't already passed in
if (infoTemplate.declaredClass === 'esri.InfoTemplate') {
return infoTemplate;
} else {
return new InfoTemplate(infoTemplate.title, infoTemplate.content);
// construct infoTemplate from object, using 2 args style:
// https://developers.arcgis.com/javascript/jsapi/infotemplate-amd.html#infotemplate2
if (angular.isArray(infoTemplate) && infoTemplate.length === 2) {
return new InfoTemplate(infoTemplate[0], infoTemplate[1]);
} else {
return new InfoTemplate(infoTemplate.title, infoTemplate.content);
}
}
}
}

// stateless utility service
var service = {};

// create a feature layer
service.createFeatureLayer = function(url, layerOptions) {
return esriLoader.require(['esri/layers/FeatureLayer', 'esri/InfoTemplate']).then(function(esriModules) {
var FeatureLayer = esriModules[0];
var InfoTemplate = esriModules[1];

// normalize info template defined in layerOptions.infoTemplate
// or nested esriLayerOption directive to be instance of esri/InfoTemplate
// and pass to layer constructor in layerOptions
if (layerOptions.infoTemplate) {
layerOptions.infoTemplate = objectToInfoTemplate(layerOptions.infoTemplate, InfoTemplate);
}

// layerOptions.mode expects a FeatureLayer constant name as a <String>
// https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#constants
if (layerOptions.hasOwnProperty('mode')) {
// look up and convert to the appropriate <Number> value
layerOptions.mode = FeatureLayer[layerOptions.mode];
}
// stateless utility service
var service = {};

// create a feature layer
service.createFeatureLayer = function(url, layerOptions) {
return esriLoader.require(['esri/layers/FeatureLayer', 'esri/InfoTemplate']).then(function(esriModules) {
var FeatureLayer = esriModules[0];
var InfoTemplate = esriModules[1];

// normalize info template defined in layerOptions.infoTemplate
// or nested esriLayerOption directive to be instance of esri/InfoTemplate
// and pass to layer constructor in layerOptions
if (layerOptions.infoTemplate) {
layerOptions.infoTemplate = objectToInfoTemplate(layerOptions.infoTemplate, InfoTemplate);
}

return new FeatureLayer(url, layerOptions);
});
};

// create a dynamic service layer
service.createDynamicMapServiceLayer = function(url, layerOptions, visibleLayers) {
return esriLoader.require(['esri/layers/ArcGISDynamicMapServiceLayer', 'esri/InfoTemplate', 'esri/layers/ImageParameters']).then(function (esriModules) {
var ArcGISDynamicMapServiceLayer = esriModules[0];
var InfoTemplate = esriModules[1];
var ImageParameters = esriModules[2];
var layer;

// normalize info templates defined in layerOptions.infoTemplates
// or nested esriLayerOption directives to be instances of esri/InfoTemplate
// and pass to layer constructor in layerOptions
if (layerOptions.infoTemplates) {
for (var layerId in layerOptions.infoTemplates) {
if (layerOptions.infoTemplates.hasOwnProperty(layerId)) {
layerOptions.infoTemplates[layerId].infoTemplate = objectToInfoTemplate(layerOptions.infoTemplates[layerId].infoTemplate, InfoTemplate);
// layerOptions.mode expects a FeatureLayer constant name as a <String>
// https://developers.arcgis.com/javascript/jsapi/featurelayer-amd.html#constants
if (layerOptions.hasOwnProperty('mode')) {
// look up and convert to the appropriate <Number> value
layerOptions.mode = FeatureLayer[layerOptions.mode];
}

return new FeatureLayer(url, layerOptions);
});
};

// create a dynamic service layer
service.createDynamicMapServiceLayer = function(url, layerOptions, visibleLayers) {
return esriLoader.require(['esri/layers/ArcGISDynamicMapServiceLayer', 'esri/InfoTemplate', 'esri/layers/ImageParameters']).then(function(esriModules) {
var ArcGISDynamicMapServiceLayer = esriModules[0];
var InfoTemplate = esriModules[1];
var ImageParameters = esriModules[2];
var layer;

// normalize info templates defined in layerOptions.infoTemplates
// or nested esriLayerOption directives to be instances of esri/InfoTemplate
// and pass to layer constructor in layerOptions
if (layerOptions.infoTemplates) {
for (var layerId in layerOptions.infoTemplates) {
if (layerOptions.infoTemplates.hasOwnProperty(layerId)) {
layerOptions.infoTemplates[layerId].infoTemplate = objectToInfoTemplate(layerOptions.infoTemplates[layerId].infoTemplate, InfoTemplate);
}
}
}
}

// check for imageParameters property and
// convert into ImageParameters() if needed
if (angular.isObject(layerOptions.imageParameters)) {
if (layerOptions.imageParameters.declaredClass !== 'esri.layers.ImageParameters') {
var imageParameters = new ImageParameters();
for (var key in layerOptions.imageParameters) {
if (layerOptions.imageParameters.hasOwnProperty(key)) {
// TODO: may want to convert timeExent to new TimeExtent()
// also not handling conversion for bbox, imageSpatialReference, nor layerTimeOptions
imageParameters[key] = layerOptions.imageParameters[key];
// check for imageParameters property and
// convert into ImageParameters() if needed
if (angular.isObject(layerOptions.imageParameters)) {
if (layerOptions.imageParameters.declaredClass !== 'esri.layers.ImageParameters') {
var imageParameters = new ImageParameters();
for (var key in layerOptions.imageParameters) {
if (layerOptions.imageParameters.hasOwnProperty(key)) {
// TODO: may want to convert timeExent to new TimeExtent()
// also not handling conversion for bbox, imageSpatialReference, nor layerTimeOptions
imageParameters[key] = layerOptions.imageParameters[key];
}
}
layerOptions.imageParameters = imageParameters;
}
layerOptions.imageParameters = imageParameters;
}
}

// create the layer object
layer = new ArcGISDynamicMapServiceLayer(url, layerOptions);
// create the layer object
layer = new ArcGISDynamicMapServiceLayer(url, layerOptions);

// set visible layers if passed as attribute
if (visibleLayers) {
layer.setVisibleLayers(parseVisibleLayers(visibleLayers));
}
// set visible layers if passed as attribute
if (visibleLayers) {
layer.setVisibleLayers(parseVisibleLayers(visibleLayers));
}

return layer;
});
};
return layer;
});
};

// create an InfoTemplate object from JSON
service.createInfoTemplate = function(infoTemplate) {
return esriLoader.require('esri/InfoTemplate').then(function(InfoTemplate) {
return objectToInfoTemplate(infoTemplate, InfoTemplate);
});
};
// create an InfoTemplate object from JSON
service.createInfoTemplate = function(infoTemplate) {
return esriLoader.require('esri/InfoTemplate').then(function(InfoTemplate) {
return objectToInfoTemplate(infoTemplate, InfoTemplate);
});
};

return service;
});
return service;
});

})(angular);
Loading

0 comments on commit 30ccdbe

Please sign in to comment.