Skip to content

Commit

Permalink
Merge pull request #133 from openlayers/f4g21
Browse files Browse the repository at this point in the history
Version updates for the new English version
  • Loading branch information
ahocevar authored Sep 24, 2021
2 parents 39541b9 + bbe8df1 commit e05db06
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 167 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openlayers-workshop",
"version": "6.7.0-en.1",
"version": "6.8.0-en.1",
"description": "OpenLayers workshop",
"private": true,
"repository": {
Expand Down
29 changes: 1 addition & 28 deletions src/en/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,8 @@
<head>
<meta charset="utf-8">
<title>OpenLayers</title>
<style>
@import "node_modules/ol/ol.css";
</style>
<style>
html, body, #map-container {
margin: 0;
height: 100%;
width: 100%;
font-family: sans-serif;
}

/*! [style] */
#year {
position: absolute;
bottom: 1em;
left: 1em;
color: white;
-webkit-text-stroke: 1px black;
font-size: 2em;
font-weight: bold;
}
/*! [style] */
</style>
</head>
<body>
<div id="map-container"></div>
<!--! [markup] -->
<div id="year"></div>
<!--! [markup] -->
<script src="./main.js" type="module"></script>
</body>
</html>
</html>
129 changes: 1 addition & 128 deletions src/en/main.js
Original file line number Diff line number Diff line change
@@ -1,128 +1 @@
import 'ol/ol.css';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import {Map, View} from 'ol';
import {Stamen, Vector as VectorSource} from 'ol/source';
import {Tile as TileLayer, WebGLPoints as WebGLPointsLayer} from 'ol/layer';
import {fromLonLat} from 'ol/proj';

const source = new VectorSource();

const client = new XMLHttpRequest();
client.open('GET', './data/meteorites.csv');
client.onload = function () {
const csv = client.responseText;
let curIndex;
let prevIndex = 0;
const features = [];

while ((curIndex = csv.indexOf('\n', prevIndex)) > 0) {
const line = csv.substr(prevIndex, curIndex - prevIndex).split(',');

prevIndex = curIndex + 1;
if (prevIndex === 0) {
continue; // skip header
}

const coords = fromLonLat([parseFloat(line[4]), parseFloat(line[3])]);

features.push(
new Feature({
mass: parseFloat(line[1]) || 0,
year: parseInt(line[2]) || 0,
geometry: new Point(coords),
})
);
}
source.addFeatures(features);
};
client.send();

//! [years]
const minYear = 1850;
const maxYear = 2015;
const span = maxYear - minYear;
const rate = 10; // years per second

const start = Date.now();

const styleVariables = {
currentYear: minYear,
};
//! [years]

//! [expressions]
const period = 10;
const periodStart = ['-', ['var', 'currentYear'], period];
const decay = [
'interpolate',
['linear'],
['get', 'year'],
periodStart,
0,
['var', 'currentYear'],
1,
];
//! [expressions]

const meteorites = new WebGLPointsLayer({
source: source,
style: {
//! [variables]
variables: styleVariables,
//! [variables]
//! [filter]
filter: ['between', ['get', 'year'], periodStart, ['var', 'currentYear']],
//! [filter]
symbol: {
symbolType: 'circle',
//! [size]
size: [
'*',
decay,
['+', ['*', ['clamp', ['*', ['get', 'mass'], 1 / 20000], 0, 1], 18], 8],
],
//! [size]
color: 'rgb(255, 0, 0)',
//! [opacity]
opacity: ['*', 0.5, decay],
//! [opacity]
},
},
//! [hitdetection]
disableHitDetection: true,
//! [hitdetection]
});

//! [declaration]
const map = new Map({
//! [declaration]
target: 'map-container',
layers: [
new TileLayer({
source: new Stamen({
layer: 'toner',
}),
}),
meteorites,
],
view: new View({
center: [0, 0],
zoom: 2,
}),
});

//! [animate]
const yearElement = document.getElementById('year');

function render() {
const elapsed = (rate * (Date.now() - start)) / 1000;
styleVariables.currentYear = Math.round(minYear + (elapsed % span));
yearElement.innerText = styleVariables.currentYear;

map.render();
requestAnimationFrame(render);
}

render();
//! [animate]
alert('Hello Workshop');
14 changes: 7 additions & 7 deletions src/en/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/en/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"colormap": "^2.3.2",
"kompas": "^0.0.1",
"ol": "^6.7.1-dev.1632492842023",
"ol": "^6.8.0",
"ol-hashed": "^2.1.0",
"ol-mapbox-style": "^6.4.2"
},
Expand Down

0 comments on commit e05db06

Please sign in to comment.