-
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.
Extent router & NPM Prepublish Script (#7)
* 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
Showing
18 changed files
with
392 additions
and
242 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
This file was deleted.
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 was deleted.
Oops, something went wrong.
This file was deleted.
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 was deleted.
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 |
---|---|---|
@@ -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; | ||
}; | ||
}); |
Oops, something went wrong.