Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Implement extentRouter
Browse files Browse the repository at this point in the history
Will help with agrc/atlas#202
  • Loading branch information
stdavis committed Jun 18, 2018
1 parent ed98e9e commit d952226
Show file tree
Hide file tree
Showing 12 changed files with 557 additions and 102 deletions.
105 changes: 61 additions & 44 deletions ExtentRouter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ExtentRouter.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion 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'
]);
};
115 changes: 72 additions & 43 deletions _src/ExtentRouter.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,72 @@
// TODO:
// initRouter: function () {
// // summary:
// // sets up the url router for persisting the map extent
// console.log('agrc.widgets.map.BaseMap::initRouter', arguments);
//
// var that = this;
// var urlObj = ioQuery.queryToObject(hash());
// var options = {
// scale: parseInt(urlObj.scale, 10),
// center: new Point({
// x: parseInt(urlObj.x, 10),
// y: parseInt(urlObj.y, 10),
// spatialReference: {wkid: 3857}
// })
// };
// this.on('load', function () {
// if (urlObj.x && urlObj.y && urlObj.scale) {
// that.setScale(options.scale);
// that.centerAt(options.center);
// }
// that.on('extent-change', lang.hitch(that, 'updateExtentHash'));
// });
//
// return (options.scale && options.center.x && options.center.y) ? options : {};
// },
// updateExtentHash: function () {
// // summary:
// // sets the extent props in the url hash
// console.log('agrc.widgets.map.BaseMap::updateExtentHash', arguments);
//
// var center = this.extent.getCenter();
// if (center.x && center.y) {
// // mixin any existing url props to allow for other routers
// var newProps = lang.mixin(ioQuery.queryToObject(hash()), {
// x: Math.round(center.x),
// y: Math.round(center.y),
// scale: Math.round(this.getScale())
// });
//
// return hash(ioQuery.objectToQuery(newProps), true);
// }
// }
define([
'dojo/hash',
'dojo/io-query',

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

watchUtils,
Point
) {
const updateExtentHash = function (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 function (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;
};
});
72 changes: 72 additions & 0 deletions _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'
], function (
hash,
ioQuery,

watchUtils,
Point
) {
const updateExtentHash = function (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 function (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;
};
});
61 changes: 61 additions & 0 deletions extentRouter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d952226

Please sign in to comment.