Skip to content

Commit 14c8426

Browse files
committed
docs(ol-heatmap-layer): add documentation for ol-heatmap-layer
closes #166
1 parent 180df6f commit 14c8426

File tree

4 files changed

+199
-0
lines changed

4 files changed

+199
-0
lines changed

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export default defineConfig({
6161
text: "ol-animated-clusterlayer",
6262
link: "/componentsguide/layers/animatedclusterlayer/",
6363
},
64+
{
65+
text: "ol-heatmap-layer",
66+
link: "/componentsguide/layers/heatmaplayer/",
67+
},
6468
{
6569
text: "ol-image-layer",
6670
link: "/componentsguide/layers/imagelayer/",
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# ol-heatmap-layer
2+
3+
ol-heatmap-layer can render vector data as a heatmap from various backend services. It should be used with together with ol-source-vector component.
4+
5+
<script setup>
6+
import HeatmapLayerDemo from "@demos/HeatmapLayerDemo.vue"
7+
</script>
8+
9+
<ClientOnly>
10+
<HeatmapLayerDemo />
11+
</ClientOnly>
12+
13+
## Usage
14+
15+
Example below shows how you can use ol-heatmap-layer and ol-source-vector to render a heatmap from a backend source.
16+
17+
```html
18+
<template>
19+
<ol-map
20+
ref="map"
21+
:loadTilesWhileAnimating="true"
22+
:loadTilesWhileInteracting="true"
23+
style="height:800px"
24+
>
25+
<ol-view
26+
ref="view"
27+
:center="center"
28+
:rotation="rotation"
29+
:zoom="zoom"
30+
:projection="projection"
31+
/>
32+
33+
<ol-tile-layer>
34+
<ol-source-osm />
35+
</ol-tile-layer>
36+
37+
<ol-heatmap-layer
38+
title="heatmap"
39+
:blur="20"
40+
:radius="20"
41+
:weight="heatmapWeight"
42+
zIndex="1"
43+
>
44+
<ol-source-vector
45+
ref="earthquakes"
46+
url="https://raw.githubusercontent.com/openlayers/openlayers/main/examples/data/kml/2012_Earthquakes_Mag5.kml"
47+
:format="kml"
48+
>
49+
</ol-source-vector>
50+
</ol-heatmap-layer>
51+
</ol-map>
52+
</template>
53+
```
54+
55+
```js
56+
import { ref, inject } from "vue";
57+
export default {
58+
setup() {
59+
const center = ref([101.97, 4.21]);
60+
const projection = ref("EPSG:4326");
61+
const zoom = ref(5);
62+
const rotation = ref(0);
63+
const format = inject("ol-format");
64+
const geoJson = new format.GeoJSON();
65+
const kml = new format.KML({ extractStyles: false });
66+
const heatmapWeight = function (feature) {
67+
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
68+
// standards-violating <magnitude> tag in each Placemark. We extract it from
69+
// the Placemark's name instead.
70+
const name = feature.get("name");
71+
const magnitude = parseFloat(name.substr(2));
72+
return magnitude - 5;
73+
};
74+
return {
75+
center,
76+
projection,
77+
zoom,
78+
rotation,
79+
geoJson,
80+
heatmapWeight,
81+
kml,
82+
};
83+
},
84+
};
85+
```
86+
87+
## Properties
88+
89+
# weight
90+
91+
- **Type**: `Function`
92+
- **Default**: `none`
93+
94+
A function that returns a weight from a feature. Weight values should range from 0 to 1 (and values outside will be clamped to that range).
95+
96+
# extent
97+
98+
- **Type**: `Array`
99+
100+
The bounding extent for layer rendering. The layer will not be rendered outside of this extent.
101+
102+
# blur
103+
104+
- **Type**: `Number`
105+
- **Default**: `15`
106+
107+
The blur size in pixels.
108+
109+
# radius
110+
111+
- **Type**: `Number`
112+
113+
The radius size in pixels.

docs/public/sitemap.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<lastmod>2021-08-15T21:05:05+00:00</lastmod>
5353
<priority>0.80</priority>
5454
</url>
55+
<url>
56+
<loc>https://vue3openlayers.netlify.app/componentsguide/layers/heatmaplayer/</loc>
57+
<lastmod>2023-02-14T21:30:20+00:00</lastmod>
58+
<priority>0.80</priority>
59+
</url>
5560
<url>
5661
<loc>https://vue3openlayers.netlify.app/componentsguide/layers/vectorlayer/</loc>
5762
<lastmod>2021-08-15T21:05:05+00:00</lastmod>

src/demos/HeatmapLayerDemo.vue

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<template>
2+
<ol-map
3+
ref="map"
4+
:loadTilesWhileAnimating="true"
5+
:loadTilesWhileInteracting="true"
6+
style="height: 400px"
7+
>
8+
<ol-view
9+
ref="view"
10+
:center="center"
11+
:rotation="rotation"
12+
:zoom="zoom"
13+
:projection="projection"
14+
/>
15+
16+
<ol-tile-layer>
17+
<ol-source-osm />
18+
</ol-tile-layer>
19+
20+
<ol-heatmap-layer
21+
title="heatmap"
22+
:blur="20"
23+
:radius="20"
24+
:weight="heatmapWeight"
25+
zIndex="1"
26+
>
27+
<ol-source-vector
28+
ref="earthquakes"
29+
url="https://raw.githubusercontent.com/openlayers/openlayers/main/examples/data/kml/2012_Earthquakes_Mag5.kml"
30+
:format="kml"
31+
>
32+
</ol-source-vector>
33+
</ol-heatmap-layer>
34+
</ol-map>
35+
</template>
36+
37+
<script>
38+
import { ref, inject } from "vue";
39+
export default {
40+
setup() {
41+
const center = ref([101.97, 4.21]);
42+
const projection = ref("EPSG:4326");
43+
const zoom = ref(5);
44+
const rotation = ref(0);
45+
const format = inject("ol-format");
46+
const geoJson = new format.GeoJSON();
47+
const kml = new format.KML({ extractStyles: false });
48+
const heatmapWeight = function (feature) {
49+
// 2012_Earthquakes_Mag5.kml stores the magnitude of each earthquake in a
50+
// standards-violating <magnitude> tag in each Placemark. We extract it from
51+
// the Placemark's name instead.
52+
const name = feature.get("name");
53+
const magnitude = parseFloat(name.substr(2));
54+
return magnitude - 5;
55+
};
56+
return {
57+
center,
58+
projection,
59+
zoom,
60+
rotation,
61+
geoJson,
62+
heatmapWeight,
63+
kml,
64+
};
65+
},
66+
};
67+
</script>
68+
69+
<style>
70+
.overlay-content {
71+
background: red !important;
72+
color: white;
73+
box-shadow: 0 5px 10px rgb(2 2 2 / 20%);
74+
padding: 10px 20px;
75+
font-size: 16px;
76+
}
77+
</style>

0 commit comments

Comments
 (0)