Skip to content

Commit f091d87

Browse files
added geojson format support
1 parent 858b9df commit f091d87

File tree

7 files changed

+714
-211
lines changed

7 files changed

+714
-211
lines changed

example/geojson.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
5+
<meta charset="utf-8"/>
6+
7+
<title>GeoJson Overlay</title>
8+
<link rel="stylesheet" href="./styles.css">
9+
</head>
10+
<body>
11+
<div id="info"></div>
12+
<script src="./geojson.js" type="module"></script>
13+
</body>
14+
</html>

example/geojson.js

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

src/three/plugins/images/EPSGTilesPlugin.js

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { EllipsoidProjectionTilesPlugin } from './EllipsoidProjectionTilesPlugin
55
import { XYZImageSource } from './sources/XYZImageSource.js';
66
import { TMSImageSource } from './sources/TMSImageSource.js';
77
import { WMTSImageSource } from './sources/WMTSImageSource.js';
8-
import { WMSImageSource } from './sources/WMSImageSource.js';
8+
9+
import { GeoJSONImageSource } from './sources/GeoJSONImageSource.js';
10+
911

1012
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
1113
export class XYZTilesPlugin extends EllipsoidProjectionTilesPlugin {
@@ -80,34 +82,15 @@ export class WMTSTilesPlugin extends EllipsoidProjectionTilesPlugin {
8082

8183
}
8284

83-
export class WMSTilesPlugin extends EllipsoidProjectionTilesPlugin {
85+
export class GeoJSONTilesPlugin extends EllipsoidProjectionTilesPlugin {
8486

8587
constructor( options = {} ) {
8688

87-
const {
88-
baseUrl,
89-
layer,
90-
crs,
91-
format,
92-
tileDimension,
93-
styles,
94-
version,
95-
...rest
96-
} = options;
89+
super( options );
9790

98-
super( rest );
99-
100-
this.name = 'WMS_TILES_PLUGIN';
101-
this.imageSource = new WMSImageSource( {
102-
baseUrl,
103-
layer,
104-
crs,
105-
format,
106-
tileDimension,
107-
styles,
108-
version
109-
} );
91+
this.name = 'GEOJSON_TILES_PLUGIN';
92+
this.imageSource = new GeoJSONImageSource( options );
11093

11194
}
11295

113-
}
96+
}

src/three/plugins/images/ImageOverlayPlugin.d.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,22 @@ export class XYZTilesOverlay extends ImageOverlay {
3838

3939
}
4040

41-
export class WMSTilesOverlay extends ImageOverlay {
41+
export class GeoJSONTilesOverlay extends ImageOverlay {
4242

4343
constructor( options: {
44-
baseUrl: string,
45-
layer: string,
46-
crs: string,
47-
format: string,
48-
tileDimension: number,
49-
styles: string,
50-
version: string,
51-
bounds: [ number, number, number, number ],
52-
levels: number,
53-
opacity: number,
54-
extraHeaders?:{ [key: string]: string}
55-
44+
// rasterize GeoJSON per tile (forwarded to GeoJSONImageSource)
45+
geojson?: any, // FeatureCollection or null (if url provided)
46+
url?: string, // optional URL alternative to geojson object
47+
tileDimension?: number, // tile size in px (runtime name: tileDimension)
48+
levels?: number, // max rasterization zoom
49+
bounds?: [ number, number, number, number ],
50+
projection?: string, // 'EPSG:3857' or 'EPSG:4326'
51+
pointRadius?: number,
52+
strokeStyle?: string,
53+
fillStyle?: string,
54+
color?: number | Color,
55+
opacity?: number,
56+
frame?: Matrix4 | null,
5657
} );
5758

5859
}

src/three/plugins/images/ImageOverlayPlugin.js

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { wrapOverlaysMaterial } from './overlays/wrapOverlaysMaterial.js';
2323
import { GeometryClipper } from '../utilities/GeometryClipper.js';
2424
import { WMTSImageSource } from './sources/WMTSImageSource.js';
2525
import { MemoryUtils } from '3d-tiles-renderer/three';
26-
import { WMSImageSource } from './sources/WMSImageSource.js';
26+
import { GeoJSONImageSource } from './sources/GeoJSONImageSource.js';
2727

2828
const _matrix = /* @__PURE__ */ new Matrix4();
2929
const _vec = /* @__PURE__ */ new Vector3();
@@ -1550,12 +1550,12 @@ export class XYZTilesOverlay extends ImageOverlay {
15501550

15511551
}
15521552

1553-
export class WMSTilesOverlay extends ImageOverlay {
1553+
export class GeoJSONTilesOverlay extends ImageOverlay {
15541554

15551555
constructor( options = {} ) {
15561556

15571557
super( options );
1558-
this.imageSource = new WMSImageSource( options );
1558+
this.imageSource = new GeoJSONImageSource( options );
15591559
this.imageSource.fetchData = ( ...args ) => this.fetch( ...args );
15601560

15611561
}
@@ -1573,24 +1573,6 @@ export class WMSTilesOverlay extends ImageOverlay {
15731573

15741574
}
15751575

1576-
fetch( url, options = {} ) {
1577-
1578-
// Add auth headers if present
1579-
if ( this.imageSource && this.imageSource.extraHeaders ) {
1580-
1581-
const { extraHeaders } = this.imageSource;
1582-
options.headers = options.headers || {};
1583-
Object.entries( extraHeaders ).forEach( ( [ key, value ] ) => {
1584-
1585-
options.headers[ key ] = value;
1586-
1587-
} );
1588-
1589-
}
1590-
return fetch( url, options );
1591-
1592-
}
1593-
15941576
}
15951577

15961578
export class WMTSTilesOverlay extends ImageOverlay {

0 commit comments

Comments
 (0)