Add an example for the WebGLPointsLayer with editable style

This commit is contained in:
Olivier Guyot committed 2019-09-24 17:59:21 +02:00
1 parent 4d7562fca2
commit cb2c596a6d
3 files changed
+86

No files matched your search

@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type": "Feature", "geometry": {"type": "Point", "coordinates": [121.4961111, 25.0]}, "properties": {"city": "yungho", "country": "tw", "region": "03", "geopoint": [25.0, 121.4961111], "longitude": 121.4961111, "latitude": 25.0, "accentcity": "Yungho", "population": 207852}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-72.233333, -37.716667]}, "properties": {"city": "mulchen", "country": "cl", "region": "06", "geopoint": [-37.716667, -72.233333], "longitude": -72.233333, "latitude": -37.716667, "accentcity": "Mulchen", "population": 22170}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-73.6405556, 40.6386111]}, "properties": {"city": "oceanside", "country": "us", "region": "NY", "geopoint": [40.6386111, -73.6405556], "longitude": -73.6405556, "latitude": 40.6386111, "accentcity": "Oceanside", "population": 32622}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-70.966667, -32.85]}, "properties": {"city": "llaillay", "country": "cl", "region": "01", "geopoint": [-32.85, -70.966667], "longitude": -70.966667, "latitude": -32.85, "accentcity": "Llaillay", "population": 16646}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [35.6, 3.1166667]}, "properties": {"city": "lodwar", "country": "ke", "region": "08", "geopoint": [3.1166667, 35.6], "longitude": 35.6, "latitude": 3.1166667, "accentcity": "Lodwar", "population": 20219}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [10.1666667, 5.9333333]}, "properties": {"city": "bamenda", "country": "cm", "region": "07", "geopoint": [5.9333333, 10.1666667], "longitude": 10.1666667, "latitude": 5.9333333, "accentcity": "Bamenda", "population": 393871}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-45.533333, -20.283333]}, "properties": {"city": "arcos", "country": "br", "region": "15", "geopoint": [-20.283333, -45.533333], "longitude": -45.533333, "latitude": -20.283333, "accentcity": "Arcos", "population": 33356}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-43.716944, -22.747222]}, "properties": {"city": "seropedica", "country": "br", "region": "21", "geopoint": [-22.747222, -43.716944], "longitude": -43.716944, "latitude": -22.747222, "accentcity": "Serop\u00e9dica", "population": 54846}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-97.1413889, 32.5630556]}, "properties": {"city": "mansfield", "country": "us", "region": "TX", "geopoint": [32.5630556, -97.1413889], "longitude": -97.1413889, "latitude": 32.5630556, "accentcity": "Mansfield", "population": 36613}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-67.5419444, 10.1738889]}, "properties": {"city": "palo negro", "country": "ve", "region": "04", "geopoint": [10.1738889, -67.5419444], "longitude": -67.5419444, "latitude": 10.1738889, "accentcity": "Palo Negro", "population": 128895}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-42.683333, -5.366667]}, "properties": {"city": "demerval lobao", "country": "br", "region": "20", "geopoint": [-5.366667, -42.683333], "longitude": -42.683333, "latitude": -5.366667, "accentcity": "Demerval Lob\u00e3o", "population": 15285}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-48.666667, -28.233333]}, "properties": {"city": "imbituba", "country": "br", "region": "26", "geopoint": [-28.233333, -48.666667], "longitude": -48.666667, "latitude": -28.233333, "accentcity": "Imbituba", "population": 43450}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [-49.333333, -5.15]}, "properties": {"city": "itupiranga", "country": "br", "region": "16", "geopoint": [-5.15, -49.333333], "longitude": -49.333333, "latitude": -5.15, "accentcity": "Itupiranga", "population": 21301}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [121.75, 24.7666667]}, "properties": {"city": "ilan", "country": "tw", "region": "04", "geopoint": [24.7666667, 121.75], "longitude": 121.75, "latitude": 24.7666667, "accentcity": "Ilan", "population": 92920}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [49.1825, 11.2847222]}, "properties": {"city": "bosaso", "country": "so", "region": "03", "geopoint": [11.2847222, 49.1825], "longitude": 49.1825, "latitude": 11.2847222, "accentcity": "Bosaso", "population": 74287}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [64.570048, 31.820894]}, "properties": {"city": "geresk", "country": "af", "region": "10", "geopoint": [31.820894, 64.570048], "longitude": 64.570048, "latitude": 31.820894, "accentcity": "Geresk", "population": 43638}},{"type": "Feature", "geometry": {"type": "Point", "coordinates": [7.573271, 47.558395]}, "properties": {"city": "basel", "country": "ch", "region": "04", "geopoint": [47.558395, 7.573271], "longitude": 7.573271, "latitude": 47.558395, "accentcity": "Basel", "population": 164474}},{"type": "Feature", "geometry": {"typeLine truncated
+19
View File
@@ -0,0 +1,19 @@
---
layout: example.html
title: WebGL points layer
shortdesc: Using a WebGL-optimized layer to render a large quantities of points
docs: >
<p>This example shows how to use a `WebGLPointsLayer` to show a large amount of points on the map.</p>
tags: "webgl, point, layer, feature"
---
<div id="map" class="map"></div>
<label>Current style used for the layer</label>
<textarea style="width: 100%; height: 20rem; font-family: monospace; font-size: small;" id="style-editor"></textarea>
<small id="style-valid" style="display: none; color: forestgreen">
✓ style is valid
</small>
<small id="style-invalid" style="display: none; color: grey">
✗ style not yet valid...
</small>
+66
View File
@@ -0,0 +1,66 @@
import Map from '../src/ol/Map.js';
import View from '../src/ol/View.js';
import TileLayer from '../src/ol/layer/Tile.js';
import WebGLPointsLayer from '../src/ol/layer/WebGLPoints.js';
import GeoJSON from '../src/ol/format/GeoJSON.js';
import Vector from '../src/ol/source/Vector.js';
import OSM from '../src/ol/source/OSM.js';
const vectorSource = new Vector({
url: 'data/geojson/world-cities.geojson',
format: new GeoJSON()
});
let literalStyle = {
symbol: {
size: 4,
color: '#3388FF',
rotateWithView: false,
offset: [0, 0],
opacity: 1
}
};
let pointsLayer;
const map = new Map({
layers: [
new TileLayer({
source: new OSM()
})
],
target: document.getElementById('map'),
view: new View({
center: [0, 0],
zoom: 2
})
});
const editor = document.getElementById('style-editor');
function refreshLayer() {
if (pointsLayer) {
map.removeLayer(pointsLayer);
}
pointsLayer = new WebGLPointsLayer({
source: vectorSource,
literalStyle: literalStyle
});
map.addLayer(pointsLayer);
editor.value = JSON.stringify(literalStyle, null, ' ');
}
function setStyleStatus(valid) {
document.getElementById('style-valid').style.display = valid ? 'initial' : 'none';
document.getElementById('style-invalid').style.display = !valid ? 'initial' : 'none';
}
editor.addEventListener('input', function() {
try {
literalStyle = JSON.parse(editor.value);
refreshLayer();
setStyleStatus(true);
} catch (e) {
setStyleStatus(false);
}
});
refreshLayer();