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

BREAKING: Upgrade maplibre-gl to v2 #160

Merged
merged 8 commits into from Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/AmplifyGeofenceControl.test.ts
Expand Up @@ -72,7 +72,7 @@ describe("AmplifyGeofenceControl", () => {
const control = new AmplifyGeofenceControl({
geofenceCollectionId: "anyString",
});
control._map = new maplibreMap();
control._map = new maplibreMap({ container: '', style: '' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@slaymance is this the required arguments you were referring to during standup?

Copy link
Contributor Author

@slaymance slaymance Jun 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the MapOptions type in v2 has those properties marked as required and the options argument is required, while in v1 it accepted MapboxOptions and options was optional.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome yep this change should be fine as effectively there will be no change to the createMap function right?

control._ui = AmplifyGeofenceControlUI(
control,
{} as unknown as HTMLElement
Expand Down
2 changes: 1 addition & 1 deletion __tests__/drawGeofences.test.ts
Expand Up @@ -5,7 +5,7 @@ jest.mock("maplibre-gl");

describe("drawGeofences", () => {
test("drawPoints default options", () => {
const map = new maplibreMap();
const map = new maplibreMap({ container: '', style: '' });
const data: any = [
[
[
Expand Down
8 changes: 4 additions & 4 deletions __tests__/drawPoints.test.ts
Expand Up @@ -35,7 +35,7 @@ describe("drawPoints", () => {
});

test("drawPoints default options", () => {
const map = new maplibreMap();
const map = new maplibreMap({ container: '', style: '' });
drawPoints(
"foo",
[
Expand All @@ -54,7 +54,7 @@ describe("drawPoints", () => {
});

test("drawPoints autoFit false", () => {
const map = new maplibreMap();
const map = new maplibreMap({ container: '', style: '' });
drawPoints(
"foo",
[
Expand All @@ -78,7 +78,7 @@ describe("drawPoints", () => {
const icon1 = "foobar";
const icon2 = "barbaz";

const map = new maplibreMap();
const map = new maplibreMap({ container: '', style: '' });
drawPoints(
"foo",
[
Expand Down Expand Up @@ -107,7 +107,7 @@ describe("drawPoints", () => {
test("drawPoints custom markers, if active marker not passed used same as regular", () => {
const icon = "foobar";

const map = new maplibreMap();
const map = new maplibreMap({ container: '', style: '' });
drawPoints(
"foo",
[
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -79,7 +79,7 @@
"husky": "^7.0.4",
"jest": "^27.0.3",
"jest-transform-stub": "^2.0.0",
"maplibre-gl": "^1.14.0",
"maplibre-gl": "^2.1.9",
"prettier": "^2.3.0",
"rollup": "^2.55.1",
"rollup-plugin-import-css": "^3.0.2",
Expand All @@ -92,7 +92,7 @@
"peerDependencies": {
"@aws-amplify/core": "^4.5.1",
"@aws-amplify/geo": "^1.3.0",
"maplibre-gl": "^1.15.2"
"maplibre-gl": "^2.1.9"
},
"dependencies": {
"@mapbox/mapbox-gl-draw": "^1.3.0",
Expand Down
4 changes: 2 additions & 2 deletions src/AmplifyMapLibreRequest.ts
Expand Up @@ -10,11 +10,11 @@ import { Geo, AmazonLocationServiceMapStyle } from "@aws-amplify/geo";
import {
Map as MaplibreMap,
RequestParameters,
MapboxOptions,
MapOptions,
} from "maplibre-gl";
import { urlEncodePeriods } from "./utils";

interface CreateMapOptions extends MapboxOptions {
interface CreateMapOptions extends MapOptions {
region?: string;
mapConstructor?: typeof MaplibreMap;
}
Expand Down
16 changes: 8 additions & 8 deletions src/drawClusterLayer.ts
@@ -1,16 +1,16 @@
import { Geo } from "@aws-amplify/geo";
import { Point } from "geojson";
import {
CircleLayer,
CirclePaint,
import type {
CircleLayerSpecification,
LngLatLike,
Map as maplibreMap,
SymbolLayer,
SymbolLayerSpecification,
} from "maplibre-gl";
import { ClusterOptions } from "./types";

import { COLOR_WHITE, MARKER_COLOR } from "./constants";
import { isGeoJsonSource } from "./utils";
import { FONT_DEFAULT_BY_STYLE } from "./constants";
import type { ClusterOptions } from "./types";

export function drawClusterLayer(
sourceName: string,
Expand Down Expand Up @@ -38,7 +38,7 @@ export function drawClusterLayer(
const clusterSymbolLayerId = `${sourceName}-layer-cluster-count`;

// Use step expressions for clusters (https://docs.mapbox.com/mapbox-gl-js/style-spec/#expressions-step)
const paintOptions: CirclePaint = {
const paintOptions: CircleLayerSpecification["paint"] = {
"circle-color": [
"step",
["get", "point_count"],
Expand All @@ -65,7 +65,7 @@ export function drawClusterLayer(
"circle-stroke-color": borderColor,
...clusterPaint,
};
const defaultClusterLayer: CircleLayer = {
const defaultClusterLayer: CircleLayerSpecification = {
id: clusterLayerId,
type: "circle",
source: sourceName,
Expand Down Expand Up @@ -120,7 +120,7 @@ export function drawClusterLayer(
const paintOptions = {
"text-color": fontColor,
};
const defaultClusterCount: SymbolLayer = {
const defaultClusterCount: SymbolLayerSpecification = {
id: clusterSymbolLayerId,
type: "symbol",
source: sourceName,
Expand Down
8 changes: 5 additions & 3 deletions src/drawUnclusteredLayer.ts
@@ -1,10 +1,12 @@
import { Point } from "geojson";
import { Map as maplibreMap, Popup, SymbolLayer } from "maplibre-gl";
import { Coordinates, UnclusteredOptions } from "./types";
import { Popup } from 'maplibre-gl';
import type { Map as maplibreMap, SymbolLayerSpecification } from "maplibre-gl";

import { ACTIVE_MARKER_COLOR, COLOR_WHITE, MARKER_COLOR } from "./constants";
import { createMarker } from "./createMarker";
import { getPopupRenderFunction } from "./popupRender";
import { isCoordinates } from "./utils";
import type { Coordinates, UnclusteredOptions } from "./types";

const HIDE_TIP = "amplify-tip";

Expand Down Expand Up @@ -33,7 +35,7 @@ export function drawUnclusteredLayer(

addUnclusteredMarkerImages(map, options);

const defaultUnclusteredPoint: SymbolLayer = {
const defaultUnclusteredPoint: SymbolLayerSpecification = {
id: unclusteredLayerId,
type: "symbol",
source: sourceName,
Expand Down
7 changes: 4 additions & 3 deletions src/utils.ts
@@ -1,6 +1,7 @@
import { Feature } from "geojson";
import { AnySourceImpl, GeoJSONSource } from "maplibre-gl";
import { Coordinates, NamedLocation, Geofence, Polygon } from "./types";
import type { GeoJSONSource, Source } from "maplibre-gl";

import type { Coordinates, NamedLocation, Geofence, Polygon } from "./types";

export function isCoordinates(array: unknown): array is Coordinates {
return (
Expand Down Expand Up @@ -48,7 +49,7 @@ export function isPolygonArray(array: unknown): array is Polygon[] {
}

export function isGeoJsonSource(
source: AnySourceImpl
source: Source
): source is GeoJSONSource {
return source.type === "geojson";
}
Expand Down
73 changes: 7 additions & 66 deletions yarn.lock
Expand Up @@ -2586,19 +2586,14 @@
resolved "https://registry.yarnpkg.com/@mapbox/geojson-normalize/-/geojson-normalize-0.0.1.tgz#1da1e6b3a7add3ad29909b30f438f60581b7cd80"
integrity sha1-HaHms6et060pkJsw9Dj2BYG3zYA=

"@mapbox/geojson-rewind@^0.5.0", "@mapbox/geojson-rewind@^0.5.1":
"@mapbox/geojson-rewind@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@mapbox/geojson-rewind/-/geojson-rewind-0.5.1.tgz#adbe16dc683eb40e90934c51a5e28c7bbf44f4e1"
integrity sha512-eL7fMmfTBKjrb+VFHXCGv9Ot0zc3C0U+CwXo1IrP+EPwDczLoXv34Tgq3y+2mPSFNVUXgU42ILWJTC7145KPTA==
dependencies:
get-stream "^6.0.1"
minimist "^1.2.5"

"@mapbox/geojson-types@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@mapbox/geojson-types/-/geojson-types-1.0.2.tgz#9aecf642cb00eab1080a57c4f949a65b4a5846d6"
integrity sha512-e9EBqHHv3EORHrSfbR9DqecPNn+AmuAoQxV6aL8Xu30bJMJR1o8PZLZzpk1Wq7/NfCbuhmakHTPYRhoqLsXRnw==

"@mapbox/geojsonhint@^2.0.0":
version "2.2.0"
resolved "https://registry.yarnpkg.com/@mapbox/geojsonhint/-/geojsonhint-2.2.0.tgz#75ca94706e9a56e6debf4e1c78fabdc67978b883"
Expand Down Expand Up @@ -2642,11 +2637,6 @@
lodash.isequal "^4.5.0"
xtend "^4.0.2"

"@mapbox/mapbox-gl-supported@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-1.5.0.tgz#f60b6a55a5d8e5ee908347d2ce4250b15103dc8e"
integrity sha512-/PT1P6DNf7vjEEiPkVIRJkvibbqWtqnyGaBz3nfRdcxclNSnSdaLU5tfAgcD7I8Yt5i+L19s406YLl1koLnLbg==

"@mapbox/mapbox-gl-supported@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@mapbox/mapbox-gl-supported/-/mapbox-gl-supported-2.0.1.tgz#c15367178d8bfe4765e6b47b542fe821ce259c7b"
Expand All @@ -2657,21 +2647,11 @@
resolved "https://registry.yarnpkg.com/@mapbox/point-geometry/-/point-geometry-0.1.0.tgz#8a83f9335c7860effa2eeeca254332aa0aeed8f2"
integrity sha1-ioP5M1x4YO/6Lu7KJUMyqgru2PI=

"@mapbox/tiny-sdf@^1.1.1":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@mapbox/tiny-sdf/-/tiny-sdf-1.2.5.tgz#424c620a96442b20402552be70a7f62a8407cc59"
integrity sha512-cD8A/zJlm6fdJOk6DqPUV8mcpyJkRz2x2R+/fYcWDYG3oWbG7/L7Yl/WqQ1VZCjnL9OTIMAn6c+BC5Eru4sQEw==

"@mapbox/tiny-sdf@^2.0.4":
version "2.0.5"
resolved "https://registry.yarnpkg.com/@mapbox/tiny-sdf/-/tiny-sdf-2.0.5.tgz#cdba698d3d65087643130f9af43a2b622ce0b372"
integrity sha512-OhXt2lS//WpLdkqrzo/KwB7SRD8AiNTFFzuo9n14IBupzIMa67yGItcK7I2W9D8Ghpa4T04Sw9FWsKCJG50Bxw==

"@mapbox/unitbezier@^0.0.0":
version "0.0.0"
resolved "https://registry.yarnpkg.com/@mapbox/unitbezier/-/unitbezier-0.0.0.tgz#15651bd553a67b8581fb398810c98ad86a34524e"
integrity sha1-FWUb1VOme4WB+zmIEMmK2Go0Uk4=

"@mapbox/unitbezier@^0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@mapbox/unitbezier/-/unitbezier-0.0.1.tgz#d32deb66c7177e9e9dfc3bbd697083e2e657ff01"
Expand Down Expand Up @@ -4564,7 +4544,7 @@ duplexer2@~0.1.0:
dependencies:
readable-stream "^2.0.2"

earcut@^2.2.2, earcut@^2.2.3:
earcut@^2.2.3:
version "2.2.3"
resolved "https://registry.yarnpkg.com/earcut/-/earcut-2.2.3.tgz#d44ced2ff5a18859568e327dd9c7d46b16f55cf4"
integrity sha512-iRDI1QeCQIhMCZk48DRDMVgQSSBDmbzzNhnxIo+pwx3swkfjMh6vh0nWLq1NdvGHLKH6wIrAM3vQWeTj6qeoug==
Expand Down Expand Up @@ -5262,7 +5242,7 @@ git-raw-commits@^2.0.0:
split2 "^3.0.0"
through2 "^4.0.0"

gl-matrix@^3.2.1, gl-matrix@^3.4.3:
gl-matrix@^3.4.3:
version "3.4.3"
resolved "https://registry.yarnpkg.com/gl-matrix/-/gl-matrix-3.4.3.tgz#fc1191e8320009fd4d20e9339595c6041ddc22c9"
integrity sha512-wcCp8vu8FT22BnvKVPjXa/ICBWRq/zjFfdofZy1WSpQZpphblv12/bOQLBC1rMM7SGOFS9ltVmKOHil5+Ml7gA==
Expand Down Expand Up @@ -5334,11 +5314,6 @@ graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0, graceful-fs@^4.2.10,
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"
integrity sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==

grid-index@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/grid-index/-/grid-index-1.1.0.tgz#97f8221edec1026c8377b86446a7c71e79522ea7"
integrity sha512-HZRwumpOGUrHyxO5bqKZL0B0GlUpwtCAzZ42sgxUPniu33R1LSFH5yrIcBCHjkctCAh3mtWKcKd9J4vDDdeVHA==

handlebars@^4.7.7:
version "4.7.7"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.7.tgz#9ce33416aad02dbd6c8fafa8240d5d98004945a1"
Expand Down Expand Up @@ -6766,7 +6741,7 @@ maplibre-gl-draw-circle@^0.0.1:
"@turf/helpers" "^6.1.4"
"@turf/length" "^6.0.2"

maplibre-gl@*:
maplibre-gl@*, maplibre-gl@^2.1.9:
version "2.1.9"
resolved "https://registry.yarnpkg.com/maplibre-gl/-/maplibre-gl-2.1.9.tgz#042f3ef4224fa890ecf7a410145243f1fc943dcd"
integrity sha512-pnWJmILeZpgA5QSI7K7xFK3yrkyYTd9srw3fCi2Ca52Phm78hsznPwUErEQcZLfxXKn/1h9t8IPdj0TH0NBNbg==
Expand Down Expand Up @@ -6795,35 +6770,6 @@ maplibre-gl@*:
tinyqueue "^2.0.3"
vt-pbf "^3.1.3"

maplibre-gl@^1.14.0:
version "1.15.3"
resolved "https://registry.yarnpkg.com/maplibre-gl/-/maplibre-gl-1.15.3.tgz#eebbdd6b4cba46c61a660d6fa1808fced126e24d"
integrity sha512-ZuOhLCNgp7Yl1L9uyKgZeuo7kKdewP0iWtmEXsZ/snp0JiVkR1Kl+m1rsfKT/wpm/O4zZ7mUGxF16cYbMIFDRA==
dependencies:
"@mapbox/geojson-rewind" "^0.5.0"
"@mapbox/geojson-types" "^1.0.2"
"@mapbox/jsonlint-lines-primitives" "^2.0.2"
"@mapbox/mapbox-gl-supported" "^1.5.0"
"@mapbox/point-geometry" "^0.1.0"
"@mapbox/tiny-sdf" "^1.1.1"
"@mapbox/unitbezier" "^0.0.0"
"@mapbox/vector-tile" "^1.3.1"
"@mapbox/whoots-js" "^3.1.0"
csscolorparser "~1.0.3"
earcut "^2.2.2"
geojson-vt "^3.2.1"
gl-matrix "^3.2.1"
grid-index "^1.1.0"
minimist "^1.2.6"
murmurhash-js "^1.0.0"
pbf "^3.2.1"
potpack "^1.0.1"
quickselect "^2.0.0"
rw "^1.3.3"
supercluster "^7.1.0"
tinyqueue "^2.0.3"
vt-pbf "^3.1.1"

marked-terminal@^5.0.0:
version "5.1.1"
resolved "https://registry.yarnpkg.com/marked-terminal/-/marked-terminal-5.1.1.tgz#d2edc2991841d893ee943b44b40b2ee9518b4d9f"
Expand Down Expand Up @@ -7641,7 +7587,7 @@ pkg-dir@^4.2.0:
dependencies:
find-up "^4.0.0"

potpack@^1.0.1, potpack@^1.0.2:
potpack@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/potpack/-/potpack-1.0.2.tgz#23b99e64eb74f5741ffe7656b5b5c4ddce8dfc14"
integrity sha512-choctRBIV9EMT9WGAZHn3V7t0Z2pMQyl0EZE6pFc/6ml3ssw7Dlf/oAOvFwjm1HVsqfQN8GfeFyJ+d8tRzqueQ==
Expand Down Expand Up @@ -8095,11 +8041,6 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

rw@^1.3.3:
version "1.3.3"
resolved "https://registry.yarnpkg.com/rw/-/rw-1.3.3.tgz#3f862dfa91ab766b14885ef4d01124bfda074fb4"
integrity sha1-P4Yt+pGrdmsUiF700BEkv9oHT7Q=

rw@~0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/rw/-/rw-0.1.4.tgz#4903cbd80248ae0ede685bf58fd236a7a9b29a3e"
Expand Down Expand Up @@ -8501,7 +8442,7 @@ suggestions-list@^0.0.2:
fuzzy "^0.1.1"
xtend "^4.0.0"

supercluster@^7.1.0, supercluster@^7.1.4:
supercluster@^7.1.4:
version "7.1.5"
resolved "https://registry.yarnpkg.com/supercluster/-/supercluster-7.1.5.tgz#65a6ce4a037a972767740614c19051b64b8be5a3"
integrity sha512-EulshI3pGUM66o6ZdH3ReiFcvHpM3vAigyK+vcxdjpJyEbIIrtbmBdY23mGgnI24uXiGFvrGq9Gkum/8U7vJWg==
Expand Down Expand Up @@ -9052,7 +8993,7 @@ vfile@^4.0.0:
unist-util-stringify-position "^2.0.0"
vfile-message "^2.0.0"

vt-pbf@^3.1.1, vt-pbf@^3.1.3:
vt-pbf@^3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/vt-pbf/-/vt-pbf-3.1.3.tgz#68fd150756465e2edae1cc5c048e063916dcfaac"
integrity sha512-2LzDFzt0mZKZ9IpVF2r69G9bXaP2Q2sArJCmcCgvfTdCCZzSyz4aCLoQyUilu37Ll56tCblIZrXFIjNUpGIlmA==
Expand Down