Clustering in Maps add-on

Hi JMIX team
Do you have any examples or can share code snippets how the weightProperty can be used?

weightProperty — if specified, then each point of the layer will have a weight value (int) defined by the weight property of the geo-object. This value will be used when calculating the summed-up value of the cluster (by default, the number of points is used).

I have a use case.

  1. I want to show the total sales amount from customers in different geolocations instead of just count of customers.
  2. The aggregation will be based on the hierarchy used e.g. Country, Province, District etc.

As per the documentation, it seems #1 above is possible but any sample code will be helpful.

Is this add-on has the option to achieve #2 above too?

Hello!

  1. weightProperty takes entity’s property to show value of the cluster instead of number of points. It should return the Integer type.

You can define the existing property from entity or create non-persistent property which will be calculated based other ones or later. For instance the weight property in Location entity:

Location class
@JmixEntity
@Table(name = "SAMPLER_LOCATION")
@Entity(name = "sampler_Location")
public class Location {

    @JmixGeneratedValue
    @Column(name = "ID", nullable = false)
    @Id
    private UUID id;

    @Column(name = "NAME")
    private String name;

    @Column(name = "POINT")
    @Geometry
    @Convert(converter = PointWKTConverter.class)
    protected Point point;

    @Column(name = "INTENSITY")
    private Double intensity;

    @JmixProperty
    @Transient
    private Integer weight = RandomUtils.nextInt(1, 100);

    public Double getIntensity() {
        return intensity;
    }

    public void setIntensity(Double intensity) {
        this.intensity = intensity;
    }

    public Point getPoint() {
        return point;
    }

    public void setPoint(Point point) {
        this.point = point;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public UUID getId() {
        return id;
    }

    public void setId(UUID id) {
        this.id = id;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }
}

And set this property in the map:

<maps:geoMap id="map"
             zoom="14"
             centerX="-1.98"
             centerY="53.464"
             height="100%"
             width="100%">
    <maps:layers>
        <maps:tile id="tiles" tileProvider="map_OpenStreetMap"/>
        <maps:vector id="locations" dataContainer="locationsDc">
            <maps:cluster disableAtZoom="18" weightProperty="weight"/>
        </maps:vector>
    </maps:layers>
</maps:geoMap>
  1. As far as I know map does not provide the ability to cluster by country, city, etc. I think the only way is to group data by containers and create several layers with cluster. However they won’t group together.
<maps:layers>
     ...
    <maps:vector id="locations" dataContainer="locationsDc">
        <maps:cluster/>
    </maps:vector>
    <maps:vector id="locations2" dataContainer="locationsDc2">
        <maps:cluster/>
    </maps:vector>
</maps:layers>

Thank you. #1 point working. How can we use the style in Cluster? for example,

  1. make it red when a certain criterion is not met and blue in other cases.
  2. change the opacity.

I found the styling of polygon but not for Clustering. Thanks for sharing some codes.

For now, cluster-marker can only be styled by its default style names.

I created an issue: jmix-framework/jmix#713

Hi,
Thanks for creating the issue for enhancement. You may also consider adding the following too:
3. Option to use different shapes (instead of just circle)
4. Option to show more than 1 value like a) target sales b) actual sales. These two fields can be the criteria to change the colour e.g. when actual sales >= target then green, else red.

Do you also have any plan to include Direction, distance, routing etc. features in the map add-on? Currently, the map component add-on looks to have very limited functionalities. Being a commercial component, I would expect more useful features in it.

1 Like

Hi Mortoza,

Thanks for your feedback!
We’ll definitely consider adding these features.

Regards,
Konstantin

1 Like