Skip to content

Commit 5fa1e13

Browse files
committedOct 28, 2024
Updated
1 parent e482fb7 commit 5fa1e13

File tree

5 files changed

+43
-8
lines changed

5 files changed

+43
-8
lines changed
 

‎example/index.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
<div style="height: 500px;">
3030
<js-map id="map"
3131
accessToken="pk.eyJ1IjoiZGp0aG9ycGUiLCJhIjoiY2x5ZnJhZjAzMDJsYTJqcjd6eWQ3cjRvcSJ9.LvoT_wihG5VQtv008P-MPw">
32-
<js-mapsource type="geojson" data="{}"></js-mapsource>
32+
<js-mapsource id="area" type="geojson"
33+
data='{ "type": "Feature", "geometry": { "type": "Point", "coordinates": [0,0] } }'></js-mapsource>
34+
<js-maplayer id="points" source="#area" type="circle" paint='{ "circle-color" : "red" , "circle-radius"
35+
: 4, "circle-stroke-width" : 2, "circle-stroke-color" : "red" }'></js-maplayer>
3336
</js-map>
3437
</div>
3538
</js-container>
36-
3739
<js-container>
3840
TAG COLOR
3941
<js-tag color="primary" texttransform="uppercase">Primary</js-tag>

‎src/element/TableBodyElement.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class TableBodyElement extends LitElement {
9494
render() {
9595
const rows = this.#renderRows();
9696
const head = this.#head ? this.#head.render() : html``;
97-
return [html`<table>${head}<tbody>${rows}</tbody></table>`];
97+
return html`<table>${head}<tbody>${rows}</tbody></table>`;
9898
}
9999

100100
#renderRows() {

‎src/mapbox/MapElement.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { LitElement, html, css, nothing, unsafeCSS } from 'lit';
22
import { Map } from 'mapbox-gl';
33
import styles from './mapbox.css.txt';
4+
import { MapSourceElement } from './MapSourceElement';
5+
import { MapLayerElement } from './MapLayerElement';
46

57
/**
68
* @class MapElement
@@ -20,6 +22,8 @@ import styles from './mapbox.css.txt';
2022
*/
2123
export class MapElement extends LitElement {
2224
#map;
25+
#sources;
26+
#layers;
2327

2428
static get localName() {
2529
return 'js-map';
@@ -88,7 +92,30 @@ export class MapElement extends LitElement {
8892
});
8993
this.#map.on('load', () => {
9094
// Add map sources
91-
console.log('Map loaded');
95+
const sources = this.querySelectorAll(MapSourceElement.localName);
96+
for (const source of sources) {
97+
this.#map.addSource(source.id, {
98+
type: source.type,
99+
data: source.data,
100+
});
101+
}
102+
103+
// Add map layers
104+
const layers = this.querySelectorAll(MapLayerElement.localName);
105+
for (const layer of layers) {
106+
const source = this.querySelector(`${layer.source}`);
107+
if (!source) {
108+
console.error(`Source ${layer.source} not found for layer ${layer.id}`);
109+
} else {
110+
console.log(`Adding layer ${layer.id} with source ${source.data}`);
111+
this.#map.addLayer({
112+
id: layer.id,
113+
source: source.id,
114+
type: layer.type,
115+
paint: layer.paint,
116+
});
117+
}
118+
}
92119
});
93120
}
94121

‎src/mapbox/MapLayerElement.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,19 @@ import styles from 'mapbox-gl/dist/mapbox-gl.css';
99
*
1010
* @example
1111
* <js-map>
12-
* <js-maplayer></js-maplayer>
12+
* <js-maplayer type="circle" source="#source"></js-maplayer>
1313
* </js-map>
1414
*/
1515
export class MapLayerElement extends LitElement {
1616
static get localName() {
1717
return 'js-maplayer';
1818
}
19+
20+
static get properties() {
21+
return {
22+
source: { type: String, reflect: true },
23+
type: { type: String, reflect: true },
24+
paint: { type: Object, reflect: true },
25+
};
26+
}
1927
}

‎src/mapbox/MapSourceElement.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@ import { LitElement, html, css, nothing } from 'lit';
1111
* </js-map>
1212
*/
1313
export class MapSourceElement extends LitElement {
14-
#source;
15-
1614
static get localName() {
1715
return 'js-mapsource';
1816
}
1917

2018
static get properties() {
2119
return {
2220
type: { type: String, reflect: true },
23-
data: { type: Object, reflect: true }
21+
data: { type: Object, reflect: true },
2422
};
2523
}
2624
}

0 commit comments

Comments
 (0)