Skip to content

Commit

Permalink
fix map zoom and initial channel on edit
Browse files Browse the repository at this point in the history
  • Loading branch information
4www committed Dec 13, 2024
1 parent 03d66d5 commit 45de2d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 2 additions & 0 deletions public/themes/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,11 @@ r4-channel-slug {
r4-avatar-update {
& fieldset {
justify-content: center;
align-items: center;
}
& legend {
text-align: center;
width: 100%;
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/components/r4-map-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ export default class R4MapPosition extends LitElement {
}

get mapChannels() {
return [
{
...this.channel,
},
{
const channels = []
if (this.channel.longitude) {
channels.push(this.channel)
}

if (this.newLongitude && this.newLatitude) {
channels.push({
...this.channel,
title: `New position for ${this.channel.slug}`,
longitude: this.newLongitude,
latitude: this.newLatitude,
},
]
})
}
return channels
}

onMapClick(event) {
Expand Down
10 changes: 8 additions & 2 deletions src/components/r4-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ export default class R4Map extends LitElement {
this.longitude = 0
this.latitude = 0
this.markers = []
this.zoom = 1
}

async firstUpdated() {
this.createMap()
this.isReady = true
this.zoom = !this.zoom && this.longitude ? 6 : 2

if (!this.zoom) {
this.zoom = 1
}

// Fetch channels and set markers for each.
if (!this.channels) {
Expand Down Expand Up @@ -115,12 +119,14 @@ export default class R4Map extends LitElement {
const rasterLayer = new TileLayer({
source: new OSM(),
})

console.log(this.channels)
this.map = new Map({
target: this.querySelector('main'),
layers: [rasterLayer],
view: new View({
center: [this.longitude, this.latitude],
zoom: this.zoom || 8,
zoom: this.zoom,
}),
overlays: [this.overlay],
})
Expand Down

0 comments on commit 45de2d4

Please sign in to comment.