pjeweb
pjeweb

Reputation: 13

OpenLayers Comparison Filter / Object Property

Is it possible / is there a workaround to compare a second level propety in OpenLayers.Filter.Comparison?

feature.attributes/context is sth. like:

{'foo': 'bar', 'baz': {'lorem': 'ipsum', 'dolor': 'sit'}, 'amet': 1337}

the rule looks like that:

var rule = new OpenLayers.Rule({
  filter: new OpenLayers.Filter.Comparison({
    type: '==',
    property: 'baz.dolor', /* <- this does not work! */
    value: 'sit'
  }),
  symbolizer: {
    graphic: true,
    graphicZIndex: 100,
    backgroundGraphicZIndex: 500,
    externalGraphic: OpenLayers.Util.getImagesLocation() + 'foo.png',
    graphicHeight: 22,
    graphicWidth: 22,
    graphicTitle: '${display_name}',
    strokeColor: '#FF0000'
  }
});

Upvotes: 1

Views: 2219

Answers (1)

fredj
fredj

Reputation: 143

You can use the OpenLayers.Filter.Function filter:

var filter = new OpenLayers.Filter.Function({
    evaluate: function(attributes) {
        return attributes.baz.dolor === 'sit';
    }
});

(untested example)

Upvotes: 3

Related Questions