1

Topic: Clustered symbology

Is it possible to do clustering like this with Indicia?

I'm sure I've asked this before, but can't find an answer anywhere. Sorry in advance if this is an old topic.

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

2

Re: Clustered symbology

Hi Charles,
Yes, it is possible, though there is no support integrated into the Indicia framework directly. In the report_helper.php file you will find a method called addFeaturesLoadingJs. Replace this with the following for a quick "hack":

private static function addFeaturesLoadingJs($addFeaturesJs, $defsettings='',
      $selsettings='{"strokeColor":"#ff0000","fillColor":"#ff0000","strokeWidth":2}', $styleFns='', $zoomToExtent=true) {
    if (!empty($addFeaturesJs)) {
      report_helper::$javascript.= "
  if (typeof OpenLayers !== \"undefined\") {
    var style = new OpenLayers.Style({
                    pointRadius: '\${radius}',
                    fillColor: '\${color}',
                    fillOpacity: 0.8,
                    strokeColor: '\${color}',
                    strokeWidth: 2,
                    strokeOpacity: 0.8,
                    fontColor: '#FFFFFF',
                    label: '\${label}'
                }, {
                    context: {
                        radius: function(feature) {
                          return Math.min(feature.attributes.count, 7) + 3;
                        },
                        label: function (feature) {
                          return feature.attributes.count;
                        },
                        color: function(feature) {
                          var n=Math.min(feature.attributes.count, 7)*36;
                          return 'rgb('+n+', 0, '+(255-n)+')';
                        }
                    }
                });
    indiciaData.reportlayer = new OpenLayers.Layer.Vector('Report output', {rendererOptions: {zIndexing: true},
        strategies: [
          new OpenLayers.Strategy.Cluster()
        ],
        styleMap: new OpenLayers.StyleMap({
            'default': style,
            'select': {
                fillColor: '#8aeeef',
                strokeColor: '#32a8a9'
            }
        })
    });
    mapInitialisationHooks.push(function(div) {
      features = [];
      $addFeaturesJs
      indiciaData.reportlayer.addFeatures(features);\n";
        if ($zoomToExtent)
          self::$javascript .= "  div.map.zoomToExtent(indiciaData.reportlayer.getDataExtent());\n";
        self::$javascript .= "  div.map.addLayer(indiciaData.reportlayer);
    });
  }\n";
    }
  }

Of course, it would be essential to make these changes an option rather than an enforced hack so that it can become part of the core code, plus it needs to be fairly flexible in how it calculates the point size, point colour and label output. In fact it might be nice to allow the strategy to switch off when you've zoomed in enough. Not sure if you fancy to take that on?

John van Breda
Biodiverse IT

3

Re: Clustered symbology

johnvanbreda wrote:

In fact it might be nice to allow the strategy to switch off when you've zoomed in enough.

Yeah, that's what the bugs count map appears to do when you get in close. This approach definitely makes sense to me.

johnvanbreda wrote:

Not sure if you fancy to take that on?

Hah, one step at a time John, one step at a time. ;-)

Charles Roper
Digital Development Manager | Field Studies Council
http://www.field-studies-council.org | https://twitter.com/charlesroper | https://twitter.com/fsc_digital

4

Re: Clustered symbology

Not quite - the cluster strategy used on bugs count and in my demo code will continue using the clustering style as you zoom in, its just the points are far enough apart not to cluster. My thoughts were that it could be an option to revert to the original grid square based view if you zoom in far enough rather than show circles.

John van Breda
Biodiverse IT