diff --git a/js/Main.js b/js/Main.js index dfd02e3..d06449c 100644 --- a/js/Main.js +++ b/js/Main.js @@ -82,7 +82,12 @@ export class Main extends Component { this.state = _.merge(this.state, props.options); } - this.mapView = hashToView(location.hash, this.props, this.state); + this.viewDefaults = { + radius: props.borderCircleRadius || props.borderSquareRadius, + basemap: this.state.basemap, + }; + + this.mapView = hashToView(location.hash, this.viewDefaults); this.state.basemap = this.mapView.basemap; this.pluginApi = new PluginApi(this); @@ -188,7 +193,7 @@ export class Main extends Component { zoom={minZoom} maxZoom={5} minZoom={minZoom} - onmoveend={e => history.replaceState({}, document.title, viewToHash(e.target, this.state))} + onmoveend={e => history.replaceState({}, document.title, viewToHash(e.target, this.state, this.viewDefaults))} onmousemove={e => this.coordsDisplay && this.coordsDisplay.setCursor(e.latlng)} > diff --git a/js/Url.js b/js/Url.js index c3d324b..10a8c7b 100644 --- a/js/Url.js +++ b/js/Url.js @@ -1,17 +1,26 @@ import {intCoords, radiusToBounds, xz} from './Util'; -export function viewToHash(leaf, appState) { +export function viewToHash(leaf, appState, defaults) { + var hash = ''; + + if (appState.basemap != defaults.basemap) + hash += '#t=' + appState.basemap; + let boundsObj = leaf.getBounds(); + let [x, z] = intCoords(boundsObj.getCenter()); let [e, n] = intCoords(boundsObj.getNorthEast()); let [w, s] = intCoords(boundsObj.getSouthWest()); - return '#b=' + [w, n, e, s].join(',') - + '#t=' + appState.basemap; + let radius = parseInt(Math.min(Math.abs(e - w), Math.abs(s - n)) / 2); + if (radius < defaults.radius) + hash += '#c=' + x + ',' + z + ',r' + radius; + + return hash || '#'; } -export function hashToView(hash, appProps, appState) { +export function hashToView(hash, defaults) { var view = { - bounds: radiusToBounds(appProps.borderCircleRadius || appProps.borderSquareRadius), - basemap: appState.basemap, + bounds: radiusToBounds(defaults.radius), + basemap: defaults.basemap, }; if (!hash) return view; @@ -34,6 +43,12 @@ export function hashToView(hash, appProps, appState) { let [w, n, e, s] = vals.split(',', 4).map(parseFloat); view.bounds = [xz(w, n), xz(e, s)]; } + else if (key == 'c') { + let [x, z, r] = vals.split(/,r?/, 3).map(parseFloat); + if (!r) view.marker = true; + r = r || 10; + view.bounds = [xz(x - r, z - r), xz(x + r, z + r)]; + } else if (key == 't') view.basemap = vals; });