Skip to content

Commit eb80300

Browse files
dfallingclaude
andauthored
Add color-scheme attribute for dark/light/system map theming (#279)
* Add color-scheme attribute for dark/light/system map theming Adds a `color-scheme` attribute to `<lit-google-map>` that forwards the value to the Google Maps API `colorScheme` option. Accepts `'LIGHT'`, `'DARK'`, or `'FOLLOW_SYSTEM'`. When omitted the Maps API defaults to `'LIGHT'`. Attribute changes after initialization are applied via `setOptions` so the map responds to live updates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Bump version to 0.0.6 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 25effd8 commit eb80300

7 files changed

Lines changed: 32 additions & 20 deletions

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project is a fork of [lit-google-map](https://github.com/arkadiuszwojcik/li
99
- add `zoom_changed`, `center_changed`, and `view_changed` events
1010
- move to [AdvancedMarkerElement](https://developers.google.com/maps/documentation/javascript/advanced-markers/migration)
1111
- add location button control for centering map on user's current location
12+
- add `color-scheme` attribute for dark/light/system color scheme support
1213

1314
## Table of contents
1415

@@ -94,6 +95,7 @@ or/and shapes:
9495
- '_map-type_' - Map type to display: 'roadmap', 'satellite', 'hybrid', 'terrain'
9596
- '_center-latitude_'- Latitude of map initial center point
9697
- '_center-longitude_' - Longitude of map initial center point
98+
- '_color-scheme_' - Map color scheme: `'LIGHT'`, `'DARK'`, or `'FOLLOW_SYSTEM'` (optional, defaults to `'LIGHT'`)
9799

98100
Example:
99101

dist/lit-google-map.bundle.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ var LitGoogleMap = (function (exports) {
8686
this.centerLongitude = 150.644;
8787
this.language = "";
8888
this.mapId = "DEMO_MAP_ID";
89+
this.colorScheme = "";
8990
this.map = null;
9091
this.markers = [];
9192
this.shapes = [];
@@ -104,6 +105,9 @@ var LitGoogleMap = (function (exports) {
104105
else if (name === "zoom") {
105106
this.map.setZoom(this.zoom);
106107
}
108+
else if (name === "color-scheme" && this.colorScheme) {
109+
this.map.setOptions({ colorScheme: this.colorScheme });
110+
}
107111
}
108112
}
109113
dispatchViewChanged() {
@@ -176,13 +180,7 @@ var LitGoogleMap = (function (exports) {
176180
this.updateControls();
177181
}
178182
getMapOptions() {
179-
return {
180-
zoom: this.zoom,
181-
center: { lat: this.centerLatitude, lng: this.centerLongitude },
182-
mapTypeId: this.mapType,
183-
styles: this.styles,
184-
mapId: this.mapId,
185-
};
183+
return Object.assign({ zoom: this.zoom, center: { lat: this.centerLatitude, lng: this.centerLongitude }, mapTypeId: this.mapType, styles: this.styles, mapId: this.mapId }, (this.colorScheme && { colorScheme: this.colorScheme }));
186184
}
187185
mapApiLoaded() {
188186
this.initGMap();
@@ -399,6 +397,10 @@ var LitGoogleMap = (function (exports) {
399397
n({ type: String, attribute: "map-id" }),
400398
__metadata("design:type", Object)
401399
], exports.LitGoogleMap.prototype, "mapId", void 0);
400+
__decorate([
401+
n({ type: String, attribute: "color-scheme" }),
402+
__metadata("design:type", String)
403+
], exports.LitGoogleMap.prototype, "colorScheme", void 0);
402404
exports.LitGoogleMap = __decorate([
403405
t("lit-google-map")
404406
], exports.LitGoogleMap);

dist/lit-google-map.bundle.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lit-google-map.esm.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
1515
this.centerLongitude = 150.644;
1616
this.language = "";
1717
this.mapId = "DEMO_MAP_ID";
18+
this.colorScheme = "";
1819
this.map = null;
1920
this.markers = [];
2021
this.shapes = [];
@@ -33,6 +34,9 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
3334
else if (name === "zoom") {
3435
this.map.setZoom(this.zoom);
3536
}
37+
else if (name === "color-scheme" && this.colorScheme) {
38+
this.map.setOptions({ colorScheme: this.colorScheme });
39+
}
3640
}
3741
}
3842
dispatchViewChanged() {
@@ -105,13 +109,7 @@ let LitGoogleMap = class LitGoogleMap extends LitElement {
105109
this.updateControls();
106110
}
107111
getMapOptions() {
108-
return {
109-
zoom: this.zoom,
110-
center: { lat: this.centerLatitude, lng: this.centerLongitude },
111-
mapTypeId: this.mapType,
112-
styles: this.styles,
113-
mapId: this.mapId,
114-
};
112+
return Object.assign({ zoom: this.zoom, center: { lat: this.centerLatitude, lng: this.centerLongitude }, mapTypeId: this.mapType, styles: this.styles, mapId: this.mapId }, (this.colorScheme && { colorScheme: this.colorScheme }));
115113
}
116114
mapApiLoaded() {
117115
this.initGMap();
@@ -328,6 +326,10 @@ __decorate([
328326
property({ type: String, attribute: "map-id" }),
329327
__metadata("design:type", Object)
330328
], LitGoogleMap.prototype, "mapId", void 0);
329+
__decorate([
330+
property({ type: String, attribute: "color-scheme" }),
331+
__metadata("design:type", String)
332+
], LitGoogleMap.prototype, "colorScheme", void 0);
331333
LitGoogleMap = __decorate([
332334
customElement("lit-google-map")
333335
], LitGoogleMap);

dist/lit-google-map.esm.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lit-google-map",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Google Maps web components based on Lit v2",
55
"private": false,
66
"license": "MIT",

src/lit-google-map.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class LitGoogleMap extends LitElement {
5858
@property({ type: String, attribute: "map-id" })
5959
mapId = "DEMO_MAP_ID";
6060

61+
@property({ type: String, attribute: "color-scheme" })
62+
colorScheme: google.maps.ColorScheme | "" = "";
63+
6164
map: google.maps.Map | null = null;
6265

6366
markers: Array<Node> = [];
@@ -78,6 +81,8 @@ export class LitGoogleMap extends LitElement {
7881
});
7982
} else if (name === "zoom") {
8083
this.map.setZoom(this.zoom);
84+
} else if (name === "color-scheme" && this.colorScheme) {
85+
this.map.setOptions({ colorScheme: this.colorScheme });
8186
}
8287
}
8388
}
@@ -187,6 +192,7 @@ export class LitGoogleMap extends LitElement {
187192
mapTypeId: this.mapType,
188193
styles: this.styles,
189194
mapId: this.mapId,
195+
...(this.colorScheme && { colorScheme: this.colorScheme }),
190196
};
191197
}
192198

0 commit comments

Comments
 (0)