Maps SDK with TypeScript
Create a map using the SDK based on TypeScript. Benefit from features like code completion, type safety, accurate documentation, and backward compatibility. Save time on your project by reducing typos and mistakes. No need to worry about changes to API endpoints and how they may affect your code.
Choose from a wide range of bundlers to find the best solution for your project. Whether you prefer Parcel, Webpack, Rollup, Turbopack, or any other bundler, you have plenty of options to choose from.
-
Create a
<div>
element with a certain id where you want your map to be.Add
<div>
tag into your page. This div will be the container where the map will be loaded. -
Include the following code in your TypeScript
app.ts
file. -
Replace
YOUR_MAPTILER_API_KEY_HERE
with your actual MapTiler API key. -
Create the map containter style. Add the map containter style to you stylesheet
style.css
. The div must have non-zero height. In this case we are going to make a fullscreen map.
Check out the tutorial How to create a map with TypeScript and Parcel.
-
Install bundler and build tools. This tutorial will use Parcel because it supports TypeScript out of the box without any additional configuration.
-
Create the TypeScript config file.
-
Update the package.json scripts. Create the
dev
andbuild
scripts. -
Create a
src
folder and inside this forder create 3 files:index.html
,app.ts
, andstyle.css
. -
Copy the following code, paste it into
index.html
file. The<div id="map">
will be the container where the map will be loaded. -
Create the map container style. Add the map container style to you stylesheet
style.css
. The div must have non-zero height. In this case we are going to make a fullscreen map. -
Include the following code in your
app.ts
file. -
Replace
YOUR_MAPTILER_API_KEY_HERE
with your actual MapTiler API key. -
Running the dev server. To see the map run the local server. Open a terminal and write.
- Now you can see your application opening http://localhost:1234 in your browser. By default, the map will be initialized with the style maptilersdk.MapStyle.STREETS and centered on the actual visitor location using the IP geolocation API provided by MapTiler Cloud.