From 449cd2a8fe0a0c68ff28fbb3323f45c9198c5211 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Wed, 25 Sep 2024 10:52:13 +0200 Subject: [PATCH 01/13] Allow maxBounds to only limit latitude Add OverscaledTileID export --- package.json | 380 +++++++++++------------ src/geo/lng_lat_bounds.ts | 2 + src/geo/projection/mercator_transform.ts | 5 +- src/geo/transform_helper.ts | 2 +- src/index.ts | 4 +- 5 files changed, 199 insertions(+), 194 deletions(-) diff --git a/package.json b/package.json index 0bc77623bc..3fa2cbe74b 100644 --- a/package.json +++ b/package.json @@ -1,192 +1,192 @@ { - "name": "maplibre-gl", - "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library", - "version": "5.0.0-pre.1", - "main": "dist/maplibre-gl.js", - "style": "dist/maplibre-gl.css", - "license": "BSD-3-Clause", - "homepage": "https://maplibre.org/", - "funding": "https://github.com/maplibre/maplibre-gl-js?sponsor=1", - "bugs": { - "url": "https://github.com/maplibre/maplibre-gl-js/issues/" - }, - "repository": { - "type": "git", - "url": "git://github.com/maplibre/maplibre-gl-js.git" - }, - "types": "dist/maplibre-gl.d.ts", - "type": "module", - "dependencies": { - "@mapbox/geojson-rewind": "^0.5.2", - "@mapbox/jsonlint-lines-primitives": "^2.0.2", - "@mapbox/point-geometry": "^0.1.0", - "@mapbox/tiny-sdf": "^2.0.6", - "@mapbox/unitbezier": "^0.0.1", - "@mapbox/vector-tile": "^1.3.1", - "@mapbox/whoots-js": "^3.1.0", - "@maplibre/maplibre-gl-style-spec": "^20.3.1", - "@types/geojson": "^7946.0.14", - "@types/geojson-vt": "3.2.5", - "@types/mapbox__point-geometry": "^0.1.4", - "@types/mapbox__vector-tile": "^1.3.4", - "@types/pbf": "^3.0.5", - "@types/supercluster": "^7.1.3", - "earcut": "^3.0.0", - "geojson-vt": "^4.0.2", - "gl-matrix": "^3.4.3", - "global-prefix": "^4.0.0", - "kdbush": "^4.0.2", - "murmurhash-js": "^1.0.0", - "pbf": "^3.3.0", - "potpack": "^2.0.0", - "quickselect": "^3.0.0", - "supercluster": "^8.0.1", - "tinyqueue": "^3.0.0", - "vt-pbf": "^3.1.3" - }, - "devDependencies": { - "@mapbox/mapbox-gl-rtl-text": "^0.3.0", - "@mapbox/mvt-fixtures": "^3.10.0", - "@rollup/plugin-commonjs": "^28.0.0", - "@rollup/plugin-json": "^6.1.0", - "@rollup/plugin-node-resolve": "^15.3.0", - "@rollup/plugin-replace": "^6.0.1", - "@rollup/plugin-strip": "^3.0.4", - "@rollup/plugin-terser": "^0.4.4", - "@rollup/plugin-typescript": "^12.1.0", - "@types/benchmark": "^2.1.5", - "@types/cssnano": "^5.0.0", - "@types/d3": "^7.4.3", - "@types/diff": "^5.2.2", - "@types/earcut": "^2.1.4", - "@types/eslint": "^8.56.7", - "@types/gl": "^6.0.5", - "@types/glob": "^8.1.0", - "@types/jest": "^29.5.13", - "@types/jsdom": "^21.1.7", - "@types/minimist": "^1.2.5", - "@types/murmurhash-js": "^1.0.6", - "@types/nise": "^1.4.5", - "@types/node": "^22.7.4", - "@types/offscreencanvas": "^2019.7.3", - "@types/pixelmatch": "^5.2.6", - "@types/pngjs": "^6.0.5", - "@types/react": "^18.3.10", - "@types/react-dom": "^18.3.0", - "@types/request": "^2.48.12", - "@types/shuffle-seed": "^1.1.3", - "@types/window-or-global": "^1.0.6", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/parser": "^7.18.0", - "address": "^2.0.3", - "autoprefixer": "^10.4.20", - "benchmark": "^2.1.4", - "canvas": "^2.11.2", - "cssnano": "^7.0.6", - "d3": "^7.9.0", - "d3-queue": "^3.0.7", - "devtools-protocol": "^0.0.1359167", - "diff": "^7.0.0", - "dts-bundle-generator": "^9.5.1", - "eslint": "^8.57.0", - "eslint-config-mourner": "^3.0.0", - "eslint-plugin-html": "^8.1.2", - "eslint-plugin-import": "^2.30.0", - "eslint-plugin-jest": "^28.8.3", - "eslint-plugin-react": "^7.37.0", - "eslint-plugin-tsdoc": "0.3.0", - "expect": "^29.7.0", - "glob": "^11.0.0", - "is-builtin-module": "^4.0.0", - "jest": "^29.7.0", - "jest-environment-jsdom": "^29.7.0", - "jest-junit": "^16.0.0", - "jest-monocart-coverage": "^1.1.1", - "jest-webgl-canvas-mock": "^2.5.3", - "jsdom": "^25.0.1", - "junit-report-builder": "^5.1.1", - "minimist": "^1.2.8", - "mock-geolocation": "^1.0.11", - "monocart-coverage-reports": "^2.11.0", - "nise": "^6.1.1", - "npm-font-open-sans": "^1.1.0", - "npm-run-all": "^4.1.5", - "pdf-merger-js": "^5.1.2", - "pixelmatch": "^6.0.0", - "pngjs": "^7.0.0", - "postcss": "^8.4.47", - "postcss-cli": "^11.0.0", - "postcss-inline-svg": "^6.0.0", - "pretty-bytes": "^6.1.1", - "puppeteer": "^23.4.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", - "rollup": "^4.23.0", - "rollup-plugin-sourcemaps2": "^0.4.1", - "rw": "^1.3.3", - "semver": "^7.6.3", - "shuffle-seed": "^1.1.6", - "source-map-explorer": "^2.5.3", - "st": "^3.0.0", - "stylelint": "^16.9.0", - "stylelint-config-standard": "^36.0.1", - "ts-jest": "^29.2.5", - "ts-node": "^10.9.2", - "tslib": "^2.7.0", - "typedoc": "^0.26.6", - "typedoc-plugin-markdown": "^4.2.8", - "typedoc-plugin-missing-exports": "^3.0.0", - "typescript": "^5.5.4" - }, - "scripts": { - "generate-dist-package": "node --no-warnings --loader ts-node/esm build/generate-dist-package.js", - "generate-shaders": "node --no-warnings --loader ts-node/esm build/generate-shaders.ts", - "generate-struct-arrays": "node --no-warnings --loader ts-node/esm build/generate-struct-arrays.ts", - "generate-style-code": "node --no-warnings --loader ts-node/esm build/generate-style-code.ts", - "generate-typings": "dts-bundle-generator --export-referenced-types --umd-module-name=maplibregl -o ./dist/maplibre-gl.d.ts ./src/index.ts", - "generate-docs": "typedoc && node --no-warnings --loader ts-node/esm build/generate-docs.ts", - "generate-images": "node --no-warnings --loader ts-node/esm build/generate-doc-images.ts", - "build-dist": "npm run build-css && npm run generate-typings && npm run build-dev && npm run build-csp-dev && npm run build-prod && npm run build-prod-unminified && npm run build-csp", - "build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev", - "watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch", - "build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true", - "build-prod-unminified": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production", - "build-csp": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:production,MINIFY:true", - "build-csp-dev": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:dev", - "build-css": "postcss -o dist/maplibre-gl.css src/css/maplibre-gl.css", - "watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css", - "build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts", - "watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch", - "start-server": "st --no-cache -H localhost --port 9966 .", - "start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material", - "start": "run-p watch-css watch-dev start-server", - "start-bench": "run-p watch-css watch-benchmarks start-server", - "lint": "eslint --cache --ext .ts,.tsx,.js,.html --ignore-path .gitignore .", - "lint-css": "stylelint **/*.css --fix -f verbose", - "test": "run-p lint lint-css test-render jest", - "jest": "jest", - "test-build": "jest --selectProjects=build --reporters=default", - "test-build-ci": "jest --selectProjects=build", - "test-integration": "jest --selectProjects=integration --reporters=default", - "test-integration-ci": "jest --coverage --selectProjects=integration", - "test-render": "node --no-warnings --loader ts-node/esm test/integration/render/run_render_tests.ts", - "test-unit": "jest --selectProjects=unit --reporters=default", - "test-unit-ci": "jest --coverage --selectProjects unit", - "test-watch-roots": "jest --watch", - "codegen": "run-p --print-label generate-dist-package generate-style-code generate-struct-arrays generate-shaders && npm run generate-typings", - "benchmark": "node --no-warnings --loader ts-node/esm test/bench/run-benchmarks.ts", - "gl-stats": "node --no-warnings --loader ts-node/esm test/bench/gl-stats.ts", - "prepare": "npm run codegen", - "typecheck": "tsc --noEmit && tsc --project tsconfig.dist.json", - "tsnode": "node --experimental-loader=ts-node/esm --no-warnings" - }, - "files": [ - "build/", - "dist/*", - "src/" - ], - "engines": { - "npm": ">=8.1.0", - "node": ">=16.14.0" - } + "name": "@windycom/leaflet-gl", + "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library", + "version": "5.0.0-pre.1", + "main": "dist/maplibre-gl.js", + "style": "dist/maplibre-gl.css", + "license": "BSD-3-Clause", + "homepage": "https://maplibre.org/", + "funding": "https://github.com/maplibre/maplibre-gl-js?sponsor=1", + "bugs": { + "url": "https://github.com/maplibre/maplibre-gl-js/issues/" + }, + "repository": { + "type": "git", + "url": "git://github.com/maplibre/maplibre-gl-js.git" + }, + "types": "dist/maplibre-gl.d.ts", + "type": "module", + "dependencies": { + "@mapbox/geojson-rewind": "^0.5.2", + "@mapbox/jsonlint-lines-primitives": "^2.0.2", + "@mapbox/point-geometry": "^0.1.0", + "@mapbox/tiny-sdf": "^2.0.6", + "@mapbox/unitbezier": "^0.0.1", + "@mapbox/vector-tile": "^1.3.1", + "@mapbox/whoots-js": "^3.1.0", + "@maplibre/maplibre-gl-style-spec": "^20.3.1", + "@types/geojson": "^7946.0.14", + "@types/geojson-vt": "3.2.5", + "@types/mapbox__point-geometry": "^0.1.4", + "@types/mapbox__vector-tile": "^1.3.4", + "@types/pbf": "^3.0.5", + "@types/supercluster": "^7.1.3", + "earcut": "^3.0.0", + "geojson-vt": "^4.0.2", + "gl-matrix": "^3.4.3", + "global-prefix": "^4.0.0", + "kdbush": "^4.0.2", + "murmurhash-js": "^1.0.0", + "pbf": "^3.3.0", + "potpack": "^2.0.0", + "quickselect": "^3.0.0", + "supercluster": "^8.0.1", + "tinyqueue": "^3.0.0", + "vt-pbf": "^3.1.3" + }, + "devDependencies": { + "@mapbox/mapbox-gl-rtl-text": "^0.3.0", + "@mapbox/mvt-fixtures": "^3.10.0", + "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-replace": "^6.0.1", + "@rollup/plugin-strip": "^3.0.4", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^12.1.0", + "@types/benchmark": "^2.1.5", + "@types/cssnano": "^5.0.0", + "@types/d3": "^7.4.3", + "@types/diff": "^5.2.2", + "@types/earcut": "^2.1.4", + "@types/eslint": "^8.56.7", + "@types/gl": "^6.0.5", + "@types/glob": "^8.1.0", + "@types/jest": "^29.5.13", + "@types/jsdom": "^21.1.7", + "@types/minimist": "^1.2.5", + "@types/murmurhash-js": "^1.0.6", + "@types/nise": "^1.4.5", + "@types/node": "^22.7.4", + "@types/offscreencanvas": "^2019.7.3", + "@types/pixelmatch": "^5.2.6", + "@types/pngjs": "^6.0.5", + "@types/react": "^18.3.10", + "@types/react-dom": "^18.3.0", + "@types/request": "^2.48.12", + "@types/shuffle-seed": "^1.1.3", + "@types/window-or-global": "^1.0.6", + "@typescript-eslint/eslint-plugin": "^7.18.0", + "@typescript-eslint/parser": "^7.18.0", + "address": "^2.0.3", + "autoprefixer": "^10.4.20", + "benchmark": "^2.1.4", + "canvas": "^2.11.2", + "cssnano": "^7.0.6", + "d3": "^7.9.0", + "d3-queue": "^3.0.7", + "devtools-protocol": "^0.0.1359167", + "diff": "^7.0.0", + "dts-bundle-generator": "^9.5.1", + "eslint": "^8.57.0", + "eslint-config-mourner": "^3.0.0", + "eslint-plugin-html": "^8.1.2", + "eslint-plugin-import": "^2.30.0", + "eslint-plugin-jest": "^28.8.3", + "eslint-plugin-react": "^7.37.0", + "eslint-plugin-tsdoc": "0.3.0", + "expect": "^29.7.0", + "glob": "^11.0.0", + "is-builtin-module": "^4.0.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "jest-junit": "^16.0.0", + "jest-monocart-coverage": "^1.1.1", + "jest-webgl-canvas-mock": "^2.5.3", + "jsdom": "^25.0.1", + "junit-report-builder": "^5.1.1", + "minimist": "^1.2.8", + "mock-geolocation": "^1.0.11", + "monocart-coverage-reports": "^2.11.0", + "nise": "^6.1.1", + "npm-font-open-sans": "^1.1.0", + "npm-run-all": "^4.1.5", + "pdf-merger-js": "^5.1.2", + "pixelmatch": "^6.0.0", + "pngjs": "^7.0.0", + "postcss": "^8.4.47", + "postcss-cli": "^11.0.0", + "postcss-inline-svg": "^6.0.0", + "pretty-bytes": "^6.1.1", + "puppeteer": "^23.4.1", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "rollup": "^4.23.0", + "rollup-plugin-sourcemaps2": "^0.4.1", + "rw": "^1.3.3", + "semver": "^7.6.3", + "shuffle-seed": "^1.1.6", + "source-map-explorer": "^2.5.3", + "st": "^3.0.0", + "stylelint": "^16.9.0", + "stylelint-config-standard": "^36.0.1", + "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", + "tslib": "^2.7.0", + "typedoc": "^0.26.6", + "typedoc-plugin-markdown": "^4.2.8", + "typedoc-plugin-missing-exports": "^3.0.0", + "typescript": "^5.5.4" + }, + "scripts": { + "generate-dist-package": "node --no-warnings --loader ts-node/esm build/generate-dist-package.js", + "generate-shaders": "node --no-warnings --loader ts-node/esm build/generate-shaders.ts", + "generate-struct-arrays": "node --no-warnings --loader ts-node/esm build/generate-struct-arrays.ts", + "generate-style-code": "node --no-warnings --loader ts-node/esm build/generate-style-code.ts", + "generate-typings": "dts-bundle-generator --export-referenced-types --umd-module-name=maplibregl -o ./dist/maplibre-gl.d.ts ./src/index.ts", + "generate-docs": "typedoc && node --no-warnings --loader ts-node/esm build/generate-docs.ts", + "generate-images": "node --no-warnings --loader ts-node/esm build/generate-doc-images.ts", + "build-dist": "npm run build-css && npm run generate-typings && npm run build-dev && npm run build-csp-dev && npm run build-prod && npm run build-prod-unminified && npm run build-csp", + "build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev", + "watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch", + "build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true", + "build-prod-unminified": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production", + "build-csp": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:production,MINIFY:true", + "build-csp-dev": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:dev", + "build-css": "postcss -o dist/maplibre-gl.css src/css/maplibre-gl.css", + "watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css", + "build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts", + "watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch", + "start-server": "st --no-cache -H localhost --port 9966 .", + "start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material", + "start": "run-p watch-css watch-dev start-server", + "start-bench": "run-p watch-css watch-benchmarks start-server", + "lint": "eslint --cache --ext .ts,.tsx,.js,.html --ignore-path .gitignore .", + "lint-css": "stylelint **/*.css --fix -f verbose", + "test": "run-p lint lint-css test-render jest", + "jest": "jest", + "test-build": "jest --selectProjects=build --reporters=default", + "test-build-ci": "jest --selectProjects=build", + "test-integration": "jest --selectProjects=integration --reporters=default", + "test-integration-ci": "jest --coverage --selectProjects=integration", + "test-render": "node --no-warnings --loader ts-node/esm test/integration/render/run_render_tests.ts", + "test-unit": "jest --selectProjects=unit --reporters=default", + "test-unit-ci": "jest --coverage --selectProjects unit", + "test-watch-roots": "jest --watch", + "codegen": "run-p --print-label generate-dist-package generate-style-code generate-struct-arrays generate-shaders && npm run generate-typings", + "benchmark": "node --no-warnings --loader ts-node/esm test/bench/run-benchmarks.ts", + "gl-stats": "node --no-warnings --loader ts-node/esm test/bench/gl-stats.ts", + "prepare": "npm run codegen", + "typecheck": "tsc --noEmit && tsc --project tsconfig.dist.json", + "tsnode": "node --experimental-loader=ts-node/esm --no-warnings" + }, + "files": [ + "build/", + "dist/*", + "src/" + ], + "engines": { + "npm": ">=8.1.0", + "node": ">=16.14.0" + } } diff --git a/src/geo/lng_lat_bounds.ts b/src/geo/lng_lat_bounds.ts index c3f1399384..0ecba74e55 100644 --- a/src/geo/lng_lat_bounds.ts +++ b/src/geo/lng_lat_bounds.ts @@ -23,6 +23,8 @@ export type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number * A `LngLatBounds` object represents a geographical bounding box, * defined by its southwest and northeast points in longitude and latitude. * + * If the longitude bounds difference is over 360°, no longitude bound is applied. + * * If no arguments are provided to the constructor, a `null` bounding box is created. * * Note that any Mapbox GL method that accepts a `LngLatBounds` object as an argument or option diff --git a/src/geo/projection/mercator_transform.ts b/src/geo/projection/mercator_transform.ts index 0347a4ecd6..1dcea17a5c 100644 --- a/src/geo/projection/mercator_transform.ts +++ b/src/geo/projection/mercator_transform.ts @@ -449,7 +449,8 @@ export class MercatorTransform implements ITransform { if (shouldZoomIn) scaleY = screenHeight / (maxY - minY); } - if (lngRange) { + const lngUnlimited = !this.lngRange || Math.abs(this.lngRange[0] - this.lngRange[1]) > 360; + if (lngRange && !lngUnlimited) { minX = wrap( mercatorXfromLng(lngRange[0]) * worldSize, 0, @@ -488,7 +489,7 @@ export class MercatorTransform implements ITransform { if (originalY + h2 > maxY) modifiedY = maxY - h2; } - if (lngRange) { + if (lngRange && !lngUnlimited) { const centerX = (minX + maxX) / 2; let wrappedX = originalX; if (this._helper._renderWorldCopies) { diff --git a/src/geo/transform_helper.ts b/src/geo/transform_helper.ts index 7a845ea456..d45ac78a42 100644 --- a/src/geo/transform_helper.ts +++ b/src/geo/transform_helper.ts @@ -420,7 +420,7 @@ export class TransformHelper implements ITransformGetters { setMaxBounds(bounds?: LngLatBounds | null): void { if (bounds) { this._lngRange = [bounds.getWest(), bounds.getEast()]; - this._latRange = [bounds.getSouth(), bounds.getNorth()]; + this._latRange = [Math.max(bounds.getSouth(), -MAX_VALID_LATITUDE), Math.min(bounds.getNorth(), MAX_VALID_LATITUDE)]; this._constrain(); } else { this._lngRange = null; diff --git a/src/index.ts b/src/index.ts index 7b046a663e..b325804b4c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import packageJSON from '../package.json' with {type: 'json'}; +import packageJSON from '../package.json' with { type: 'json' }; import {Map} from './ui/map'; import {NavigationControl} from './ui/control/navigation_control'; import {GeolocateControl} from './ui/control/geolocate_control'; @@ -27,6 +27,7 @@ import {RasterDEMTileSource} from './source/raster_dem_tile_source'; import {RasterTileSource} from './source/raster_tile_source'; import {VectorTileSource} from './source/vector_tile_source'; import {VideoSource} from './source/video_source'; +import {OverscaledTileID} from './source/tile_id'; import {Source, addSourceType} from './source/source'; import {addProtocol, removeProtocol} from './source/protocol_crud'; import {getGlobalDispatcher} from './util/dispatcher'; @@ -213,6 +214,7 @@ export { MapWheelEvent, MapTouchEvent, MapMouseEvent, + OverscaledTileID, type IControl, type CustomLayerInterface, type CanvasSourceSpecification, From d9f18130133a40c8b3930e531b2600149829afb6 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Wed, 31 Jul 2024 16:18:26 +0200 Subject: [PATCH 02/13] Add support for custom texture formats in raster-tile-source --- src/render/texture.ts | 49 ++++++++++++++++++++++++++------ src/source/raster_tile_source.ts | 43 ++++++++++++++++++---------- 2 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/render/texture.ts b/src/render/texture.ts index 99ce6a335f..c162cad406 100644 --- a/src/render/texture.ts +++ b/src/render/texture.ts @@ -1,8 +1,9 @@ import type {Context} from '../gl/context'; import type {RGBAImage, AlphaImage} from '../util/image'; -import {isImageBitmap} from '../util/util'; +import {extend, isImageBitmap} from '../util/util'; -export type TextureFormat = WebGLRenderingContextBase['RGBA'] | WebGLRenderingContextBase['ALPHA']; +export type TextureFormatWebGL2 = WebGL2RenderingContextBase['RG8'] | WebGL2RenderingContextBase['R8'] +export type TextureFormat = WebGLRenderingContextBase['RGBA'] |WebGLRenderingContextBase['RGB'] | WebGLRenderingContextBase['ALPHA'] | WebGLRenderingContextBase['LUMINANCE'] | TextureFormatWebGL2; export type TextureFilter = WebGLRenderingContextBase['LINEAR'] | WebGLRenderingContextBase['LINEAR_MIPMAP_NEAREST'] | WebGLRenderingContextBase['NEAREST']; export type TextureWrap = WebGLRenderingContextBase['REPEAT'] | WebGLRenderingContextBase['CLAMP_TO_EDGE'] | WebGLRenderingContextBase['MIRRORED_REPEAT']; @@ -35,12 +36,18 @@ export class Texture { this.context = context; this.format = format; this.texture = context.gl.createTexture(); - this.update(image, options); + + // Pass format to the update method to enforce its usage + this.update(image, extend(options, {format})); } + /** + * @summary Updates texture content, can also change texture format if necessary + */ update(image: TextureImage, options?: { premultiply?: boolean; useMipmap?: boolean; + format?:TextureFormat; } | null, position?: { x: number; y: number; @@ -51,27 +58,36 @@ export class Texture { const {gl} = context; this.useMipmap = Boolean(options && options.useMipmap); + + // Use default maplibre format gl.RGBA to remain compatible with all users of the Texture class + const newFormat = options && options.format ? options.format : gl.RGBA; + const formatChanged = this.format !== newFormat; + this.format = newFormat; + gl.bindTexture(gl.TEXTURE_2D, this.texture); context.pixelStoreUnpackFlipY.set(false); context.pixelStoreUnpack.set(1); context.pixelStoreUnpackPremultiplyAlpha.set(this.format === gl.RGBA && (!options || options.premultiply !== false)); - if (resize) { + // Since internal-format and format can be represented by different values (e.g. gl.RG8 vs gl.RG) in WebGL2, we need to preform conversion + const format = this.textureFormatFromInternalFormat(this.format); + + if (resize || formatChanged) { this.size = [width, height]; if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || isImageBitmap(image)) { - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, gl.UNSIGNED_BYTE, image); + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, format, gl.UNSIGNED_BYTE, image); } else { - gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, (image as DataTextureImage).data); + gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, format, gl.UNSIGNED_BYTE, (image as DataTextureImage).data); } } else { const {x, y} = position || {x: 0, y: 0}; if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData || isImageBitmap(image)) { - gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, image); + gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, format, gl.UNSIGNED_BYTE, image); } else { - gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, (image as DataTextureImage).data); + gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, format, gl.UNSIGNED_BYTE, (image as DataTextureImage).data); } } @@ -111,4 +127,21 @@ export class Texture { gl.deleteTexture(this.texture); this.texture = null; } + + /** + * @summary Method for accessing texture format by its internal format for cases, when these two are not the same + * - specifically for special WebGL2 formats + */ + textureFormatFromInternalFormat(internalFormat: TextureFormat) { + let format: GLenum = internalFormat; + switch (internalFormat) { + case WebGL2RenderingContext['RG8']: + format = WebGL2RenderingContext['RG']; + break; + case WebGL2RenderingContext['R8']: + format = WebGL2RenderingContext['RED']; + break; + } + return format; + } } diff --git a/src/source/raster_tile_source.ts b/src/source/raster_tile_source.ts index 7ad46cb0bd..74ced6193c 100644 --- a/src/source/raster_tile_source.ts +++ b/src/source/raster_tile_source.ts @@ -1,18 +1,18 @@ -import {extend, pick} from '../util/util'; +import { extend, pick } from '../util/util'; -import {ImageRequest} from '../util/image_request'; +import { ImageRequest } from '../util/image_request'; -import {ResourceType} from '../util/request_manager'; -import {Event, ErrorEvent, Evented} from '../util/evented'; -import {loadTileJson} from './load_tilejson'; -import {TileBounds} from './tile_bounds'; -import {Texture} from '../render/texture'; +import { ResourceType } from '../util/request_manager'; +import { Event, ErrorEvent, Evented } from '../util/evented'; +import { loadTileJson } from './load_tilejson'; +import { TileBounds } from './tile_bounds'; +import { Texture, TextureFormat } from '../render/texture'; -import type {Source} from './source'; -import type {OverscaledTileID} from './tile_id'; -import type {Map} from '../ui/map'; -import type {Dispatcher} from '../util/dispatcher'; -import type {Tile} from './tile'; +import type { Source } from './source'; +import type { OverscaledTileID } from './tile_id'; +import type { Map } from '../ui/map'; +import type { Dispatcher } from '../util/dispatcher'; +import type { Tile } from './tile'; import type { RasterSourceSpecification, RasterDEMSourceSpecification @@ -66,6 +66,7 @@ export class RasterTileSource extends Evented implements Source { _loaded: boolean; _options: RasterSourceSpecification | RasterDEMSourceSpecification; _tileJSONRequest: AbortController; + _textureFormat: TextureFormat; constructor(id: string, options: RasterSourceSpecification | RasterDEMSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) { super(); @@ -80,12 +81,22 @@ export class RasterTileSource extends Evented implements Source { this.scheme = 'xyz'; this.tileSize = 512; this._loaded = false; + this._textureFormat = WebGLRenderingContext.RGBA; this._options = extend({type: 'raster'}, options); extend(this, pick(options, ['url', 'scheme', 'tileSize'])); } - async load() { + + set textureFormat(format: TextureFormat) { + this._textureFormat = format; + } + + get textureFormat(): TextureFormat { + return this._textureFormat; + } + + async load() { this._loaded = false; this.fire(new Event('dataloading', {dataType: 'source'})); this._tileJSONRequest = new AbortController(); @@ -189,10 +200,12 @@ export class RasterTileSource extends Evented implements Source { const gl = context.gl; const img = response.data; tile.texture = this.map.painter.getTileTexture(img.width); + if (tile.texture) { - tile.texture.update(img, {useMipmap: true}); + // We need to update the format since tile textures are being reused by various sources + tile.texture.update(img, {useMipmap: true, format: this.textureFormat}); } else { - tile.texture = new Texture(context, img, gl.RGBA, {useMipmap: true}); + tile.texture = new Texture(context, img, this.textureFormat, {useMipmap: true}); tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST); } tile.state = 'loaded'; From 69948fe4a4c58b432b72878c6d0ab7a7b727ea20 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Wed, 4 Sep 2024 14:31:55 +0200 Subject: [PATCH 03/13] Fix setting of texture format --- src/render/texture.ts | 2 +- src/source/raster_tile_source.ts | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/render/texture.ts b/src/render/texture.ts index c162cad406..b19122921b 100644 --- a/src/render/texture.ts +++ b/src/render/texture.ts @@ -38,7 +38,7 @@ export class Texture { this.texture = context.gl.createTexture(); // Pass format to the update method to enforce its usage - this.update(image, extend(options, {format})); + this.update(image, options ? extend(options, {format}) : {format}); } /** diff --git a/src/source/raster_tile_source.ts b/src/source/raster_tile_source.ts index 74ced6193c..e29157e05a 100644 --- a/src/source/raster_tile_source.ts +++ b/src/source/raster_tile_source.ts @@ -1,18 +1,18 @@ -import { extend, pick } from '../util/util'; +import {extend, pick} from '../util/util'; -import { ImageRequest } from '../util/image_request'; +import {ImageRequest} from '../util/image_request'; -import { ResourceType } from '../util/request_manager'; -import { Event, ErrorEvent, Evented } from '../util/evented'; -import { loadTileJson } from './load_tilejson'; -import { TileBounds } from './tile_bounds'; -import { Texture, TextureFormat } from '../render/texture'; +import {ResourceType} from '../util/request_manager'; +import {Event, ErrorEvent, Evented} from '../util/evented'; +import {loadTileJson} from './load_tilejson'; +import {TileBounds} from './tile_bounds'; +import {Texture, TextureFormat} from '../render/texture'; -import type { Source } from './source'; -import type { OverscaledTileID } from './tile_id'; -import type { Map } from '../ui/map'; -import type { Dispatcher } from '../util/dispatcher'; -import type { Tile } from './tile'; +import type {Source} from './source'; +import type {OverscaledTileID} from './tile_id'; +import type {Map} from '../ui/map'; +import type {Dispatcher} from '../util/dispatcher'; +import type {Tile} from './tile'; import type { RasterSourceSpecification, RasterDEMSourceSpecification @@ -87,7 +87,6 @@ export class RasterTileSource extends Evented implements Source { extend(this, pick(options, ['url', 'scheme', 'tileSize'])); } - set textureFormat(format: TextureFormat) { this._textureFormat = format; } @@ -96,7 +95,7 @@ export class RasterTileSource extends Evented implements Source { return this._textureFormat; } - async load() { + async load() { this._loaded = false; this.fire(new Event('dataloading', {dataType: 'source'})); this._tileJSONRequest = new AbortController(); From 0d32a94aafa66b578935391d75632b4fded46feb Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Thu, 26 Sep 2024 18:15:45 +0200 Subject: [PATCH 04/13] Add exports for Event, Tile, and SourceCache --- src/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b325804b4c..73fcf3b703 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,7 +14,7 @@ import {LngLat, LngLatLike} from './geo/lng_lat'; import {LngLatBounds, LngLatBoundsLike} from './geo/lng_lat_bounds'; import Point from '@mapbox/point-geometry'; import {MercatorCoordinate} from './geo/mercator_coordinate'; -import {Evented} from './util/evented'; +import {Evented, Event} from './util/evented'; import {config} from './util/config'; import {rtlMainThreadPluginFactory} from './source/rtl_text_plugin_main_thread'; import {WorkerPool} from './util/worker_pool'; @@ -28,6 +28,7 @@ import {RasterTileSource} from './source/raster_tile_source'; import {VectorTileSource} from './source/vector_tile_source'; import {VideoSource} from './source/video_source'; import {OverscaledTileID} from './source/tile_id'; +import {Tile} from './source/tile'; import {Source, addSourceType} from './source/source'; import {addProtocol, removeProtocol} from './source/protocol_crud'; import {getGlobalDispatcher} from './util/dispatcher'; @@ -48,6 +49,7 @@ import {KeyboardHandler} from './ui/handler/keyboard'; import {TwoFingersTouchPitchHandler, TwoFingersTouchRotateHandler, TwoFingersTouchZoomHandler} from './ui/handler/two_fingers_touch'; import {MessageType} from './util/actor_messages'; import {createTileMesh} from './util/create_tile_mesh'; +import {SourceCache} from './source/source_cache'; const version = packageJSON.version; export type * from '@maplibre/maplibre-gl-style-spec'; @@ -189,6 +191,9 @@ export { LngLatBounds, Point, MercatorCoordinate, + SourceCache, + Event, + Tile, Evented, AJAXError, config, From 1b5d1e8f488c9fb5a50b7d55a2c74736fd03d958 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Tue, 1 Oct 2024 09:20:57 +0200 Subject: [PATCH 05/13] Rename package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3fa2cbe74b..9a731278e0 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@windycom/leaflet-gl", + "name": "@windycom/maplibre-gl", "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library", "version": "5.0.0-pre.1", "main": "dist/maplibre-gl.js", From 22fd8bc54898e967d63258e7ff51ae51bada511c Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Tue, 1 Oct 2024 09:45:27 +0200 Subject: [PATCH 06/13] Reset package.json formatting --- package.json | 382 +++++++++++++++++++++++++-------------------------- 1 file changed, 191 insertions(+), 191 deletions(-) diff --git a/package.json b/package.json index 9a731278e0..bae96eab11 100644 --- a/package.json +++ b/package.json @@ -1,192 +1,192 @@ { - "name": "@windycom/maplibre-gl", - "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library", - "version": "5.0.0-pre.1", - "main": "dist/maplibre-gl.js", - "style": "dist/maplibre-gl.css", - "license": "BSD-3-Clause", - "homepage": "https://maplibre.org/", - "funding": "https://github.com/maplibre/maplibre-gl-js?sponsor=1", - "bugs": { - "url": "https://github.com/maplibre/maplibre-gl-js/issues/" - }, - "repository": { - "type": "git", - "url": "git://github.com/maplibre/maplibre-gl-js.git" - }, - "types": "dist/maplibre-gl.d.ts", - "type": "module", - "dependencies": { - "@mapbox/geojson-rewind": "^0.5.2", - "@mapbox/jsonlint-lines-primitives": "^2.0.2", - "@mapbox/point-geometry": "^0.1.0", - "@mapbox/tiny-sdf": "^2.0.6", - "@mapbox/unitbezier": "^0.0.1", - "@mapbox/vector-tile": "^1.3.1", - "@mapbox/whoots-js": "^3.1.0", - "@maplibre/maplibre-gl-style-spec": "^20.3.1", - "@types/geojson": "^7946.0.14", - "@types/geojson-vt": "3.2.5", - "@types/mapbox__point-geometry": "^0.1.4", - "@types/mapbox__vector-tile": "^1.3.4", - "@types/pbf": "^3.0.5", - "@types/supercluster": "^7.1.3", - "earcut": "^3.0.0", - "geojson-vt": "^4.0.2", - "gl-matrix": "^3.4.3", - "global-prefix": "^4.0.0", - "kdbush": "^4.0.2", - "murmurhash-js": "^1.0.0", - "pbf": "^3.3.0", - "potpack": "^2.0.0", - "quickselect": "^3.0.0", - "supercluster": "^8.0.1", - "tinyqueue": "^3.0.0", - "vt-pbf": "^3.1.3" - }, - "devDependencies": { - "@mapbox/mapbox-gl-rtl-text": "^0.3.0", - "@mapbox/mvt-fixtures": "^3.10.0", - "@rollup/plugin-commonjs": "^28.0.0", - "@rollup/plugin-json": "^6.1.0", - "@rollup/plugin-node-resolve": "^15.3.0", - "@rollup/plugin-replace": "^6.0.1", - "@rollup/plugin-strip": "^3.0.4", - "@rollup/plugin-terser": "^0.4.4", - "@rollup/plugin-typescript": "^12.1.0", - "@types/benchmark": "^2.1.5", - "@types/cssnano": "^5.0.0", - "@types/d3": "^7.4.3", - "@types/diff": "^5.2.2", - "@types/earcut": "^2.1.4", - "@types/eslint": "^8.56.7", - "@types/gl": "^6.0.5", - "@types/glob": "^8.1.0", - "@types/jest": "^29.5.13", - "@types/jsdom": "^21.1.7", - "@types/minimist": "^1.2.5", - "@types/murmurhash-js": "^1.0.6", - "@types/nise": "^1.4.5", - "@types/node": "^22.7.4", - "@types/offscreencanvas": "^2019.7.3", - "@types/pixelmatch": "^5.2.6", - "@types/pngjs": "^6.0.5", - "@types/react": "^18.3.10", - "@types/react-dom": "^18.3.0", - "@types/request": "^2.48.12", - "@types/shuffle-seed": "^1.1.3", - "@types/window-or-global": "^1.0.6", - "@typescript-eslint/eslint-plugin": "^7.18.0", - "@typescript-eslint/parser": "^7.18.0", - "address": "^2.0.3", - "autoprefixer": "^10.4.20", - "benchmark": "^2.1.4", - "canvas": "^2.11.2", - "cssnano": "^7.0.6", - "d3": "^7.9.0", - "d3-queue": "^3.0.7", - "devtools-protocol": "^0.0.1359167", - "diff": "^7.0.0", - "dts-bundle-generator": "^9.5.1", - "eslint": "^8.57.0", - "eslint-config-mourner": "^3.0.0", - "eslint-plugin-html": "^8.1.2", - "eslint-plugin-import": "^2.30.0", - "eslint-plugin-jest": "^28.8.3", - "eslint-plugin-react": "^7.37.0", - "eslint-plugin-tsdoc": "0.3.0", - "expect": "^29.7.0", - "glob": "^11.0.0", - "is-builtin-module": "^4.0.0", - "jest": "^29.7.0", - "jest-environment-jsdom": "^29.7.0", - "jest-junit": "^16.0.0", - "jest-monocart-coverage": "^1.1.1", - "jest-webgl-canvas-mock": "^2.5.3", - "jsdom": "^25.0.1", - "junit-report-builder": "^5.1.1", - "minimist": "^1.2.8", - "mock-geolocation": "^1.0.11", - "monocart-coverage-reports": "^2.11.0", - "nise": "^6.1.1", - "npm-font-open-sans": "^1.1.0", - "npm-run-all": "^4.1.5", - "pdf-merger-js": "^5.1.2", - "pixelmatch": "^6.0.0", - "pngjs": "^7.0.0", - "postcss": "^8.4.47", - "postcss-cli": "^11.0.0", - "postcss-inline-svg": "^6.0.0", - "pretty-bytes": "^6.1.1", - "puppeteer": "^23.4.1", - "react": "^18.3.1", - "react-dom": "^18.3.1", - "rollup": "^4.23.0", - "rollup-plugin-sourcemaps2": "^0.4.1", - "rw": "^1.3.3", - "semver": "^7.6.3", - "shuffle-seed": "^1.1.6", - "source-map-explorer": "^2.5.3", - "st": "^3.0.0", - "stylelint": "^16.9.0", - "stylelint-config-standard": "^36.0.1", - "ts-jest": "^29.2.5", - "ts-node": "^10.9.2", - "tslib": "^2.7.0", - "typedoc": "^0.26.6", - "typedoc-plugin-markdown": "^4.2.8", - "typedoc-plugin-missing-exports": "^3.0.0", - "typescript": "^5.5.4" - }, - "scripts": { - "generate-dist-package": "node --no-warnings --loader ts-node/esm build/generate-dist-package.js", - "generate-shaders": "node --no-warnings --loader ts-node/esm build/generate-shaders.ts", - "generate-struct-arrays": "node --no-warnings --loader ts-node/esm build/generate-struct-arrays.ts", - "generate-style-code": "node --no-warnings --loader ts-node/esm build/generate-style-code.ts", - "generate-typings": "dts-bundle-generator --export-referenced-types --umd-module-name=maplibregl -o ./dist/maplibre-gl.d.ts ./src/index.ts", - "generate-docs": "typedoc && node --no-warnings --loader ts-node/esm build/generate-docs.ts", - "generate-images": "node --no-warnings --loader ts-node/esm build/generate-doc-images.ts", - "build-dist": "npm run build-css && npm run generate-typings && npm run build-dev && npm run build-csp-dev && npm run build-prod && npm run build-prod-unminified && npm run build-csp", - "build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev", - "watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch", - "build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true", - "build-prod-unminified": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production", - "build-csp": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:production,MINIFY:true", - "build-csp-dev": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:dev", - "build-css": "postcss -o dist/maplibre-gl.css src/css/maplibre-gl.css", - "watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css", - "build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts", - "watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch", - "start-server": "st --no-cache -H localhost --port 9966 .", - "start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material", - "start": "run-p watch-css watch-dev start-server", - "start-bench": "run-p watch-css watch-benchmarks start-server", - "lint": "eslint --cache --ext .ts,.tsx,.js,.html --ignore-path .gitignore .", - "lint-css": "stylelint **/*.css --fix -f verbose", - "test": "run-p lint lint-css test-render jest", - "jest": "jest", - "test-build": "jest --selectProjects=build --reporters=default", - "test-build-ci": "jest --selectProjects=build", - "test-integration": "jest --selectProjects=integration --reporters=default", - "test-integration-ci": "jest --coverage --selectProjects=integration", - "test-render": "node --no-warnings --loader ts-node/esm test/integration/render/run_render_tests.ts", - "test-unit": "jest --selectProjects=unit --reporters=default", - "test-unit-ci": "jest --coverage --selectProjects unit", - "test-watch-roots": "jest --watch", - "codegen": "run-p --print-label generate-dist-package generate-style-code generate-struct-arrays generate-shaders && npm run generate-typings", - "benchmark": "node --no-warnings --loader ts-node/esm test/bench/run-benchmarks.ts", - "gl-stats": "node --no-warnings --loader ts-node/esm test/bench/gl-stats.ts", - "prepare": "npm run codegen", - "typecheck": "tsc --noEmit && tsc --project tsconfig.dist.json", - "tsnode": "node --experimental-loader=ts-node/esm --no-warnings" - }, - "files": [ - "build/", - "dist/*", - "src/" - ], - "engines": { - "npm": ">=8.1.0", - "node": ">=16.14.0" - } -} + "name": "@windycom/maplibre-gl", + "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library", + "version": "5.0.0-pre.1", + "main": "dist/maplibre-gl.js", + "style": "dist/maplibre-gl.css", + "license": "BSD-3-Clause", + "homepage": "https://maplibre.org/", + "funding": "https://github.com/maplibre/maplibre-gl-js?sponsor=1", + "bugs": { + "url": "https://github.com/maplibre/maplibre-gl-js/issues/" + }, + "repository": { + "type": "git", + "url": "git://github.com/maplibre/maplibre-gl-js.git" + }, + "types": "dist/maplibre-gl.d.ts", + "type": "module", + "dependencies": { + "@mapbox/geojson-rewind": "^0.5.2", + "@mapbox/jsonlint-lines-primitives": "^2.0.2", + "@mapbox/point-geometry": "^0.1.0", + "@mapbox/tiny-sdf": "^2.0.6", + "@mapbox/unitbezier": "^0.0.1", + "@mapbox/vector-tile": "^1.3.1", + "@mapbox/whoots-js": "^3.1.0", + "@maplibre/maplibre-gl-style-spec": "^20.3.1", + "@types/geojson": "^7946.0.14", + "@types/geojson-vt": "3.2.5", + "@types/mapbox__point-geometry": "^0.1.4", + "@types/mapbox__vector-tile": "^1.3.4", + "@types/pbf": "^3.0.5", + "@types/supercluster": "^7.1.3", + "earcut": "^3.0.0", + "geojson-vt": "^4.0.2", + "gl-matrix": "^3.4.3", + "global-prefix": "^4.0.0", + "kdbush": "^4.0.2", + "murmurhash-js": "^1.0.0", + "pbf": "^3.3.0", + "potpack": "^2.0.0", + "quickselect": "^3.0.0", + "supercluster": "^8.0.1", + "tinyqueue": "^3.0.0", + "vt-pbf": "^3.1.3" + }, + "devDependencies": { + "@mapbox/mapbox-gl-rtl-text": "^0.3.0", + "@mapbox/mvt-fixtures": "^3.10.0", + "@rollup/plugin-commonjs": "^28.0.0", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.3.0", + "@rollup/plugin-replace": "^6.0.1", + "@rollup/plugin-strip": "^3.0.4", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^12.1.0", + "@types/benchmark": "^2.1.5", + "@types/cssnano": "^5.0.0", + "@types/d3": "^7.4.3", + "@types/diff": "^5.2.2", + "@types/earcut": "^2.1.4", + "@types/eslint": "^8.56.7", + "@types/gl": "^6.0.5", + "@types/glob": "^8.1.0", + "@types/jest": "^29.5.13", + "@types/jsdom": "^21.1.7", + "@types/minimist": "^1.2.5", + "@types/murmurhash-js": "^1.0.6", + "@types/nise": "^1.4.5", + "@types/node": "^22.7.4", + "@types/offscreencanvas": "^2019.7.3", + "@types/pixelmatch": "^5.2.6", + "@types/pngjs": "^6.0.5", + "@types/react": "^18.3.10", + "@types/react-dom": "^18.3.0", + "@types/request": "^2.48.12", + "@types/shuffle-seed": "^1.1.3", + "@types/window-or-global": "^1.0.6", + "@typescript-eslint/eslint-plugin": "^7.18.0", + "@typescript-eslint/parser": "^7.18.0", + "address": "^2.0.3", + "autoprefixer": "^10.4.20", + "benchmark": "^2.1.4", + "canvas": "^2.11.2", + "cssnano": "^7.0.6", + "d3": "^7.9.0", + "d3-queue": "^3.0.7", + "devtools-protocol": "^0.0.1359167", + "diff": "^7.0.0", + "dts-bundle-generator": "^9.5.1", + "eslint": "^8.57.0", + "eslint-config-mourner": "^3.0.0", + "eslint-plugin-html": "^8.1.2", + "eslint-plugin-import": "^2.30.0", + "eslint-plugin-jest": "^28.8.3", + "eslint-plugin-react": "^7.37.0", + "eslint-plugin-tsdoc": "0.3.0", + "expect": "^29.7.0", + "glob": "^11.0.0", + "is-builtin-module": "^4.0.0", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "jest-junit": "^16.0.0", + "jest-monocart-coverage": "^1.1.1", + "jest-webgl-canvas-mock": "^2.5.3", + "jsdom": "^25.0.1", + "junit-report-builder": "^5.1.1", + "minimist": "^1.2.8", + "mock-geolocation": "^1.0.11", + "monocart-coverage-reports": "^2.11.0", + "nise": "^6.1.1", + "npm-font-open-sans": "^1.1.0", + "npm-run-all": "^4.1.5", + "pdf-merger-js": "^5.1.2", + "pixelmatch": "^6.0.0", + "pngjs": "^7.0.0", + "postcss": "^8.4.47", + "postcss-cli": "^11.0.0", + "postcss-inline-svg": "^6.0.0", + "pretty-bytes": "^6.1.1", + "puppeteer": "^23.4.1", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "rollup": "^4.23.0", + "rollup-plugin-sourcemaps2": "^0.4.1", + "rw": "^1.3.3", + "semver": "^7.6.3", + "shuffle-seed": "^1.1.6", + "source-map-explorer": "^2.5.3", + "st": "^3.0.0", + "stylelint": "^16.9.0", + "stylelint-config-standard": "^36.0.1", + "ts-jest": "^29.2.5", + "ts-node": "^10.9.2", + "tslib": "^2.7.0", + "typedoc": "^0.26.6", + "typedoc-plugin-markdown": "^4.2.8", + "typedoc-plugin-missing-exports": "^3.0.0", + "typescript": "^5.5.4" + }, + "scripts": { + "generate-dist-package": "node --no-warnings --loader ts-node/esm build/generate-dist-package.js", + "generate-shaders": "node --no-warnings --loader ts-node/esm build/generate-shaders.ts", + "generate-struct-arrays": "node --no-warnings --loader ts-node/esm build/generate-struct-arrays.ts", + "generate-style-code": "node --no-warnings --loader ts-node/esm build/generate-style-code.ts", + "generate-typings": "dts-bundle-generator --export-referenced-types --umd-module-name=maplibregl -o ./dist/maplibre-gl.d.ts ./src/index.ts", + "generate-docs": "typedoc && node --no-warnings --loader ts-node/esm build/generate-docs.ts", + "generate-images": "node --no-warnings --loader ts-node/esm build/generate-doc-images.ts", + "build-dist": "npm run build-css && npm run generate-typings && npm run build-dev && npm run build-csp-dev && npm run build-prod && npm run build-prod-unminified && npm run build-csp", + "build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev", + "watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch", + "build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true", + "build-prod-unminified": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production", + "build-csp": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:production,MINIFY:true", + "build-csp-dev": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts --environment BUILD:dev", + "build-css": "postcss -o dist/maplibre-gl.css src/css/maplibre-gl.css", + "watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css", + "build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts", + "watch-benchmarks": "rollup --configPlugin @rollup/plugin-typescript -c test/bench/rollup_config_benchmarks.ts --watch", + "start-server": "st --no-cache -H localhost --port 9966 .", + "start-docs": "docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material", + "start": "run-p watch-css watch-dev start-server", + "start-bench": "run-p watch-css watch-benchmarks start-server", + "lint": "eslint --cache --ext .ts,.tsx,.js,.html --ignore-path .gitignore .", + "lint-css": "stylelint **/*.css --fix -f verbose", + "test": "run-p lint lint-css test-render jest", + "jest": "jest", + "test-build": "jest --selectProjects=build --reporters=default", + "test-build-ci": "jest --selectProjects=build", + "test-integration": "jest --selectProjects=integration --reporters=default", + "test-integration-ci": "jest --coverage --selectProjects=integration", + "test-render": "node --no-warnings --loader ts-node/esm test/integration/render/run_render_tests.ts", + "test-unit": "jest --selectProjects=unit --reporters=default", + "test-unit-ci": "jest --coverage --selectProjects unit", + "test-watch-roots": "jest --watch", + "codegen": "run-p --print-label generate-dist-package generate-style-code generate-struct-arrays generate-shaders && npm run generate-typings", + "benchmark": "node --no-warnings --loader ts-node/esm test/bench/run-benchmarks.ts", + "gl-stats": "node --no-warnings --loader ts-node/esm test/bench/gl-stats.ts", + "prepare": "npm run codegen", + "typecheck": "tsc --noEmit && tsc --project tsconfig.dist.json", + "tsnode": "node --experimental-loader=ts-node/esm --no-warnings" + }, + "files": [ + "build/", + "dist/*", + "src/" + ], + "engines": { + "npm": ">=8.1.0", + "node": ">=16.14.0" + } +} \ No newline at end of file From 946e5125b7f9a3c97ab0d125f58d7be0eb60d2b7 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Tue, 1 Oct 2024 09:56:30 +0200 Subject: [PATCH 07/13] Update readme --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0a9646174..a69a13dfc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## 4.7.1-beta.1 + +- Added custom features that were not part of the main branch + - viewport tile padding + - latitude bounds + - support for texture formats other than gl.RGBA used by raster tile sources + - exports for Event, Tile, SourceCache, and OverscaledTileID + +# === LeafletGL follows === + ## main ### ✨ Features and improvements From 81913d2ffd35f0998662b433bb2bc44cfc9f818d Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Tue, 1 Oct 2024 11:11:04 +0200 Subject: [PATCH 08/13] Remove anotation, add WebGL2 check --- src/render/texture.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/render/texture.ts b/src/render/texture.ts index b19122921b..2ae87e37b5 100644 --- a/src/render/texture.ts +++ b/src/render/texture.ts @@ -42,7 +42,7 @@ export class Texture { } /** - * @summary Updates texture content, can also change texture format if necessary + * Updates texture content, can also change texture format if necessary */ update(image: TextureImage, options?: { premultiply?: boolean; @@ -129,11 +129,16 @@ export class Texture { } /** - * @summary Method for accessing texture format by its internal format for cases, when these two are not the same + * Method for accessing texture format by its internal format for cases, when these two are not the same * - specifically for special WebGL2 formats */ textureFormatFromInternalFormat(internalFormat: TextureFormat) { let format: GLenum = internalFormat; + + if (!WebGL2RenderingContext) { + return format; + } + switch (internalFormat) { case WebGL2RenderingContext['RG8']: format = WebGL2RenderingContext['RG']; From 179092f0723e821952ae6755c4148a6f1e68ef28 Mon Sep 17 00:00:00 2001 From: Jakub Pelc Date: Tue, 1 Oct 2024 11:18:27 +0200 Subject: [PATCH 09/13] Fix lint # Conflicts: # src/geo/projection/globe_utils.ts --- src/util/web_worker_transfer.test.ts | 3 +-- src/util/web_worker_transfer.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/util/web_worker_transfer.test.ts b/src/util/web_worker_transfer.test.ts index 4969e0dc97..ce9d4db68e 100644 --- a/src/util/web_worker_transfer.test.ts +++ b/src/util/web_worker_transfer.test.ts @@ -1,6 +1,5 @@ -import {SerializedObject} from '../../dist/maplibre-gl'; import {AJAXError} from './ajax'; -import {register, serialize, deserialize} from './web_worker_transfer'; +import {register, serialize, deserialize, SerializedObject} from './web_worker_transfer'; describe('web worker transfer', () => { test('round trip', () => { diff --git a/src/util/web_worker_transfer.ts b/src/util/web_worker_transfer.ts index a8f1cd4325..3616156959 100644 --- a/src/util/web_worker_transfer.ts +++ b/src/util/web_worker_transfer.ts @@ -7,7 +7,7 @@ import {isImageBitmap} from './util'; /** * A class that is serialized to and json, that can be constructed back to the original class in the worker or in the main thread */ -type SerializedObject = { +export type SerializedObject = { [_: string]: S; }; From 31ee69a5bbbe959d1c389f396835815f18fa57f4 Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Tue, 1 Oct 2024 12:50:55 +0200 Subject: [PATCH 10/13] Remove line from changelog --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a69a13dfc5..6c03b18e23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,6 @@ ## 4.7.1-beta.1 - Added custom features that were not part of the main branch - - viewport tile padding - latitude bounds - support for texture formats other than gl.RGBA used by raster tile sources - exports for Event, Tile, SourceCache, and OverscaledTileID From 326589d4207316545f2e54055cd5a1e9013a5fbb Mon Sep 17 00:00:00 2001 From: Jakub Pelc Date: Tue, 1 Oct 2024 13:22:24 +0200 Subject: [PATCH 11/13] Update build size --- test/build/min.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/build/min.test.ts b/test/build/min.test.ts index 71272d2f14..bac948a859 100644 --- a/test/build/min.test.ts +++ b/test/build/min.test.ts @@ -36,7 +36,7 @@ describe('test min build', () => { const decreaseQuota = 4096; // feel free to update this value after you've checked that it has changed on purpose :-) - const expectedBytes = 877777; + const expectedBytes = 879038; expect(actualBytes).toBeLessThan(expectedBytes + increaseQuota); expect(actualBytes).toBeGreaterThan(expectedBytes - decreaseQuota); From 4d19edf335a0dfa4b1fe5350b772d66e96f875cf Mon Sep 17 00:00:00 2001 From: Jakub Pelc Date: Tue, 1 Oct 2024 15:06:41 +0200 Subject: [PATCH 12/13] Fix lnglat constrain bug --- src/geo/projection/mercator_transform.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/geo/projection/mercator_transform.ts b/src/geo/projection/mercator_transform.ts index 1dcea17a5c..83b945c397 100644 --- a/src/geo/projection/mercator_transform.ts +++ b/src/geo/projection/mercator_transform.ts @@ -449,7 +449,8 @@ export class MercatorTransform implements ITransform { if (shouldZoomIn) scaleY = screenHeight / (maxY - minY); } - const lngUnlimited = !this.lngRange || Math.abs(this.lngRange[0] - this.lngRange[1]) > 360; + const lngUnlimited = !lngRange || Math.abs(lngRange[0] - lngRange[1]) >= 1e6; + if (lngRange && !lngUnlimited) { minX = wrap( mercatorXfromLng(lngRange[0]) * worldSize, From 260ec5ef11d8c0b27235be437883236a1d2f361f Mon Sep 17 00:00:00 2001 From: Patrik Schiller Date: Thu, 3 Oct 2024 09:51:24 +0200 Subject: [PATCH 13/13] Simplify ternary operator --- src/render/texture.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/texture.ts b/src/render/texture.ts index 2ae87e37b5..f568fb5ca3 100644 --- a/src/render/texture.ts +++ b/src/render/texture.ts @@ -60,7 +60,7 @@ export class Texture { this.useMipmap = Boolean(options && options.useMipmap); // Use default maplibre format gl.RGBA to remain compatible with all users of the Texture class - const newFormat = options && options.format ? options.format : gl.RGBA; + const newFormat = options?.format ?? gl.RGBA; const formatChanged = this.format !== newFormat; this.format = newFormat;