naderio / nativescript-google-maps-utils

NativeScript Google Maps SDK utility library to support features such as marker clustering, heatmap, ...
The Unlicense
33 stars 15 forks source link

Overriding DefaultClusterRenderer function doesn't get called #5

Closed dxshindeo closed 7 years ago

dxshindeo commented 7 years ago
var renderer = new dis.clustering.view.DefaultClusterRenderer(app.android.context, dis.gMap, dis.cluster_manager);

renderer.onBeforeClusterItemRendered = function (item, markerOptions) {
    console.log("setup");
    markerOptions.alpha(0.8);
    markerOptions.flat(true);
    markerOptions.rotation(item.rotation);

    var icon = new Image();
    icon.imageSource = imageSource.fromResource('icon_location');
    var androidIcon = com.google.android.gms.maps.model.BitmapDescriptorFactory.fromBitmap(icon.imageSource.android);
    markerOptions.icon(androidIcon);

};

dis.cluster_manager.setRenderer(renderer);

It compiles without errors, and when I do renderer.setMinClusterSize(1); it sets it accordingly. However, I get the default markers and default cluster style. So I am console.logging the function, but it is not logging out anything. Is this implemented correctly?

naderio commented 7 years ago

@dxshindeo that's not the correct way to override a class' method in nativescript, please check https://docs.nativescript.org/runtimes/android/generator/extend-class-interface it goes as follow

const CustomClusterRenderer = dis.clustering.view.DefaultClusterRenderer.extend({

  //constructor
  init: function () {},

  onBeforeClusterItemRendered: function (item, markerOptions) {

    console.log("setup");
    markerOptions.alpha(0.8);
    markerOptions.flat(true);
    markerOptions.rotation(item.rotation);

    var icon = new Image();
    icon.imageSource = imageSource.fromResource('icon_location');
    var androidIcon = com.google.android.gms.maps.model.BitmapDescriptorFactory.fromBitmap(icon.imageSource.android);
    markerOptions.icon(androidIcon);

  }

});

var renderer = new CustomClusterRenderer(app.android.context, dis.gMap, dis.cluster_manager);
dxshindeo commented 7 years ago

Thank you, this worked!!! :)