react-native-maplibre-lite 0.1.1 → 0.1.2

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.
Files changed (70) hide show
  1. package/lib/module/components/MapPlaceholder.js +2 -3
  2. package/lib/module/components/MapPlaceholder.js.map +1 -1
  3. package/lib/module/components/MapView.js +117 -41
  4. package/lib/module/components/MapView.js.map +1 -1
  5. package/lib/module/components/Marker.js +2 -2
  6. package/lib/module/components/Marker.js.map +1 -1
  7. package/lib/module/components/Polygon.js +2 -2
  8. package/lib/module/components/Polygon.js.map +1 -1
  9. package/lib/module/components/Polyline.js +2 -2
  10. package/lib/module/components/Polyline.js.map +1 -1
  11. package/lib/module/components/utils.js +29 -0
  12. package/lib/module/components/utils.js.map +1 -0
  13. package/lib/module/{webContent.js → components/webContent.js} +18 -32
  14. package/lib/module/components/webContent.js.map +1 -0
  15. package/lib/module/components/webFunctions/addMarkerWeb.js +36 -10
  16. package/lib/module/components/webFunctions/addMarkerWeb.js.map +1 -1
  17. package/lib/module/components/webFunctions/addPolylineWeb.js +2 -2
  18. package/lib/module/components/webFunctions/fitBoundsWeb.js +6 -2
  19. package/lib/module/components/webFunctions/fitBoundsWeb.js.map +1 -1
  20. package/lib/module/components/webFunctions/flyToWeb.js +14 -0
  21. package/lib/module/components/webFunctions/flyToWeb.js.map +1 -0
  22. package/lib/module/components/webFunctions/initWeb.js +21 -19
  23. package/lib/module/components/webFunctions/initWeb.js.map +1 -1
  24. package/lib/module/components/webFunctions/updateWeb.js +78 -0
  25. package/lib/module/components/webFunctions/updateWeb.js.map +1 -0
  26. package/lib/typescript/src/components/MapPlaceholder.d.ts.map +1 -1
  27. package/lib/typescript/src/components/MapView.d.ts +8 -1
  28. package/lib/typescript/src/components/MapView.d.ts.map +1 -1
  29. package/lib/typescript/src/components/Marker.d.ts +1 -1
  30. package/lib/typescript/src/components/Marker.d.ts.map +1 -1
  31. package/lib/typescript/src/components/Polygon.d.ts +1 -1
  32. package/lib/typescript/src/components/Polygon.d.ts.map +1 -1
  33. package/lib/typescript/src/components/types.d.ts +4 -0
  34. package/lib/typescript/src/components/types.d.ts.map +1 -1
  35. package/lib/typescript/src/components/utils.d.ts +2 -0
  36. package/lib/typescript/src/components/utils.d.ts.map +1 -0
  37. package/lib/typescript/src/components/webContent.d.ts +3 -0
  38. package/lib/typescript/src/components/webContent.d.ts.map +1 -0
  39. package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts +1 -1
  40. package/lib/typescript/src/components/webFunctions/addMarkerWeb.d.ts.map +1 -1
  41. package/lib/typescript/src/components/webFunctions/addPolylineWeb.d.ts +1 -1
  42. package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts +1 -1
  43. package/lib/typescript/src/components/webFunctions/fitBoundsWeb.d.ts.map +1 -1
  44. package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts +2 -0
  45. package/lib/typescript/src/components/webFunctions/flyToWeb.d.ts.map +1 -0
  46. package/lib/typescript/src/components/webFunctions/initWeb.d.ts +1 -1
  47. package/lib/typescript/src/components/webFunctions/initWeb.d.ts.map +1 -1
  48. package/lib/typescript/src/components/webFunctions/updateWeb.d.ts +3 -0
  49. package/lib/typescript/src/components/webFunctions/updateWeb.d.ts.map +1 -0
  50. package/lib/typescript/src/index.d.ts +1 -1
  51. package/lib/typescript/src/index.d.ts.map +1 -1
  52. package/package.json +1 -1
  53. package/src/components/MapPlaceholder.tsx +9 -5
  54. package/src/components/MapView.tsx +163 -57
  55. package/src/components/Marker.tsx +3 -3
  56. package/src/components/Polygon.tsx +3 -3
  57. package/src/components/Polyline.tsx +2 -2
  58. package/src/components/types.ts +4 -0
  59. package/src/components/utils.ts +31 -0
  60. package/src/{webContent.ts → components/webContent.ts} +20 -39
  61. package/src/components/webFunctions/addMarkerWeb.ts +36 -10
  62. package/src/components/webFunctions/addPolylineWeb.ts +2 -2
  63. package/src/components/webFunctions/fitBoundsWeb.ts +6 -2
  64. package/src/components/webFunctions/flyToWeb.ts +11 -0
  65. package/src/components/webFunctions/initWeb.ts +21 -19
  66. package/src/components/webFunctions/updateWeb.ts +75 -0
  67. package/src/index.tsx +1 -1
  68. package/lib/module/webContent.js.map +0 -1
  69. package/lib/typescript/src/webContent.d.ts +0 -3
  70. package/lib/typescript/src/webContent.d.ts.map +0 -1
@@ -1,8 +1,12 @@
1
1
  export default /*js*/`
2
2
  if(functionName === 'fitBounds') {
3
+
4
+ var padding = (params && params.padding) ? params.padding : 40;
5
+ var duration = (params && params.duration) ? params.duration : 500;
6
+
3
7
  map.fitBounds(params.bounds, {
4
- padding: 40,
5
- duration: 1000
8
+ padding: padding,
9
+ duration: duration
6
10
  });
7
11
  }
8
12
  `;
@@ -0,0 +1,11 @@
1
+ export const flyToWeb = /*js*/`
2
+ if(functionName === 'flyTo') {
3
+
4
+ var duration = (params && params.duration) ? params.duration : 500;
5
+ map.flyTo({
6
+ center: params.center,
7
+ zoom: params.zoom,
8
+ duration: duration
9
+ });
10
+ }
11
+ `;
@@ -58,23 +58,19 @@ export default /*js*/`
58
58
  }
59
59
 
60
60
 
61
- map = new maplibregl.Map({
62
- container: 'map',
63
- style: params.style,
64
- //Moscow coordinates
65
- center: params.center, // starting position [lng, lat]
66
- zoom: params.zoom, // starting zoom
67
61
 
68
62
 
69
- // общий выключатель
70
- zoomControl: params.zoomEnabled,
71
- // точнее
72
- scrollZoom: params.scrollEnabled, // колесо мыши / трекпад
63
+ map = new maplibregl.Map({
64
+ container: 'map',
65
+ style: params.mapStyle,
66
+ center: params.center,
67
+ zoom: params.zoom,
68
+ scrollZoom: params.scrollEnabled,
73
69
  doubleClickZoom: params.zoomEnabled,
74
70
  touchZoomRotate: params.zoomEnabled,
75
71
  minZoom: params.minZoom,
76
- maxZoom: params.maxZoom,
77
- dragPan: params.scrollEnabled, // запрет перетаскивания
72
+ maxZoom: params.maxZoom,
73
+ dragPan: params.scrollEnabled,
78
74
  dragRotate: params.zoomEnabled,
79
75
  antialias: params.antialias ?? false,
80
76
  crossSourceCollisions: params.crossSourceCollisions ?? true,
@@ -104,34 +100,40 @@ export default /*js*/`
104
100
 
105
101
 
106
102
  return {
107
- center,
108
- zoom
103
+ center: center,
104
+ zoom: zoom
109
105
  }
110
106
  }
107
+
108
+ map.on('error', function(event){
109
+
110
+
111
+ window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'error', params: event }));
112
+ })
111
113
 
112
114
  //movestart moveend
113
- map.on("movestart",(event)=>{
115
+ map.on("movestart", function(event){
114
116
  if(params.turboWhileMoving){
115
117
  setOverlayLayersVisibility(map, 'none');
116
118
  }
117
119
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'movestart', params: getEventParams() }));
118
120
  })
119
- map.on("moveend",(event)=>{
121
+ map.on("moveend", function(event){
120
122
  if(params.turboWhileMoving){
121
123
  setOverlayLayersVisibility(map, 'visible');
122
124
  }
123
125
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'moveend', params: getEventParams() }));
124
126
  })
125
127
  /*zoomstart zoomend*/
126
- map.on("zoomstart",(event)=>{
128
+ map.on("zoomstart", function(event){
127
129
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'zoomstart', params: getEventParams() }));
128
130
  })
129
- map.on("zoomend",(event)=>{
131
+ map.on("zoomend", function(event){
130
132
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'zoomend', params: getEventParams() }));
131
133
  })
132
134
 
133
135
 
134
- map.on("idle",(event)=>{
136
+ map.on("idle", function(event){
135
137
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'idle', params: getEventParams() }));
136
138
  })
137
139
 
@@ -0,0 +1,75 @@
1
+ export default /*js*/`
2
+
3
+ function centersAreEqual(a, b, epsilon = 1e-6) {
4
+ return (
5
+ Math.abs(a.lng - b[0]) < epsilon &&
6
+ Math.abs(a.lat - b[1]) < epsilon
7
+ );
8
+ }
9
+
10
+ if(functionName === 'update') {
11
+
12
+ /* if(params && params.center) {
13
+ var newCenter = params.center;
14
+ var currentCenter = map.getCenter();
15
+
16
+ if (!centersAreEqual(currentCenter, newCenter)) {
17
+ map.setCenter(newCenter);
18
+ }
19
+ }
20
+
21
+ if(params && params.zoom != null) {
22
+ var newZoom = params.zoom;
23
+ var currentZoom = map.getZoom();
24
+
25
+ if(currentZoom !== newZoom) {
26
+ map.setZoom(newZoom);
27
+ }
28
+ }*/
29
+
30
+ if(params && params.minZoom != null) {
31
+ var newMinZoom = params.minZoom;
32
+ var currentMinZoom = map.getMinZoom();
33
+
34
+ if(currentMinZoom !== newMinZoom) {
35
+ map.setMinZoom(newMinZoom);
36
+ }
37
+ }
38
+
39
+ if(params && params.maxZoom != null) {
40
+ var newMaxZoom = params.maxZoom;
41
+ var currentMaxZoom = map.getMaxZoom();
42
+
43
+ if(currentMaxZoom !== newMaxZoom) {
44
+ map.setMaxZoom(newMaxZoom);
45
+ }
46
+ }
47
+
48
+ if(params && params.zoomEnabled != null) {
49
+ if(params.zoomEnabled) {
50
+ map.doubleClickZoom.enable();
51
+ map.touchZoomRotate.enable();
52
+ map.dragRotate.enable();
53
+ } else {
54
+ map.doubleClickZoom.disable();
55
+ map.touchZoomRotate.disable();
56
+ map.dragRotate.disable();
57
+ }
58
+ }
59
+
60
+ if(params && params.scrollEnabled != null) {
61
+ if(params.scrollEnabled) {
62
+ map.scrollZoom.enable();
63
+ map.dragPan.enable();
64
+ } else {
65
+ map.scrollZoom.disable();
66
+ map.dragPan.disable();
67
+ }
68
+ }
69
+
70
+ if(params && params.mapStyle) {
71
+ map.setStyle(params.mapStyle);
72
+ }
73
+
74
+ }
75
+ `;
package/src/index.tsx CHANGED
@@ -7,4 +7,4 @@ export { MapView, Marker, Polygon, Polyline };
7
7
  export default MapView;
8
8
 
9
9
  export type { MapViewRef } from './components/MapView';
10
- export type { MarkerProps, PolygonProps, PolylineProps, EventParams } from './components/types';
10
+ export type { MarkerProps, PolygonProps, PolylineProps, EventParams, SourcesProps } from './components/types';
@@ -1 +0,0 @@
1
- {"version":3,"names":["AsyncStorage","CACHE_VERSION","loadResources","url","cacheKey","stored","getItem","_","response","fetch","ok","Error","status","text","setItem","maplibreHtmlMap","webFunctions","sources","maplibreJS","maplibreCSS","pmtiles","pmtilesJS"],"sourceRoot":"../../src","sources":["webContent.ts"],"mappings":";;AAAA,OAAOA,YAAY,MAAM,2CAA2C;AAIpE,MAAMC,aAAa,GAAG,IAAI;AAE1B,MAAMC,aAAa,GAAG,MAAOC,GAAW,IAAK;EACzC,MAAMC,QAAQ,GAAG,GAAGD,GAAG,IAAIF,aAAa,EAAE;EAE1C,IAAI;IACA,MAAMI,MAAM,GAAG,MAAML,YAAY,CAACM,OAAO,CAACF,QAAQ,CAAC;IACnD,IAAIC,MAAM,EAAE;MACR,OAAOA,MAAM;IACjB;EACJ,CAAC,CAAC,OAAOE,CAAC,EAAE;IACR;EAAA;EAGJ,MAAMC,QAAQ,GAAG,MAAMC,KAAK,CAACN,GAAG,CAAC;EACjC,IAAI,CAACK,QAAQ,CAACE,EAAE,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,4BAA4BR,GAAG,KAAKK,QAAQ,CAACI,MAAM,GAAG,CAAC;EAC3E;EACA,MAAMC,IAAI,GAAG,MAAML,QAAQ,CAACK,IAAI,CAAC,CAAC;EAElC,IAAIA,IAAI,EAAE;IACN,IAAI;MACA,MAAMb,YAAY,CAACc,OAAO,CAACV,QAAQ,EAAES,IAAI,CAAC;IAC9C,CAAC,CAAC,OAAON,CAAC,EAAE;MACR;IAAA;EAER;EACA,OAAOM,IAAI;AACf,CAAC;AAED,OAAO,MAAME,eAAe,GAAG,MAAAA,CAAOC,YAAoB,EAAEC,OAAqB,KAAK;EAClF;;EAGA,IAAIC,UAAU,GAAG,MAAMhB,aAAa,CAACe,OAAO,CAACC,UAAU,CAAC;EACxD,IAAIC,WAAW,GAAG,MAAMjB,aAAa,CAACe,OAAO,CAACE,WAAW,CAAC;EAC1D,IAAIC,OAAO,GAAG,MAAMlB,aAAa,CAACe,OAAO,CAACI,SAAS,CAAC;EAIpD,OAAO;AACX;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,cAAcH,UAAU;AACxB;AACA,aAAaC,WAAW;AACxB;AACA;AACA,cAAcC,OAAO;AACrB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,EAAEJ,YAAY;AACd;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ;AACR,CAAC","ignoreList":[]}
@@ -1,3 +0,0 @@
1
- import type { SourcesProps } from './components/types';
2
- export declare const maplibreHtmlMap: (webFunctions: string, sources: SourcesProps) => Promise<string>;
3
- //# sourceMappingURL=webContent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"webContent.d.ts","sourceRoot":"","sources":["../../../src/webContent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAgCvD,eAAO,MAAM,eAAe,GAAU,cAAc,MAAM,EAAE,SAAS,YAAY,oBAmJhF,CAAC"}