dapriett / nativescript-google-maps-sdk

Cross Platform Google Maps SDK for Nativescript
MIT License
244 stars 164 forks source link

infoWindow properties can only be set once #372

Open dlcole opened 4 years ago

dlcole commented 4 years ago

I have a custom infoWindow with a property that contains a timestamp to indicate how long the marker has been at that position. I set the property in the markerSelect event handler and it works as expected the first time. On any subsequent invocations, though, the infoWindow text remains unchanged.

That is, tapping the marker the first time accurately shows how long the marker has been at that position. Tapping the marker a second and subsequent time always shows the value of the first tap, as if the property can only be written to once.

Is this an inherent limitation, or is there a way to set the property value so that the current value will be shown on the infoWindow?

dapriett commented 4 years ago

@dlcole - Could be a limitation on how we're attaching the view, and maybe the bindingContext isn't refreshing.

Could mess around with deleting the reference to marker._infoWindowView to remove the cache of the view before updating the timestamp:

https://github.com/dapriett/nativescript-google-maps-sdk/blob/000798392872f5c426aeb1b64b846f52d9ce2cf8/src/map-view-common.ts#L197

dlcole commented 4 years ago

@dapriett - That works! Here's my resulting code:

exports.onMarkerSelect = function (args) {

  // See: https://github.com/dapriett/nativescript-google-maps-sdk/issues/372
  if (args.marker.hasOwnProperty("uuid")) {
    args.marker._infoWindowView = undefined;
    args.marker.info = myutils.timeSince(args.marker.timestamp);
  }

} 

Thanks for your prompt help.