简体   繁体   中英

Geoserver WFS layer as Timestamp fields converted to string on OpenLayers Vector layer

I am using a WFS layer in open layers with the following code:

    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"
            }
        })             
    }); 

from a function where the parameters are passed in. This layer works nicely.

I now want to apply filters to this layer, one of which being using the between comparison on a date field.

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

It appears as if all the fields are converted to string types so trying to do this camparison results in no data being returned:

I have also tried creating function filter which returns no results:

                    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;
                                }
                         })                      
                    ]
                });

Can anyone help with this. Examples are few and far between.

I haven't tested this, but have you tried timestamp-like value? in Javascript: new Date().getTime() This returns the number of miliseconds since the given time. If you could arrange your database to return this value too, you'd be working with an integer. And that is pretty easy...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM