-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenHistoricalMap layer to maps #454
Changes from 3 commits
eb0e7ab
95da99c
e5fa8c6
eb8bcb7
74a8b06
3d2deeb
6e78609
109615a
48de6cd
5958d8c
7628d92
734ea4c
2a31281
7ed30be
cbe4cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import '../components/GrampsjsMapSearchbox.js' | |
import '../components/GrampsjsMapTimeSlider.js' | ||
import '../components/GrampsjsPlaceBox.js' | ||
import {apiGet, getMediaUrl} from '../api.js' | ||
import {isDateBetweenYears} from '../util.js' | ||
import {isDateBetweenYears, getGregorianYears} from '../util.js' | ||
import '@material/mwc-textfield' | ||
|
||
// This is used for initial map center in absence of places | ||
|
@@ -82,6 +82,7 @@ export class GrampsjsViewMap extends GrampsjsView { | |
_year: {type: Number}, | ||
_yearSpan: {type: Number}, | ||
_currentLayer: {type: String}, | ||
_minYear: {type: Number}, | ||
} | ||
} | ||
|
||
|
@@ -100,6 +101,7 @@ export class GrampsjsViewMap extends GrampsjsView { | |
this._year = -1 | ||
this._yearSpan = -1 | ||
this._currentLayer = '' | ||
this._minYear = 1500 | ||
} | ||
|
||
renderContent() { | ||
|
@@ -132,6 +134,7 @@ export class GrampsjsViewMap extends GrampsjsView { | |
>${this._renderPlaceDetails()}</grampsjs-map-searchbox | ||
> | ||
<grampsjs-map-time-slider | ||
min="${this._minYear}" | ||
?filterMap="${this._currentLayer === 'OpenHistoricalMap'}" | ||
@timeslider:change="${this._handleTimeSliderChange}" | ||
.strings="${this.strings}" | ||
|
@@ -389,12 +392,25 @@ export class GrampsjsViewMap extends GrampsjsView { | |
if ('data' in data) { | ||
this.error = false | ||
this._dataEvents = data.data.filter(event => event.place) | ||
this._minYear = this._getMinYear() | ||
} else if ('error' in data) { | ||
this.error = true | ||
this._errorMessage = data.error | ||
} | ||
} | ||
|
||
_getMinYear() { | ||
const years = this._dataEvents | ||
?.filter(event => event.place) | ||
?.map(event => getGregorianYears(event.date)?.[0]) | ||
?.filter(y => y !== undefined) | ||
let minYear = Math.min(...years) | ||
const lastYear = new Date().getFullYear() - 1 | ||
minYear = Math.min(minYear, lastYear) | ||
minYear = Math.max(minYear, 1) // disallow negative | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, the map data and filtering code support BCE dates. Quite unlikely, of course, but I mention this in case we do decide to allow it in the future. The only gotcha is that the year is offset by one because there’s no year 0, per ISO 8601. Currently this component is using −1 as a magic number for an unset year; we’d need to use something else like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes you're right. I think it's pretty ok for Gramps Web, but of course not ok for OHM in general. So would be more elegant to handle in full generality in the future here as well. |
||
return minYear | ||
} | ||
|
||
async _fetchDataLayers() { | ||
const rules = { | ||
rules: [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OHM offers multiple official stylesheets. For now, I’ve gone with the default “Historical” style. If desired, Gramps can define its own custom style, following the MapLibre GL Style Specification. Tools like Fresco and Maputnik allow you to design custom styles visually.