Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds instructions of using Typescript #113

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/en/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ The following modules will be covered in this workshop:
* [WebGL Rendering](webgl/README.md) - Rendering meteorite impact sites with WebGL.
* [Vector Tiles](vectortile/README.md) - Create beautiful maps with vector tiles.
* [Raster Operations](raster/README.md) - Manipulating pixels with a raster source.
* [Typescript](typescript/README.md) - Learn how to add a map to a webpage.
* [Deploying](deploying/README.md) - Building applications for production.
1 change: 1 addition & 0 deletions doc/en/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@
* [Map setup](raster/map.md)
* [Render elevation data](raster/elevation.md)
* [Render sea level](raster/raster.md)
* [Typescript](typescript/README.md)
* [Deploying](deploying/README.md)
15 changes: 15 additions & 0 deletions doc/en/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Typescript

Make sure you've completed the [Basics](../basics/README.md).

Typescript should already be installed, but if not:

npm i typescript -D

The openlayers typings should already be installed, but if not:

npm i @types/ol -D

Start the typescript transpiler in watch mode using the `tsc` script:

npm run tsc
Binary file added doc/en/typescript/map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions package-lock.json

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

20 changes: 20 additions & 0 deletions src/en/examples/typescript/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import "ol/ol.css";
import { Map, View } from "ol";
import TileLayer from "ol/layer/Tile";
import XYZSource from "ol/source/XYZ";
import { fromLonLat } from "ol/proj";

new Map({
target: "map-container",
layers: [
new TileLayer({
source: new XYZSource({
url: "http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg",
}),
}),
],
view: new View({
center: fromLonLat([0, 0]),
zoom: 2,
}),
});
23 changes: 23 additions & 0 deletions src/en/examples/typescript/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>OpenLayers</title>
<style>
html,
body,
#map-container {
margin: 0;
height: 100%;
width: 100%;
font-family: sans-serif;
}
</style>
</head>

<body>
<div id="map-container"></div>
</body>

</html>
13 changes: 13 additions & 0 deletions src/en/examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ES2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "ES2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"strict": true, /* Enable all strict type-checking options. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"skipLibCheck": true, /* Skip type checking of declaration files. */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"files": [
"./main.ts"
]
}
Loading