This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Will help with agrc/atlas#202
- Loading branch information
Showing
12 changed files
with
557 additions
and
102 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.