Microsoft.Maps.ClusterLayer RRS feed

  • Question

  • Hi I am trying to create JSON to populate clusters of pins. A simple test to see if this works fails, can you please tell me why. See below.

        This works as per your example

                      var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(2, map.getBounds());

                      var clusterLayer = new Microsoft.Maps.ClusterLayer(pushpins, { gridSize: 100 });

        This does not work, I don't know why as the object models are identical !!!

                      var pushpins = Microsoft.Maps.TestDataGenerator.getPushpins(2, map.getBounds());

                      data = JSON.parse(JSON.stringify(pushpins)); // data should be the same as pushpins yet it does not work

                      var clusterLayer = new Microsoft.Maps.ClusterLayer(data, { gridSize: 100 });

    Wednesday, March 15, 2017 10:25 AM


  • The second method shouldn't work, pushpins are not simple JSON objects, they are JavaScript classes that have functions. When you use JSON stringify/parse the functions are stripped out and as such the resulting object is no longer a Pushpin class. When you pass that into the cluster layer it isn't able to do anything with it as all the required functions on the Pushpin class are missing from the JSON object.

    [Blog] [twitter] [LinkedIn]

    Wednesday, March 15, 2017 3:30 PM