MCPcopy Create free account
hub / github.com/carbonplan/maps / validateMapInstance

Function validateMapInstance

src/map-provider.js:8–83  ·  view source on GitHub ↗
(map)

Source from the content-addressed store, hash-verified

6const MapContext = createContext(null)
7
8const validateMapInstance = (map) => {
9 if (!map) {
10 throw new Error(
11 '@carbonplan/maps: A map instance must be provided to MapProvider'
12 )
13 }
14 if (map.getProjection) {
15 const projection = map.getProjection()
16 // projection is undefined by default in maplibre-gl
17 if (projection) {
18 if (projection.name !== 'mercator' || projection.type !== 'mercator') {
19 throw new Error(
20 '@carbonplan/maps: Only the web-mercator projection is supported at this time'
21 )
22 }
23 }
24 }
25
26 const requiredMethods = [
27 'on',
28 'off',
29 'once',
30 'remove',
31 'loaded',
32 'getZoom',
33 'setZoom',
34 'setPitch',
35 'setBearing',
36 'getCenter',
37 'setCenter',
38 'getBounds',
39 'project',
40 'unproject',
41 'easeTo',
42 'getSource',
43 'addSource',
44 'getLayer',
45 'addLayer',
46 'removeLayer',
47 'setPaintProperty',
48 'triggerRepaint',
49 'getContainer',
50 'getCanvas',
51 'zoomIn',
52 'zoomOut',
53 ]
54
55 const missingMethods = requiredMethods.filter(
56 (method) => typeof map[method] !== 'function'
57 )
58
59 const touchMethods = [
60 { name: 'touchPitch', method: 'disable' },
61 { name: 'touchPitch', method: 'enable' },
62 { name: 'dragPan', method: 'disable' },
63 { name: 'dragPan', method: 'enable' },
64 { name: 'dragRotate', method: 'disable' },
65 { name: 'dragRotate', method: 'enable' },

Callers 1

map-provider.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected