Dynamic creation of cluster icons



  • It's necessary to generate caste bacons for clusters that are supposed to paint data for clustered marks (some diagrams; something like that does. layout.PieChart)

    I'm doing something like this for the mark right now. iconImageHref in the form of a marker data:image/svg+xml;charset=UTF-8,<svg ... />

    For clusters while using templateLayoutFactory (Grunts) clusterIconContentLayout Clasterizer) to get the text inside the skirt and to put the tag for the badge clusterIcons: [{ href: clusterIconSrc, size: [60, 60], width: [-30, -30] }] (in properties for Clusterer)

    The solution would be to transfer a function that would create a url with caste svg or a whole object. clusterIcons

    I don't see how to do anything like this.

    I tried to get to the internal api modules, but I'm still looking for nothing. Napr, that's the way it is.

    modules.define('theme.islands.cluster.layout.Icon', ['theme.islands.cluster.layout.Icon'], override(provide, baseIcon) => {
      const overrided = Object.assign({}, baseIcon, {
        getShape: function getShape(geometry) { /*...*/ },
      })
      provide(overrided)
    })
    

    Used:

    • ymaps api v2.1.79
    • react-yandex-maps v4.6.0


  • Possible solution: redefining the method Clusterer.prototype.createClusterin which the characteristics of the cluster specified clusterIcons Dynamic (depending on the bulb of clustered objects and their properties) href for the icon of the cluster:

    // Save original `createCluster` method...
    const origCreateCluster = Clusterer.prototype.createCluster
    // Override `createCluster` method...
    Clusterer.prototype.createCluster = function overrideCreateCluster(center, geoObjects) {
      // Fetch clustered objects data...
      const objData = geoObjects.map(geoObj => ({ id: geoObj.options.get('id') }))
      // Generate `clusterIcons` object with custom icon src...
      const iconSrc = getClusterIconSrcByObjData(objData)
      const clusterIconsEntry = { ...defaultClusterIconsEntry, href: iconSrc }
      this.options.set('clusterIcons', [clusterIconsEntry])
      // Get cluster placemark content...
      return origCreateCluster.call(this, center, geoObjects)
    }
    

    This method works except for url with data:image/svg+xml;charset=UTF-8,<svg We need to use url in the base64L code. data:image/svg+xml;base64,... (with help) btoa, nap. ♪


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2