@maptrip/map-tiles 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +239 -0
- package/dist/map-tiles.js +13558 -0
- package/lib/api-extensions/google/MapTripGoogleMapType.js +25 -0
- package/lib/api-extensions/leaflet/MapTripLeafletGridLayer.js +24 -0
- package/lib/api-extensions/openlayers/MapTripOpenLayersSource.js +43 -0
- package/lib/core/CollisionDetector.js +65 -0
- package/lib/core/VectorTileFactory.js +245 -0
- package/lib/core/VectorTileLoader.js +127 -0
- package/lib/core/VectorTileRenderer.js +826 -0
- package/lib/core/constants.js +18 -0
- package/lib/core/rendering_config_default.js +1107 -0
- package/lib/core/rendering_config_grayscale.js +1107 -0
- package/lib/core/rendering_config_traffic.js +120 -0
- package/lib/main.js +18 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
# map-tiles
|
|
2
|
+
|
|
3
|
+
[MapTrip](https://maptrip.de) is a GPS navigation software for trucks, waste management and emergency vehicles.
|
|
4
|
+
|
|
5
|
+
This project allows you to use MapTrip map tiles in third-party mapping APIs like LeafletJS, OpenLayers or Google Maps.
|
|
6
|
+
For all supported APIs, there is a class with which you can add our maps to the respective API.
|
|
7
|
+
|
|
8
|
+
> To use this API, you need a MapTrip API key. If you are already a user and do not have an API key, please contact our [support team](mailto:support@infoware.de).
|
|
9
|
+
|
|
10
|
+
## Authorization
|
|
11
|
+
|
|
12
|
+
In order to utilize the functionalities provided by the map-tiles package, you need a token obtained through your MapTrip API key. If you don't already have an API key, please contact our [support team](mailto:support@infoware.de).
|
|
13
|
+
|
|
14
|
+
Tokens are granted with a validity period of up to 30 days. After that timeframe, you have to generate a new token. To get a new token, initiate a POST request with your API Key and a new duration to https://api.maptrip.de/v1/authenticate/apikey:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
fetch("https://api.maptrip.de/v1/authenticate/apikey", {
|
|
18
|
+
method: "POST",
|
|
19
|
+
headers: {
|
|
20
|
+
Accept: "application/json",
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
},
|
|
23
|
+
body: JSON.stringify({
|
|
24
|
+
apikey: "YOUR_API_KEY",
|
|
25
|
+
duration: 2592000,
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The response body will include the key `token` in the schema:
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"token": string,
|
|
35
|
+
"authorization": string,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Integration in your mapping API
|
|
41
|
+
|
|
42
|
+
### LeafletJS
|
|
43
|
+
|
|
44
|
+
Supported versions: 1.0.0 and newer (recommended: 1.9.x)
|
|
45
|
+
|
|
46
|
+
Install [LeafletJS](https://leafletjs.com/) with `npm install leaflet@~1.9.x`. To use MapTrip map tiles in LeafletJS,
|
|
47
|
+
you create an instance of `MapTripLeafletGridLayer` and add it to the layers of a map:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { MapTripLeafletGridLayer } from "dist/map-tiles.js";
|
|
51
|
+
|
|
52
|
+
import L from 'leaflet';
|
|
53
|
+
import 'leaflet/dist/leaflet.css';
|
|
54
|
+
|
|
55
|
+
const layer = new MapTripLeafletGridLayer({
|
|
56
|
+
provider: "TomTom",
|
|
57
|
+
token: "Insert your MapTrip token here",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
L.map("map", {
|
|
61
|
+
center: [50.94017, 6.95988],
|
|
62
|
+
zoom: 13,
|
|
63
|
+
layers: [layer],
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`MapTripLeafletGridLayer` can be configured with all properties listed in the section _Properties_, and also with these:
|
|
68
|
+
|
|
69
|
+
- `token`: A valid and non-expired token for your account, see section _Authorization_ (**required**)
|
|
70
|
+
- `attribution`: The copyright notes to show in the map
|
|
71
|
+
- `minZoom`: The minimum zoom level for the map (must not be smaller than 2)
|
|
72
|
+
- `maxZoom`: The maximum zoom level for the map (must not be larger than 18)
|
|
73
|
+
|
|
74
|
+
### OpenLayers
|
|
75
|
+
|
|
76
|
+
Supported versions: 7.0.0 and newer (recommended: 8.2.x)
|
|
77
|
+
|
|
78
|
+
Install [OpenLayers](https://openlayers.org/) with `npm install ol@~8.2.x`. To create a map application with OpenLayers
|
|
79
|
+
and MapTrip map tiles, you create an instance of `MapTripOpenLayersSource` and add it to the layers of a map:
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
import { MapTripOpenLayersSource } from "dist/map-tiles.js";
|
|
83
|
+
|
|
84
|
+
import Map from "ol/Map.js";
|
|
85
|
+
import View from "ol/View.js";
|
|
86
|
+
import TileLayer from "ol/layer/Tile.js";
|
|
87
|
+
import * as olProj from "ol/proj";
|
|
88
|
+
import "ol/ol.css";
|
|
89
|
+
|
|
90
|
+
new Map({
|
|
91
|
+
layers: [
|
|
92
|
+
new TileLayer({
|
|
93
|
+
source: new MapTripOpenLayersSource({
|
|
94
|
+
provider: "TomTom",
|
|
95
|
+
token: "Insert your MapTrip token here",
|
|
96
|
+
}),
|
|
97
|
+
}),
|
|
98
|
+
],
|
|
99
|
+
view: new View({
|
|
100
|
+
projection: "EPSG:3857",
|
|
101
|
+
center: olProj.fromLonLat([6.95988, 50.94017]),
|
|
102
|
+
zoom: 13,
|
|
103
|
+
}),
|
|
104
|
+
target: "map",
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`MapTripOpenLayersSource` can be configured with all properties listed in the section _Properties_, and also with these:
|
|
109
|
+
|
|
110
|
+
- `token`: A valid and non-expired token for your account, see section _Authorization_ (**required**)
|
|
111
|
+
|
|
112
|
+
### Google Maps
|
|
113
|
+
|
|
114
|
+
Supported versions: 1.16.1 and newer
|
|
115
|
+
|
|
116
|
+
Install the [Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/overview)
|
|
117
|
+
JS loader with `npm install @googlemaps/js-api-loader@~1.16.x`.
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
import { MapTripGoogleMapType } from "dist/map-tiles.js";
|
|
121
|
+
import { Loader } from "@googlemaps/js-api-loader";
|
|
122
|
+
|
|
123
|
+
new Loader({
|
|
124
|
+
apiKey: "Insert your Google Maps API key here",
|
|
125
|
+
})
|
|
126
|
+
.importLibrary("maps")
|
|
127
|
+
.then(({ Map }) => {
|
|
128
|
+
const map = new Map(document.getElementById("map"), {
|
|
129
|
+
zoom: 13,
|
|
130
|
+
center: { lat: 50.94017, lng: 6.95988 },
|
|
131
|
+
mapTypeId: "MapTrip",
|
|
132
|
+
mapTypeControlOptions: {
|
|
133
|
+
mapTypeIds: ["roadmap", "satellite", "MapTrip"],
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
let mapType = new MapTripGoogleMapType({
|
|
138
|
+
token: "Insert your MapTrip token here",
|
|
139
|
+
name: "MapTrip",
|
|
140
|
+
provider: "TomTom",
|
|
141
|
+
});
|
|
142
|
+
map.mapTypes.set("MapTrip", mapType);
|
|
143
|
+
})
|
|
144
|
+
.catch((e) => {
|
|
145
|
+
console.error("Failed to import Google Maps API:", e);
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
`MapTripGoogleMapType` can be configured with all properties listed in the section _Properties_, and also with these:
|
|
150
|
+
|
|
151
|
+
- `token`: A valid and non-expired token for your account, see section _Authorization_ (**required**)
|
|
152
|
+
- `name`: The name Google Maps will show in the map types selection
|
|
153
|
+
|
|
154
|
+
### Other Maps
|
|
155
|
+
|
|
156
|
+
If you use an API that is not in the list above, you can integrate the tiles yourself.
|
|
157
|
+
To do this, you need to find out how you can integrate your own function that provides the tiles.
|
|
158
|
+
|
|
159
|
+
This function will be called with the x, y and z indexes of all tiles. To create a tile for an index,
|
|
160
|
+
you can use our factory class. This is initialized with the map provider you want to use:
|
|
161
|
+
|
|
162
|
+
```js
|
|
163
|
+
const factory = VectorTileFactory.createFactory({ provider: "TomTom" });
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Using this factory, you can create tiles by providing their x, y and z indexes and your MapTrip token (see _Authorization_):
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
let canvas = factory.getJsonTile(x, y, z, token);
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
You can also provide a callback which is called when the tile is rendered:
|
|
173
|
+
|
|
174
|
+
```js
|
|
175
|
+
let canvas = factory.getJsonTile(x, y, z, token, () => {
|
|
176
|
+
canvas.className = "loaded";
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Please refer to the documentation of your API to see how you can implement your own tiles provider.
|
|
181
|
+
|
|
182
|
+
## Map Data Providers
|
|
183
|
+
|
|
184
|
+
The maps can be rendered with map data from various providers. To do this, set the property `provider`
|
|
185
|
+
to one of the strings `TomTom`, `HERE` or `OpenStreetmap` when creating a factory:
|
|
186
|
+
|
|
187
|
+
```js
|
|
188
|
+
const factory = VectorTileFactory.createFactory({
|
|
189
|
+
provider: "TomTom",
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Which data you are allowed to use depends on your MapTrip license.
|
|
194
|
+
If in doubt, please contact our [support team](mailto:support@infoware.de).
|
|
195
|
+
|
|
196
|
+
## Properties
|
|
197
|
+
|
|
198
|
+
You can specify a third parameter with properties when creating the factory. These values are available:
|
|
199
|
+
|
|
200
|
+
| Property | Description | Default Value |
|
|
201
|
+
| ----------------- | ------------------------------------------------------------------------------------------------- | ------------------------ |
|
|
202
|
+
| provider | The map data provider (`TomTom`, `HERE` or `OpenStreetmap`) | OpenStreetmap |
|
|
203
|
+
| baseMap | Set to `false` for a traffic overlay which can be used on top of e.g. an aerial view | true |
|
|
204
|
+
| traffic | Add traffic flows to the map tiles (only available for TomTom and HERE maps) | false |
|
|
205
|
+
| timeout | Load timeout for tiles in milliseconds. Increase this if you have a very slow internet connection | 5000 |
|
|
206
|
+
| parallelDownloads | The number of tiles that are loaded in parallel | 12 |
|
|
207
|
+
| renderingConfig | Set a custom rendering configuration to customize layers, colors, line widths etc. | RENDERING_CONFIG_DEFAULT |
|
|
208
|
+
|
|
209
|
+
This factory initializes a factory with TomTom data and traffic flows:
|
|
210
|
+
|
|
211
|
+
```js
|
|
212
|
+
const factory = VectorTileFactory.createFactory({
|
|
213
|
+
provider: "TomTom",
|
|
214
|
+
traffic: true,
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Here is an example of how you can increase the timeout to 10 seconds:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
const factory = VectorTileFactory.createFactory({
|
|
222
|
+
provider: "OpenStreetmap",
|
|
223
|
+
timeout: 10000,
|
|
224
|
+
});
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
If you want to display traffic flows on a bitmap map (e.g. aerial images), you can use
|
|
228
|
+
a factory that only renders traffic and no base map:
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
const factory = VectorTileFactory.createFactory({
|
|
232
|
+
provider: "HERE",
|
|
233
|
+
baseMap: false,
|
|
234
|
+
traffic: true,
|
|
235
|
+
});
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
It will create tiles which have a transparent background and semi-transparent traffic flows.
|
|
239
|
+
To use them, you mapping API has to be able to use both base layers and overlays.
|