21
21
*/
22
22
23
23
import { map, mapCommon, site } from '@kit.MapKit';
24
+ import { RNComponentContext } from '@rnoh/react-native-openharmony';
24
25
import { AIRMapCallout, AIR_MAP_CALLOUT_TYPE } from './AIRMaps/AIRMapCallout';
26
+ import { AIR_MAP_CIRCLE_TYPE } from './AIRMaps/AIRMapCircle';
25
27
import { AIRMapMarkerDescriptor,
26
28
AIRMapPolylineDescriptor,
27
29
AIRMapPolygonDescriptor,
@@ -34,6 +36,8 @@ import { AIRMapMarkerDescriptor,
34
36
AIRMapOverlayDescriptor
35
37
} from './AIRMaps/AIRMapDescriptorTypes';
36
38
import { AIRMapMarker, AIR_MAP_MARKER_TYPE } from './AIRMaps/AIRMapMarker';
39
+ import { AIR_MAP_POLYGON_TYPE } from './AIRMaps/AIRMapPolygon';
40
+ import { AIR_MAP_POLYLINE_TYPE } from './AIRMaps/AIRMapPolyline';
37
41
import { LWError, LWLog } from './LWLog';
38
42
import { MapsTurboManager } from './MapsTurboManager';
39
43
import {
@@ -57,17 +61,22 @@ export class MapsManager{
57
61
58
62
private mapController?: map.MapComponentController;
59
63
private initMapController = false;
64
+ private eventNodeMap: Map<string, number> = new Map();
60
65
61
66
initMapComponentController(controller?: map.MapComponentController){
62
67
LWLog('MapsManager.initMapComponentController----->controller=' + controller)
63
68
if (!controller) {
64
69
//释放controller
65
70
if (this.mapController) {
71
+ this.eventNodeMap.clear();
66
72
this.mapController?.off('markerClick', ()=>{});
67
73
this.mapController?.off('markerDragStart', ()=>{});
68
74
this.mapController?.off('markerDrag', ()=>{});
69
75
this.mapController?.off('markerDragEnd', ()=>{});
70
76
this.mapController?.off('infoWindowClick', ()=>{});
77
+ this.mapController?.off('polylineClick', ()=>{});
78
+ this.mapController?.off('polygonClick', ()=>{});
79
+ this.mapController?.off('circleClick', ()=>{});
71
80
}
72
81
}
73
82
this.mapController = controller;
@@ -113,27 +122,27 @@ export class MapsManager{
113
122
};
114
123
return this.mapController.addMarker(markerOptions).then(marker => {
115
124
LWLog('MapsManager.addMarker----------marker=' + marker.getId())
116
-
125
+ this.eventNodeMap.set(marker.getId(), desc.tag);
117
126
this.mapController?.on("markerClick", (marker)=>{
118
- _this.ctx.rnInstance.emitComponentEvent(_this.descriptor.tag , AIR_MAP_MARKER_TYPE, { type: "onPress" });
127
+ _this.ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(marker.getId()) , AIR_MAP_MARKER_TYPE, { type: "onPress" });
119
128
if (marker.getTitle()) {
120
129
marker.setInfoWindowVisible(!marker.isInfoWindowVisible());
121
130
}
122
131
})
123
132
this.mapController?.on("markerDragStart", (marker)=>{
124
- _this.ctx.rnInstance.emitComponentEvent(_this.descriptor.tag , AIR_MAP_MARKER_TYPE, { type: "onDragStart", coordinate: marker.getPosition() });
133
+ _this.ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(marker.getId()) , AIR_MAP_MARKER_TYPE, { type: "onDragStart", coordinate: marker.getPosition() });
125
134
})
126
135
this.mapController?.on("markerDrag", (marker)=>{
127
- _this.ctx.rnInstance.emitComponentEvent(_this.descriptor.tag , AIR_MAP_MARKER_TYPE, { type: "onDrag", coordinate: marker.getPosition() });
136
+ _this.ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(marker.getId()) , AIR_MAP_MARKER_TYPE, { type: "onDrag", coordinate: marker.getPosition() });
128
137
})
129
138
this.mapController?.on("markerDragEnd", (marker)=>{
130
- _this.ctx.rnInstance.emitComponentEvent(_this.descriptor.tag , AIR_MAP_MARKER_TYPE, { type: "onDragEnd", coordinate: marker.getPosition() });
139
+ _this.ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(marker.getId()) , AIR_MAP_MARKER_TYPE, { type: "onDragEnd", coordinate: marker.getPosition() });
131
140
})
132
141
return marker;
133
142
});
134
143
}
135
144
136
- addPolyline(desc: AIRMapPolylineDescriptor){
145
+ addPolyline(desc: AIRMapPolylineDescriptor, ctx: RNComponentContext ){
137
146
LWLog('MapsManager.addPolyline----------rawProps=【' + JSON.stringify(desc.rawProps) + '】')
138
147
if (!this.mapController) {
139
148
LWError('addPolyline error, mapController is undefined!')
@@ -157,12 +166,15 @@ export class MapsManager{
157
166
// 创建polyline
158
167
return this.mapController.addPolyline(polylineOption).then(mapPolyline=>{
159
168
LWLog('MapsManager.addPolyline----------polyline=' + mapPolyline)
169
+ this.eventNodeMap.set(mapPolyline.getId(), desc.tag);
170
+ this.mapController?.on("polylineClick", (polyline) => {
171
+ ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(polyline.getId()), AIR_MAP_POLYLINE_TYPE, { type: "onPress" });
172
+ })
160
173
return mapPolyline;
161
174
});
162
-
163
175
}
164
176
165
- addPolygon(desc: AIRMapPolygonDescriptor){
177
+ addPolygon(desc: AIRMapPolygonDescriptor, ctx: RNComponentContext ){
166
178
LWLog('MapsManager.addPolygon----------rawProps=【' + JSON.stringify(desc.rawProps) + '】')
167
179
if (!this.mapController) {
168
180
LWError('addPolygon error, mapController is undefined!')
@@ -184,12 +196,15 @@ export class MapsManager{
184
196
// 创建多边形
185
197
return this.mapController.addPolygon(polygonOptions).then(mapPolygon=>{
186
198
LWLog('MapsManager.addPolygon----------polygon=' + mapPolygon)
199
+ this.eventNodeMap.set(mapPolygon.getId(), desc.tag);
200
+ this.mapController?.on("polygonClick", (polygon) => {
201
+ ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(polygon.getId()), AIR_MAP_POLYGON_TYPE, { type: "onPress" });
202
+ })
187
203
return mapPolygon;
188
204
});
189
-
190
205
}
191
206
192
- addCircle(desc: AIRMapCircleDescriptor){
207
+ addCircle(desc: AIRMapCircleDescriptor, ctx: RNComponentContext ){
193
208
LWLog('MapsManager.addCircle----------rawProps=【' + JSON.stringify(desc.rawProps) + '】')
194
209
if (!this.mapController) {
195
210
LWError('addCircle error, mapController is undefined!')
@@ -212,6 +227,10 @@ export class MapsManager{
212
227
// 创建Circle
213
228
return this.mapController.addCircle(mapCircleOptions).then(mapCircle=>{
214
229
LWLog('MapsManager.addCircle----------circle=' + JSON.stringify(mapCircle));
230
+ this.eventNodeMap.set(mapCircle.getId(), desc.tag);
231
+ this.mapController?.on("circleClick", (circle) => {
232
+ ctx.rnInstance.emitComponentEvent(this.eventNodeMap.get(circle.getId()), AIR_MAP_CIRCLE_TYPE, { type: "onPress" });
233
+ })
215
234
return mapCircle;
216
235
});
217
236
}
0 commit comments