react-native-maplibre-lite 0.1.1 → 0.1.3

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 +52 -20
  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 +52 -20
  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
+ `;
@@ -12,10 +12,40 @@ export default /*js*/`
12
12
  var layerType = layer.type;
13
13
  var shouldHide = false;
14
14
 
15
- if(layerType === 'symbol' || layerType === 'fill-extrusion' || layerType === 'hillshade'){
15
+ // Keep labels (streets / addresses) visible hide only expensive visual layers by default.
16
+ if(layerType === 'fill-extrusion' || layerType === 'hillshade'){
16
17
  shouldHide = true;
17
18
  }
18
19
 
20
+ if(layerType === 'symbol' && aggressive){
21
+ var idLower = String(layerId || '').toLowerCase();
22
+ var sourceLayerLower = String(layer['source-layer'] || '').toLowerCase();
23
+
24
+ // Keep road + address/house number labels.
25
+ var keepLabel =
26
+ idLower.indexOf('road') !== -1 ||
27
+ idLower.indexOf('street') !== -1 ||
28
+ idLower.indexOf('housenumber') !== -1 ||
29
+ idLower.indexOf('house_number') !== -1 ||
30
+ idLower.indexOf('house-number') !== -1 ||
31
+ idLower.indexOf('address') !== -1 ||
32
+ sourceLayerLower.indexOf('housenumber') !== -1 ||
33
+ sourceLayerLower.indexOf('house') !== -1 ||
34
+ sourceLayerLower.indexOf('address') !== -1;
35
+
36
+ // Hide most POI/other symbols in aggressive mode.
37
+ var hideSymbol =
38
+ idLower.indexOf('poi') !== -1 ||
39
+ idLower.indexOf('transit') !== -1 ||
40
+ idLower.indexOf('airport') !== -1 ||
41
+ idLower.indexOf('rail') !== -1 ||
42
+ idLower.indexOf('ferry') !== -1;
43
+
44
+ if(!keepLabel && hideSymbol){
45
+ shouldHide = true;
46
+ }
47
+ }
48
+
19
49
  if(aggressive && (layerType === 'line' || layerType === 'circle')){
20
50
  var layerIdLower = String(layerId || '').toLowerCase();
21
51
  if(
@@ -58,23 +88,19 @@ export default /*js*/`
58
88
  }
59
89
 
60
90
 
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
91
 
68
92
 
69
- // общий выключатель
70
- zoomControl: params.zoomEnabled,
71
- // точнее
72
- scrollZoom: params.scrollEnabled, // колесо мыши / трекпад
93
+ map = new maplibregl.Map({
94
+ container: 'map',
95
+ style: params.mapStyle,
96
+ center: params.center,
97
+ zoom: params.zoom,
98
+ scrollZoom: params.scrollEnabled,
73
99
  doubleClickZoom: params.zoomEnabled,
74
100
  touchZoomRotate: params.zoomEnabled,
75
101
  minZoom: params.minZoom,
76
- maxZoom: params.maxZoom,
77
- dragPan: params.scrollEnabled, // запрет перетаскивания
102
+ maxZoom: params.maxZoom,
103
+ dragPan: params.scrollEnabled,
78
104
  dragRotate: params.zoomEnabled,
79
105
  antialias: params.antialias ?? false,
80
106
  crossSourceCollisions: params.crossSourceCollisions ?? true,
@@ -104,34 +130,40 @@ export default /*js*/`
104
130
 
105
131
 
106
132
  return {
107
- center,
108
- zoom
133
+ center: center,
134
+ zoom: zoom
109
135
  }
110
136
  }
137
+
138
+ map.on('error', function(event){
139
+
140
+
141
+ window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'error', params: event }));
142
+ })
111
143
 
112
144
  //movestart moveend
113
- map.on("movestart",(event)=>{
145
+ map.on("movestart", function(event){
114
146
  if(params.turboWhileMoving){
115
147
  setOverlayLayersVisibility(map, 'none');
116
148
  }
117
149
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'movestart', params: getEventParams() }));
118
150
  })
119
- map.on("moveend",(event)=>{
151
+ map.on("moveend", function(event){
120
152
  if(params.turboWhileMoving){
121
153
  setOverlayLayersVisibility(map, 'visible');
122
154
  }
123
155
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'moveend', params: getEventParams() }));
124
156
  })
125
157
  /*zoomstart zoomend*/
126
- map.on("zoomstart",(event)=>{
158
+ map.on("zoomstart", function(event){
127
159
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'zoomstart', params: getEventParams() }));
128
160
  })
129
- map.on("zoomend",(event)=>{
161
+ map.on("zoomend", function(event){
130
162
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'zoomend', params: getEventParams() }));
131
163
  })
132
164
 
133
165
 
134
- map.on("idle",(event)=>{
166
+ map.on("idle", function(event){
135
167
  window.ReactNativeWebView.postMessage(JSON.stringify({ type: 'event', event: 'idle', params: getEventParams() }));
136
168
  })
137
169
 
@@ -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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ACA;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"}