ionic-team / ionic-native-google-maps

Google maps plugin for Ionic Native
Other
221 stars 125 forks source link

Polygon is missing subscription when previous polygon is removed #273

Closed alvaromico closed 4 years ago

alvaromico commented 4 years ago

I'm submitting a ... (check one with "x")

If you choose 'problem or bug report', please select OS: (check one with "x")

cordova information: (run $> cordova plugin list)

cordova-plugin-background-mode 0.7.3 "BackgroundMode" cordova-plugin-camera 4.1.0 "Camera" cordova-plugin-dbcopy 2.1.2 "sqlDB" cordova-plugin-device 2.0.3 "Device" cordova-plugin-file 6.0.2 "File" cordova-plugin-geolocation 4.0.2 "Geolocation" cordova-plugin-googlemaps 2.6.2 "cordova-plugin-googlemaps" cordova-plugin-headercolor 1.0 "HeaderColor" cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 2.5.3 "cordova-plugin-ionic-webview" cordova-plugin-mauron85-background-geolocation 3.0.1 "CDVBackgroundGeolocation" cordova-plugin-network-information 2.0.2 "Network Information" cordova-plugin-photo-viewer 1.1.5 "PhotoViewer" cordova-plugin-splashscreen 5.0.3 "Splashscreen" cordova-plugin-statusbar 2.4.3 "StatusBar" cordova-plugin-whitelist 1.3.4 "Whitelist" cordova-plugin-zip 3.1.0 "cordova-plugin-zip" cordova-sqlite-storage 3.4.0 "Cordova sqlite storage plugin - cordova-sqlite-storage plugin version"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

"@ionic-native/core": "~4.17.0", "@ionic-native/google-maps": "^4.17.0",

Current behavior: Two ploygons are added to the map, then each polygon is subscribed to POLYGON_CLICK event. When first polygon is removed, second polygon subscription is not working. If the polygon removed is the second added,first polygon subscription works perfectly.

Expected behavior: Two ploygons are added to the map, then each polygon is subscribed to POLYGON_CLICK event. When first polygon is removed, second polygon subscription works.

Related code, data or error log (please format your code or data): I put an example because project repository is not public, I hope is enough:

this.map = GoogleMaps.create('map', this.mapOptions);
this.map.one(GoogleMapsEvent.MAP_READY).then(async () => {
const poly1 = await this.map.addPolygon({
    points: [{ lat: 39.477177, lng: -0.367565 }, { lat: 39.482963, lng: -0.364673 }
      , { lat: 39.483940, lng: -0.367988 }, { lat: 39.478777, lng: -0.370885 }],
    clickable: true,
  }).then((polygon: Polygon) => {
    return polygon;
  });

  poly1.on(GoogleMapsEvent.POLYGON_CLICK).subscribe((data) => {
    console.log('polygon click');
  });

  const poly2 = await this.map.addPolygon({
    points: [{ lat: 39.477838, lng: -0.387920 }, { lat: 39.475468, lng: -0.387167 }
      , { lat: 39.475558, lng: -0.385773 }, { lat: 39.478317, lng: -0.385941 }],
    clickable: true
  }).then((polygon: Polygon) => {
    return polygon;
  });

  poly2.on(GoogleMapsEvent.POLYGON_CLICK).subscribe((data) => {
    console.log('polygon click');
  });

  poly1.remove();
});

}

If ploy1.setVisible(false) is used instead of poly1.remove(), the error persists.

wf9a5m75 commented 4 years ago

Please upgrade @ionic-native/google-maps at least before asking.

alvaromico commented 4 years ago

Sorry, updated to last 4.X.X version because I'm using ionic v3, and if I'm not wrong version 5 of native plugins only works on ionic v4 right?

wf9a5m75 commented 4 years ago

Yes. No longer support for 4.x.x.

alvaromico commented 4 years ago

I've tried in a ionic v4 project, with latest ionic-native/core (5.17.1) and ionic-native/google-maps(5.5.0) plugins versions and the error still remains.

wf9a5m75 commented 4 years ago

Try this.map.addPolygonSync() instead of await this.map.addPolygon

alvaromico commented 4 years ago

Yes, I tried that when I did the test in the ionic v4 project and it was failed too. The same error occured using Polylines (addPolyline() and addPolylineSync()).

wf9a5m75 commented 4 years ago

I see, please debug and send a pull request.