8 | This demo is using the UMD bundle. Add ?key=YOUR_API_KEY to the URL.
9 |
11 | Open JS console. 12 |
13 | 14 | 15 | 16 | 17 | 89 | 90 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import dts from "rollup-plugin-dts"; 2 | import esbuild from "rollup-plugin-esbuild"; 3 | import { nodeResolve } from "@rollup/plugin-node-resolve"; 4 | import globals from "rollup-plugin-node-globals"; 5 | import commonjs from "@rollup/plugin-commonjs"; 6 | import json from "@rollup/plugin-json"; 7 | 8 | const name = "maptiler-client" 9 | 10 | const bundles = [ 11 | // ES module, not minified + sourcemap 12 | { 13 | plugins: [ 14 | json(), 15 | esbuild(), 16 | ], 17 | output: [ 18 | { 19 | file: `dist/${name}.mjs`, 20 | format: "es", 21 | sourcemap: true 22 | } 23 | ], 24 | input: "src/index.ts", 25 | watch: { 26 | include: "src/**" 27 | }, 28 | external: ["quick-lru"] 29 | }, 30 | 31 | // CJS module, not minified + sourcemap 32 | { 33 | plugins: [ 34 | nodeResolve(), 35 | commonjs({ include: "node_modules/**" }), 36 | globals(), 37 | json(), 38 | esbuild() 39 | ], 40 | output: [ 41 | { 42 | file: `dist/${name}.cjs`, 43 | format: "cjs", 44 | sourcemap: true 45 | } 46 | ], 47 | input: "src/index.ts", 48 | watch: { 49 | include: "src/**" 50 | }, 51 | external: [] // Decided to include QuickLRU to the CJS bundle because it is otherwise not CJS compatible 52 | }, 53 | 54 | // UMD module, not minified 55 | { 56 | plugins: [ 57 | nodeResolve(), // for the standalone UMD, we want to resolve so that the bundle contains all the dep. 58 | commonjs({ include: "node_modules/**" }), 59 | globals(), 60 | json(), 61 | esbuild() 62 | ], 63 | output: [ 64 | { 65 | name: "maptilerClient", 66 | file: `dist/${name}.umd.js`, 67 | format: "umd", 68 | sourcemap: true 69 | } 70 | ], 71 | input: "src/index.ts", 72 | watch: { 73 | include: "src/**" 74 | }, 75 | external: [] 76 | }, 77 | 78 | // types 79 | { 80 | "plugins": [ 81 | dts() 82 | ], 83 | output: { 84 | file: `dist/${name}.d.ts`, 85 | format: "es" 86 | }, 87 | input: "src/index.ts" 88 | } 89 | ] 90 | 91 | if (process.env.NODE_ENV === "production") { 92 | bundles.push( 93 | // ES module, minified 94 | { 95 | plugins: [ 96 | json(), 97 | esbuild({ 98 | sourceMap: false, 99 | minify: true, 100 | }) 101 | ], 102 | output: [ 103 | { 104 | file: `dist/${name}.min.mjs`, 105 | format: "es", 106 | } 107 | ], 108 | input: "src/index.ts", 109 | external: ["quick-lru"], 110 | }, 111 | { 112 | plugins: [ 113 | nodeResolve(), // for the standalone UMD, we want to resolve so that the bundle contains all the dep. 114 | commonjs({ include: "node_modules/**" }), 115 | globals(), 116 | json(), 117 | esbuild({ 118 | sourceMap: false, 119 | minify: true, 120 | }) 121 | ], 122 | output: [ 123 | { 124 | name: "maptilerClient", 125 | file: `dist/${name}.umd.min.js`, 126 | format: "umd", 127 | sourcemap: false 128 | } 129 | ], 130 | input: "src/index.ts", 131 | watch: { 132 | include: "src/**" 133 | }, 134 | external: [] 135 | }) 136 | 137 | } 138 | 139 | export default bundles 140 | 141 | 142 | -------------------------------------------------------------------------------- /examples/test-browser-es.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |8 | This demo is using the ES module. 9 |
10 |11 | Open JS console. 12 |
13 | 14 | 15 | 16 | 99 | 100 | -------------------------------------------------------------------------------- /test/demProfiler/index.test.ts: -------------------------------------------------------------------------------- 1 | import fs from "fs"; 2 | import { promisify } from "util"; 3 | import { describe, it, expect } from "vitest"; 4 | import { profileLineString } from "../../src/demProfiler"; 5 | import sharp from "sharp"; 6 | 7 | const readFileAsync = promisify(fs.readFile); 8 | 9 | describe("profile", () => { 10 | it("simple line at zoom 13", async () => { 11 | const coordinates: GeoJSON.Position[] = [ 12 | [-111.88811277644503, 40.79618409829391], 13 | [-111.88645596614953, 40.797821596351326], 14 | [-111.88857300152719, 40.79938937578956], 15 | [-111.88811277644503, 40.80168871865277], 16 | [-111.88502926839493, 40.80350026602076], 17 | [-111.88553551598517, 40.80482405782945], 18 | ]; 19 | 20 | const path = { 21 | type: "Feature" as const, 22 | properties: {}, 23 | geometry: { 24 | type: "LineString" as const, 25 | coordinates, 26 | }, 27 | }; 28 | 29 | const options = { 30 | metric: "m" as "m" | "ft", 31 | zoom: 13, 32 | tileSize: 512, 33 | tileRequest: async (x: number, y: number, z: number) => { 34 | const buf = await sharp(`test/fixtures/${z}-${x}-${y}.webp`) 35 | .raw() 36 | .toBuffer({ resolveWithObject: true }); 37 | return { 38 | channels: buf.info.channels, 39 | image: new Uint8ClampedArray(buf.data), 40 | }; 41 | }, 42 | }; 43 | 44 | expect(await profileLineString(path, options)).toEqual( 45 | JSON.parse( 46 | await readFileAsync("test/fixtures/profileSimple13m.json", "utf-8"), 47 | ), 48 | ); 49 | 50 | options.metric = "ft" as const; 51 | 52 | expect(await profileLineString(path, options)).toEqual( 53 | JSON.parse( 54 | await readFileAsync("test/fixtures/profileSimple13ft.json", "utf-8"), 55 | ), 56 | ); 57 | }); 58 | 59 | it("simple line at zoom 14", async () => { 60 | const coordinates: GeoJSON.Position[] = [ 61 | [-111.88811277644503, 40.79618409829391], 62 | [-111.88645596614953, 40.797821596351326], 63 | [-111.88857300152719, 40.79938937578956], 64 | [-111.88811277644503, 40.80168871865277], 65 | [-111.88502926839493, 40.80350026602076], 66 | [-111.88553551598517, 40.80482405782945], 67 | ]; 68 | 69 | const path = { 70 | type: "Feature" as const, 71 | properties: {}, 72 | geometry: { 73 | type: "LineString" as const, 74 | coordinates, 75 | }, 76 | }; 77 | 78 | const options = { 79 | metric: "m" as "m" | "ft", 80 | zoom: 13, 81 | tileSize: 512, 82 | tileRequest: async (x: number, y: number, z: number) => { 83 | const buf = await sharp(`test/fixtures/${z}-${x}-${y}.webp`) 84 | .raw() 85 | .toBuffer({ resolveWithObject: true }); 86 | return { 87 | channels: buf.info.channels, 88 | image: new Uint8ClampedArray(buf.data), 89 | }; 90 | }, 91 | }; 92 | 93 | expect(await profileLineString(path, options)).toEqual( 94 | JSON.parse( 95 | await readFileAsync("test/fixtures/profileSimple14m.json", "utf-8"), 96 | ), 97 | ); 98 | 99 | options.metric = "ft" as const; 100 | 101 | expect(await profileLineString(path, options)).toEqual( 102 | JSON.parse( 103 | await readFileAsync("test/fixtures/profileSimple14ft.json", "utf-8"), 104 | ), 105 | ); 106 | }); 107 | }); 108 | -------------------------------------------------------------------------------- /test/fixtures/gdal.gpx.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "properties": { 7 | "name": "track name" 8 | }, 9 | "geometry": { 10 | "type": "MultiLineString", 11 | "coordinates": [ 12 | [ 13 | [ 14 | 15, 15 | 14, 16 | 16 17 | ], 18 | [ 19 | 18, 20 | 17, 21 | 19 22 | ] 23 | ], 24 | [ 25 | [ 26 | 21, 27 | 20, 28 | 22 29 | ], 30 | [ 31 | 24, 32 | 23, 33 | 25 34 | ] 35 | ] 36 | ] 37 | } 38 | }, 39 | { 40 | "type": "Feature", 41 | "properties": { 42 | "name": "route name", 43 | "time": "2007-11-25T17:58:00Z" 44 | }, 45 | "geometry": { 46 | "type": "LineString", 47 | "coordinates": [ 48 | [ 49 | 6, 50 | 5, 51 | 7 52 | ], 53 | [ 54 | 9, 55 | 8, 56 | 10 57 | ], 58 | [ 59 | 12, 60 | 11, 61 | 13 62 | ] 63 | ] 64 | } 65 | }, 66 | { 67 | "type": "Feature", 68 | "properties": { 69 | "name": "waypoint name", 70 | "cmt": "waypoint comment", 71 | "desc": "waypoint description", 72 | "time": "2007-11-25T17:58:00+01:00", 73 | "links": [ 74 | { 75 | "href": "href", 76 | "text": "text", 77 | "type": "type" 78 | }, 79 | { 80 | "href": "href2", 81 | "text": "text2", 82 | "type": "type2" 83 | }, 84 | { 85 | "href": "href3", 86 | "text": "text3", 87 | "type": "type3" 88 | } 89 | ], 90 | "type": "type" 91 | }, 92 | "geometry": { 93 | "type": "Point", 94 | "coordinates": [ 95 | 1, 96 | 0, 97 | 2 98 | ] 99 | } 100 | }, 101 | { 102 | "type": "Feature", 103 | "properties": {}, 104 | "geometry": { 105 | "type": "Point", 106 | "coordinates": [ 107 | 4, 108 | 3 109 | ] 110 | } 111 | } 112 | ] 113 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # MapTiler Client Changelog 2 | 3 | ## 2.6.0 4 | ### New Features 5 | - Bumps 'Streets' & 'Landscape' styles (and their variants) to new v4 styles. 6 | - Adds the new 'Base' style and its variants. 7 | - Namespaces V4 and V2 Styles and adds mechanism for switching to defaults. 8 | 9 | ### Bug Fixes 10 | None 11 | 12 | ### Others 13 | - Adds custom deprecation warnings. 14 | - Deprecates the older v2 styles and adds warnings regarding their usage. 15 | 16 | ## 2.5.1 17 | ### New Features 18 | None 19 | 20 | ### Bug Fixes 21 | None 22 | 23 | ### Others 24 | `Hybrid` map style is no longer deprecated. 25 | 26 | ## 2.5.0 27 | ### New Features 28 | - `at` and `batch` functions compute elevation on the server using MapTiler Elevation API by default 29 | - Elevation supports Node.js: computed on server when `bufferToPixelData` is not provided 30 | - Added `computeOn` option to force client/server elevation processing 31 | - Added `canParsePixelData` function to check if elevation can be computed on the client 32 | 33 | ### Bug Fixes 34 | - `bufferToPixelData` can be undefined 35 | 36 | ### Others 37 | None 38 | 39 | ## 2.4.0 40 | ### New Features 41 | - Added `elevation` option to Geolocation API 42 | 43 | ### Bug Fixes 44 | None 45 | 46 | ### Others 47 | None 48 | 49 | ## 2.3.2 50 | ### New Features 51 | None 52 | 53 | ### Bug Fixes 54 | None 55 | 56 | ### Others 57 | Added deprecation warning and field for styles that will be deprecated in the future. 58 | 59 | ## 2.3.1 60 | ### New Features 61 | None 62 | 63 | ### Bug Fixes 64 | - Fixed default export for new styles 65 | 66 | ## 2.3.0 67 | ### New Features 68 | - Additional new map styles as part of the MapStyle Object 69 | 70 | ### Bug Fixes 71 | None 72 | 73 | ### Others 74 | None 75 | 76 | ## 2.2.1 77 | ### Bug Fixes 78 | - Fixed incorrect `geocoding: false` for some more languages 79 | 80 | ## 2.2.0 81 | ### New Features 82 | - Exposing ISO languages and non-ISO language separately 83 | ### Others 84 | - fixing typos 85 | - languages are now ordered alphabetically 86 | 87 | ## 2.1.0 88 | ### New Features 89 | - Added `continental_marine` and `major_landform` to geocoding type 90 | ### Bug Fixes 91 | - Fixed Czech language geocoding flag 92 | ### Others 93 | - Languages are now listed in the Client library 94 | - Improved geocoding types and limit documentation 95 | 96 | ## 2.0.0 97 | ### New Features 98 | - Added `matching_text` and `matching_place_name` properties to geocoding feature response 99 | - Added `road` to geocoding `types` 100 | ### Others 101 | - Languages are now listed in the Client library 102 | 103 | ## 1.8.1 104 | ### Bug Fixes 105 | - The QuickLRU dependency is not CJS compatible to it is now fully bundled into the CJS bundle 106 | ### Others 107 | - Moved somes wrongly positioned deps into devDep 108 | 109 | ## 1.8.0 110 | ### New Features 111 | - Rework of the elevation API to be improve developper experience (new module `elevation`) 112 | - Expoing some geo math with the new `math` module 113 | - synchronized geocoding types with current geocoding API 114 | - added `excludeTypes` option to geocoding API 115 | 116 | ## 1.7.0 117 | ### New Features 118 | - DEM elevation API (https://github.com/maptiler/maptiler-client-js/pull/24) 119 | ### Bug Fixes 120 | - `geocoding.byId` can now be used with the apiKey (https://github.com/maptiler/maptiler-client-js/pull/27) 121 | - the Typescript types are now properly exported (https://github.com/maptiler/maptiler-client-js/pull/25) 122 | ### Others 123 | - the Typescript `moduleResolution` is now `"Bundler"` (used to be `"Node"`) (https://github.com/maptiler/maptiler-client-js/pull/28) 124 | - updated some dev-dependencies (https://github.com/maptiler/maptiler-client-js/pull/28) 125 | -------------------------------------------------------------------------------- /test/geometry/util.test.ts: -------------------------------------------------------------------------------- 1 | import { describe, it, expect, test } from "vitest"; 2 | import { 3 | earthRadius, 4 | xyzToTileID, 5 | mToFt, 6 | degToRad, 7 | getZoomLevelResolution, 8 | } from "../../src/geometry"; 9 | 10 | test("earthRadius", () => { 11 | expect(earthRadius).toEqual(6371008.8); 12 | }); 13 | 14 | describe("xyzToTileID", () => { 15 | it("managing tile x-y-z to ID", () => { 16 | expect(xyzToTileID(0, 0, 0)).toEqual(0); 17 | expect(xyzToTileID(0, 0, 1)).toEqual(1); 18 | expect(xyzToTileID(1, 0, 1)).toEqual(33); 19 | expect(xyzToTileID(1, 1, 1)).toEqual(97); 20 | expect(xyzToTileID(1048575, 1048575, 20)).toEqual(35184372088820); 21 | }); 22 | 23 | it("xyzToTileID for all zooms 1-7", () => { 24 | const idCache = new Set
8 | This demo is using the UMD bundle. Add ?key=YOUR_API_KEY to the URL.
9 |
11 | Open JS console. 12 |
13 | 14 | 15 | 16 | 17 | 113 | 114 | -------------------------------------------------------------------------------- /test/fixtures/style_url.kml.geojson: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "geometry": { 7 | "type": "Polygon", 8 | "coordinates": [ 9 | [ 10 | [ 11 | -122.0857412771483, 12 | 37.42227033155257, 13 | 17 14 | ], 15 | [ 16 | -122.0858169768481, 17 | 37.42231408832346, 18 | 17 19 | ], 20 | [ 21 | -122.085852582875, 22 | 37.42230337469744, 23 | 17 24 | ], 25 | [ 26 | -122.0858799945639, 27 | 37.42225686138789, 28 | 17 29 | ], 30 | [ 31 | -122.0858860101409, 32 | 37.4222311076138, 33 | 17 34 | ], 35 | [ 36 | -122.0858069157288, 37 | 37.42220250173855, 38 | 17 39 | ], 40 | [ 41 | -122.0858379542653, 42 | 37.42214027058678, 43 | 17 44 | ], 45 | [ 46 | -122.0856732640519, 47 | 37.42208690214408, 48 | 17 49 | ], 50 | [ 51 | -122.0856022926407, 52 | 37.42214885429042, 53 | 17 54 | ], 55 | [ 56 | -122.0855902778436, 57 | 37.422128290487, 58 | 17 59 | ], 60 | [ 61 | -122.0855841672237, 62 | 37.42208171967246, 63 | 17 64 | ], 65 | [ 66 | -122.0854852065741, 67 | 37.42210455874995, 68 | 17 69 | ], 70 | [ 71 | -122.0855067264352, 72 | 37.42214267949824, 73 | 17 74 | ], 75 | [ 76 | -122.0854430712915, 77 | 37.42212783846172, 78 | 17 79 | ], 80 | [ 81 | -122.0850990714904, 82 | 37.42251282407603, 83 | 17 84 | ], 85 | [ 86 | -122.0856769818632, 87 | 37.42281815323651, 88 | 17 89 | ], 90 | [ 91 | -122.0860162273783, 92 | 37.42244918858722, 93 | 17 94 | ], 95 | [ 96 | -122.0857260327004, 97 | 37.42229239604253, 98 | 17 99 | ], 100 | [ 101 | -122.0857412771483, 102 | 37.42227033155257, 103 | 17 104 | ] 105 | ] 106 | ] 107 | }, 108 | "properties": { 109 | "name": "Building 41", 110 | "styleUrl": "#transBluePoly", 111 | "styleHash": "-109facd6", 112 | "stroke": "#000000", 113 | "stroke-opacity": 1, 114 | "stroke-width": 1.5, 115 | "fill": "#0000ff", 116 | "fill-opacity": 0.49019607843137253 117 | } 118 | } 119 | ] 120 | } -------------------------------------------------------------------------------- /examples/linestring.geojson: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "type": "FeatureCollection", 4 | "features": [ 5 | { 6 | "type": "Feature", 7 | "geometry": { 8 | "type": "LineString", 9 | "coordinates": [ 10 | [ 11 | 6.249869, 12 | 46.402238, 13 | 424.3 14 | ], 15 | [ 16 | 6.249877, 17 | 46.40224, 18 | 424.4 19 | ], 20 | [ 21 | 6.249877, 22 | 46.402237, 23 | 424.4 24 | ], 25 | [ 26 | 6.249871, 27 | 46.402232, 28 | 424.5 29 | ], 30 | [ 31 | 6.249863, 32 | 46.402227, 33 | 424.6 34 | ], 35 | [ 36 | 6.249856, 37 | 46.402223, 38 | 424.7 39 | ], 40 | [ 41 | 6.249849, 42 | 46.402224, 43 | 424.8 44 | ], 45 | [ 46 | 6.249846, 47 | 46.402226, 48 | 424.8 49 | ], 50 | [ 51 | 6.249844, 52 | 46.402228, 53 | 424.8 54 | ], 55 | [ 56 | 6.249843, 57 | 46.402228, 58 | 424.8 59 | ], 60 | [ 61 | 6.249834, 62 | 46.402226, 63 | 424.9 64 | ], 65 | [ 66 | 6.249828, 67 | 46.402225, 68 | 425 69 | ], 70 | [ 71 | 6.249812, 72 | 46.402222, 73 | 425.2 74 | ], 75 | [ 76 | 6.249803, 77 | 46.402219, 78 | 425.3 79 | ], 80 | [ 81 | 6.249793, 82 | 46.402217, 83 | 425.4 84 | ], 85 | [ 86 | 6.249783, 87 | 46.402214, 88 | 425.5 89 | ], 90 | [ 91 | 6.249773, 92 | 46.402211, 93 | 425.6 94 | ], 95 | [ 96 | 6.249743, 97 | 46.402183, 98 | 426.1 99 | ], 100 | [ 101 | 6.249713, 102 | 46.402158, 103 | 426.5 104 | ], 105 | [ 106 | 6.24968, 107 | 46.402124, 108 | 427.1 109 | ], 110 | [ 111 | 6.249654, 112 | 46.40209, 113 | 427.6 114 | ], 115 | [ 116 | 6.249629, 117 | 46.402061, 118 | 428 119 | ], 120 | [ 121 | 6.249609, 122 | 46.402035, 123 | 428.4 124 | ], 125 | [ 126 | 6.249576, 127 | 46.402004, 128 | 428.8 129 | ], 130 | [ 131 | 6.249564, 132 | 46.401996, 133 | 428.9 134 | ], 135 | [ 136 | 6.249515, 137 | 46.401992, 138 | 429.5 139 | ], 140 | [ 141 | 6.249496, 142 | 46.401995, 143 | 429.5 144 | ], 145 | [ 146 | 6.249457, 147 | 46.402003, 148 | 429.6 149 | ], 150 | [ 151 | 6.249411, 152 | 46.402019, 153 | 429.6 154 | ] 155 | ] 156 | }, 157 | "id": "d22fc9f8-ba40-4f46-b46d-939564068e0a", 158 | "properties": { 159 | "name": "It's been a while", 160 | "type": "1" 161 | } 162 | } 163 | ] 164 | } -------------------------------------------------------------------------------- /test/fixtures/multitrack.kml: -------------------------------------------------------------------------------- 1 | 2 |