Skip to content

Commit

Permalink
Merge pull request #160 from milesap/build-v1.0.6
Browse files Browse the repository at this point in the history
chore(build): version 1.6.0
  • Loading branch information
Miles Petrov authored Oct 14, 2016
2 parents 39ce4a2 + 720cac3 commit 2ab3c76
Show file tree
Hide file tree
Showing 29 changed files with 56,219 additions and 467 deletions.
3 changes: 0 additions & 3 deletions .jscsrc
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
Expand Down
61 changes: 41 additions & 20 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
/* globals -$ */
'use strict';
var gulp = require('gulp');
var del = require('del');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var babelify = require('babelify');
var pkg = require('./package.json');
var $ = require('gulp-load-plugins')({ lazy: true });
var Dgeni = require('dgeni');
const gulp = require('gulp');
const del = require('del');
const yargs = require('yargs');
const args = yargs.argv;
const runSequence = require('run-sequence');
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const babelify = require('babelify');
const pkg = require('./package.json');
const $ = require('gulp-load-plugins')({ lazy: true });
const Dgeni = require('dgeni');

require('gulp-help')(gulp);

gulp.task('clean', 'Remove dist folder', function (done) {
del('dist', done);
let PROD_MODE = args.prod;

/**
* --prod: generate source maps and uglify code; this is turned on when running 'gulp dist'
* --guts: skip style checks
*/

gulp.task('clean', 'Remove dist folder', function () {
del.sync('dist');
});

gulp.task('check', 'Checks code against style guidelines', function () {
gulp.task('check', 'Checks code against style guidelines', function (done) {
if (args.guts) {
return done();
}

return gulp
.src(['src/**/*.js', '*.js'])
.pipe($.jshint())
Expand All @@ -41,25 +55,32 @@ gulp.task('zip', 'Generate zip for distribution', ['build'], function () {
.pipe(gulp.dest('dist'));
});

gulp.task('dist', 'Generate tgz and zip files for distribution', ['zip', 'tgz']);
// gulp.task('dist', 'Generate tgz and zip files for distribution', ['zip', 'tgz']);

gulp.task('build', 'Transpile and concatenate the code', function () {
gulp.task('dist', 'Generate tgz and zip files for distribution', done => {
// turn on --prod flag to enable minification
runSequence('prod', 'check', ['zip', 'tgz'], done);
});

gulp.task('build', 'Transpile and concatenate the code', ['clean'], function () {
var b = browserify({ entries: 'src/index.js', standalone: 'geoapi' }).transform(babelify);
return b.bundle()
.pipe(source('gapi.js'))
.pipe(buffer())
.pipe($.derequire())
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.if(PROD_MODE, $.sourcemaps.init()))
/* .pipe($.babel()) */
.pipe($.concat('geoapi.js'))
/* .pipe(gulp.dest('dist/v' + pkg.version)) */
.pipe(gulp.dest('dist'))
.pipe($.rename('geoapi.min.js'))
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
.pipe($.if(PROD_MODE, $.rename('geoapi.min.js'))) // do not create a minified file unless --prod is provided
.pipe($.if(PROD_MODE, $.uglify()))
.pipe($.if(PROD_MODE, $.sourcemaps.write('.')))
.pipe($.if(PROD_MODE, gulp.dest('dist')));
});

gulp.task('prod', 'Sets production mode', () => PROD_MODE = true);

gulp.task('test', 'Run unit tests in jasmine', ['check', 'build'], function () {
return gulp
.src('spec/*Spec.js')
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"name": "geoApi",
"version": "1.0.1",
"version": "1.0.6",
"description": "",
"main": "dist/geoapi.js",
"dependencies": {},
"dependencies": {
},
"devDependencies": {
"babelify": "~6.3.0",
"brfs": "~1.4.3",
"browserify": "~11.2.0",
"canonical-path": "0.0.2",
"canvg-origin": "^1.0.0",
"csv2geojson": "https://github.com/mapbox/csv2geojson.git#v4.0.0",
"del": "^2.0.2",
"dgeni": "^0.4.1",
Expand All @@ -20,6 +22,7 @@
"gulp-derequire": "~2.1.0",
"gulp-gzip": "^1.2.0",
"gulp-help": "^1.6.1",
"gulp-if": "^2.0.1",
"gulp-jasmine": "^2.1.0",
"gulp-jscs": "^3.0.1",
"gulp-jscs-stylish": "^1.2.0",
Expand All @@ -33,13 +36,16 @@
"jshint-stylish": "^2.0.1",
"lodash": "^3.10.1",
"proj4": "^2.3.12",
"run-sequence": "^1.2.2",
"shpjs": "https://github.com/calvinmetcalf/shapefile-js.git#v3.3.1",
"svg.js": "^2.3.4",
"terraformer": "~1.0.4",
"terraformer-arcgis-parser": "~1.0.4",
"terraformer-proj4js": "https://github.com/RAMP-PCAR/terraformer-proj4js.git#v0.2.1",
"terraformer-proj4js": "https://github.com/RAMP-PCAR/terraformer-proj4js.git#v0.2.2",
"text-encoding": "0.6.0",
"vinyl-buffer": "~1.0.0",
"vinyl-source-stream": "~1.1.0"
"vinyl-source-stream": "~1.1.0",
"yargs": "^5.0.0"
},
"scripts": {
"test": "gulp test"
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const events = require('./events.js');
const hilight = require('./hilight.js');
const layer = require('./layer.js');
const mapManager = require('./mapManager.js');
const mapPrint = require('./mapPrint.js');
const proj = require('./proj.js');
const query = require('./query.js');
const shared = require('./shared.js');
const symbology = require('./symbology.js');

Expand All @@ -17,15 +19,19 @@ function initAll(esriBundle, window) {
api.proj = proj(esriBundle);
api.basemap = basemap(esriBundle);
api.mapManager = mapManager(esriBundle);
api.mapPrint = mapPrint(esriBundle, api);
api.attribs = attribute(esriBundle, api);
api.symbology = symbology(window);
api.hilight = hilight(esriBundle, api);
api.events = events();
api.query = query(esriBundle);
api.shared = shared(esriBundle);
api.debug = function () {
if (arguments.length === 1) {
debug = arguments[0] === true;
}

return debug;
};
api.esriBundle = function () {
if (debug) {
Expand Down Expand Up @@ -71,7 +77,11 @@ module.exports = function (esriLoaderUrl, window) {
['esri/tasks/IdentifyParameters', 'IdentifyParameters'],
['esri/tasks/IdentifyTask', 'IdentifyTask'],
['esri/tasks/ProjectParameters', 'ProjectParameters'],
['esri/tasks/query', 'Query']
['esri/tasks/query', 'Query'],
['esri/tasks/QueryTask', 'QueryTask'],
['esri/tasks/PrintParameters', 'PrintParameters'],
['esri/tasks/PrintTask', 'PrintTask'],
['esri/tasks/PrintTemplate', 'PrintTemplate']
];

function makeDojoRequests() {
Expand Down
24 changes: 21 additions & 3 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ function predictLayerUrlBuilder(esriBundle) {
* - name: best attempt at guessing the name of the service (string). only present for ESRI service URLs
* - fields: array of field definitions for the layer. conforms to ESRI's REST field standard. only present for feature layer and image service URLs.
* - geometryType: describes the geometry of the layer (string). conforms to ESRI's REST geometry type enum values. only present for feature layer URLs.
* - groupIdx: property only available if a group layer is queried. it is the layer index of the group layer in the list under its parent dynamic layer
*
* @method predictLayerUrl
* @param {String} url a url to something that is hopefully a map service
Expand Down Expand Up @@ -421,7 +422,19 @@ function predictLayerUrlBuilder(esriBundle) {
resolve(infoEsri);
} else {
// it was a esri service. rejoice.
resolve(infoEsri);

// shortlived rejoice because grouped layers lul
if (infoEsri.serviceType === serviceType.GroupLayer) {
const lastSlash = url.lastIndexOf('/');
const layerIdx = parseInt(url.substring(lastSlash + 1));
url = url.substring(0, lastSlash);
pokeEsriService(url, esriBundle).then(infoDynamic => {
infoDynamic.groupIdx = layerIdx;
resolve(infoDynamic);
});
} else {
resolve(infoEsri);
}
}
});
} else {
Expand Down Expand Up @@ -704,9 +717,10 @@ function assignIds(geoJson) {
}

// for every feature, if it does not have an id property, add it.
// 0 is not a valid object id
geoJson.features.forEach(function (val, idx) {
if (typeof val.id === 'undefined') {
val.id = idx;
val.id = idx + 1;
}
});
}
Expand Down Expand Up @@ -841,10 +855,11 @@ function makeGeoJsonLayerBuilder(esriBundle, geoApi) {
// console.log('reprojecting ' + srcProj + ' -> EPSG:' + targetWkid);
geoApi.proj.projectGeojson(geoJson, destProj, srcProj);
const esriJson = Terraformer.ArcGIS.convert(geoJson, { sr: targetWkid });
const geometryType = layerDefinition.drawingInfo.geometryType;

const fs = {
features: esriJson,
geometryType: layerDefinition.drawingInfo.geometryType
geometryType
};
const layer = new esriBundle.FeatureLayer(
{
Expand All @@ -862,6 +877,9 @@ function makeGeoJsonLayerBuilder(esriBundle, geoApi) {
layer.renderer.symbol.color = new esriBundle.Color(opts.colour);
}

// initializing layer using JSON does not set this property. do it manually.
layer.geometryType = geometryType;

resolve(layer);
});

Expand Down
19 changes: 18 additions & 1 deletion src/mapManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = function (esriBundle) {
getExtentFromJson,
setupMap,
setProxy,
mapDefault
mapDefault,
findClosestLOD
};

let basemapCtrl;
Expand Down Expand Up @@ -182,5 +183,21 @@ module.exports = function (esriBundle) {
spatialReference: { wkid: extentJson.spatialReference.wkid } });
}

/**
* @ngdoc method
* @name findClosestLOD
* @memberof mapManager
* Finds the level of detail closest to the provided scale.
*
* @param {Array} lods list of levels of detail objects
* @param {Number} scale scale value to search for in the levels of detail
* @return {Object} the level of detail object closest to the scale
*/
function findClosestLOD(lods, scale) {
const diffs = lods.map(lod => Math.abs(lod.scale - scale));
const lodIdx = diffs.indexOf(Math.min(...diffs));
return lods[lodIdx];
}

return mapManager;
};
Loading

0 comments on commit 2ab3c76

Please sign in to comment.