Geoserver WFS图层作为在OpenLayers Vector图层上转换为字符串的Timestamp字段

时间:2014-03-04 05:17:07

标签: function filter openlayers between

我在开放图层中使用WFS图层,代码如下:

    crashes = new OpenLayers.Layer.Vector(title, {
        strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1}), clusterStrategy],
        minScale: minimumScale,
        visibility:visiblity,
        displayInLayerSwitcher:showInLayerSwitcher,
        protocol: new OpenLayers.Protocol.WFS({
            version: "1.1.0",
            srsName: srid,
            url: wfsUrl,
            featureType: layerName,
            geometryName: geomCol,
            featurePrefix: prefix,
            featureNS :  namespace
        }),
        styleMap: new OpenLayers.StyleMap({
            "default": style,
            "select": {
                fillColor: "red",
                strokeColor: "#32a8a9"
            }
        })             
    }); 

来自传入参数的函数。这个层很好地工作。

我现在想要对此图层应用过滤器,其中一个过滤器使用日期字段之间的比较。

                       ,new OpenLayers.Filter.Comparison({
                            type: OpenLayers.Filter.Comparison.BETWEEN,
                            property: "CRASH_DATE",
                            lowerBoundary: new Date(2011,0,1);,
                            upperBoundary: new Date(2014,0,1);
                        })

似乎所有字段都转换为字符串类型,因此尝试执行此camparison结果时不会返回任何数据:

我也尝试过创建没有结果的函数过滤器:

                    vehicleCrashLayer.filter = new OpenLayers.Filter.Logical({
                    type: OpenLayers.Filter.Logical.AND,
                    filters: [
                        new OpenLayers.Filter.Spatial({
                            type: OpenLayers.Filter.Spatial.INTERSECTS,
                            value: event.feature.geometry,
                        })            
                        ,new OpenLayers.Filter.Comparison({
                            type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
                            property: "SEVERITY",
                            value: "Property Damage Only"
                        })                                       
                        ,new OpenLayers.Filter.Comparison({
                            type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
                            property: "SEVERITY",
                            value: "Not Known"
                        }) 

                        ,new OpenLayers.Filter.Comparison({
                            type: OpenLayers.Filter.Comparison.NOT_EQUAL_TO,
                            property: "SEVERITY",
                            value: "Not Stated"
                        })                     
                        ,new OpenLayers.Filter.Function({
                            name: 'dateBetween',
                            type: OpenLayers.Filter.Function,
                            evaluate: function(feature){
                                 console.log(feature.attributes);
                                 var x=0;
                                 return true;
                                }
                         })                      
                    ]
                });

任何人都可以帮忙解决这个问题。例子很少见。

1 个答案:

答案 0 :(得分:0)

我还没有对此进行测试,但您是否尝试过类似时间戳的价值? 在Javascript中:new Date().getTime() 这将返回自给定时间以来的毫秒数。如果您可以安排数据库也返回此值,那么您将使用整数。这很容易......