Skip to content

Commit

Permalink
Extent router & NPM Prepublish Script (#7)
Browse files Browse the repository at this point in the history
* Implement extentRouter

Will help with agrc/atlas#202

* remove all babel/sass output and wire npm prepublish script

* ignore babel/sass output

* update items

* ignore secrets files in npm package

* remove unused secrets.json

* remove function

* casing craziness

* this is a windows trick

* lowercase 4lyfe
  • Loading branch information
stdavis committed Jun 22, 2018
1 parent c4ae74f commit 4b438c9
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 242 deletions.
6 changes: 6 additions & 0 deletions packages/map-tools/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ node_modules/
secrets.json
tests/spec/
vendor/
/MapView.js
MapView.js.map
/extentRouter.js
extentRouter.js.map
resources/MapView.css
resources/MapView.css.map
44 changes: 0 additions & 44 deletions packages/map-tools/ExtentRouter.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/map-tools/ExtentRouter.js.map

This file was deleted.

21 changes: 20 additions & 1 deletion packages/map-tools/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ module.exports = function (grunt) {
]
}
},
exec: {
main: {
cmd: 'node node_modules/jasmine/bin/jasmine.js --config=tests/e2e/jasmine.json'
},
debug: {
cmd: 'DEBUG=true node node_modules/jasmine/bin/jasmine.js --config=tests/e2e/jasmine.json'
}
},
jasmine: {
main: {
options: {
Expand Down Expand Up @@ -112,6 +120,17 @@ module.exports = function (grunt) {
'eslint',
'connect',
'babel',
'jasmine'
'jasmine',
'exec:main'
]);

grunt.registerTask('e2e', [
'connect',
'exec:main'
]);

grunt.registerTask('e2edebug', [
'connect',
'exec:debug'
]);
};
55 changes: 0 additions & 55 deletions packages/map-tools/MapView.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/map-tools/MapView.js.map

This file was deleted.

2 changes: 0 additions & 2 deletions packages/map-tools/_SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

<script src="tests/jasmineAMDErrorChecking.js"></script>

<script src="tests/spec/SpecExtentRouter.js"></script>

<script src="tests/spec/SpecMapView.js"></script>

<script src=".grunt/grunt-contrib-jasmine/reporter.js"></script>
Expand Down
43 changes: 0 additions & 43 deletions packages/map-tools/_src/ExtentRouter.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/map-tools/_src/MapView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define([
'dojo/query',
'dojo/text!./resources/templates/loader.html',
'dojo/_base/declare'
], function (
], (
_TemplatedMixin,
_WidgetBase,

Expand All @@ -16,7 +16,7 @@ define([
query,
loaderTemplate,
declare
) {
) => {
return declare(null, {
// loader: DomNode
// the widget containing the loader animation
Expand Down
72 changes: 72 additions & 0 deletions packages/map-tools/_src/extentRouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
define([
'dojo/hash',
'dojo/io-query',

'esri/core/watchUtils',
'esri/geometry/Point'
], (
hash,
ioQuery,

watchUtils,
Point
) => {
const updateExtentHash = (mapView) => {
// summary:
// sets the extent props in the url hash
// mapView: esri/views/mapView
console.log('map-tools/ExtentRouter:updateExtentHash', arguments);

if ((!mapView.scale && !mapView.zoom) || !mapView.center) {
return;
}

const center = mapView.center;
// mixin any existing url props to allow for other routers
const newProps = Object.assign(ioQuery.queryToObject(hash()), {
x: Math.round(center.x),
y: Math.round(center.y)
});

if (mapView.zoom) {
newProps.zoom = mapView.zoom;
} else {
newProps.scale = Math.rount(mapView.scale);
}

return hash(ioQuery.objectToQuery(newProps), true);
};

return (mapView) => {
// summary:
// sets up the url router for persisting the map extent
// mapView: esri/views/mapView
console.log('map-tools/ExtentRouter:constructor', arguments);

const urlObj = ioQuery.queryToObject(hash());
const options = {
scale: parseInt(urlObj.scale, 10),
center: new Point({
x: parseInt(urlObj.x, 10),
y: parseInt(urlObj.y, 10),
spatialReference: {wkid: 3857}
}),
zoom: parseInt(urlObj.zoom, 10)
};
mapView.when(() => {
if (options.center.x && options.center.y && (options.scale || options.zoom)) {
if (options.zoom) {
mapView.zoom = options.zoom;
} else {
mapView.scale = options.scale;
}

mapView.center = options.center;
}
watchUtils.whenTrue(mapView, 'stationary', updateExtentHash.bind(null, mapView));
});

// return for unit tests assertion
return options;
};
});
Loading

0 comments on commit 4b438c9

Please sign in to comment.