On Mar 16, 2012, at 3:13 PM, nguyenl wrote:

> Hi,
> 
> I'm trying to configure openlayers to render a Vector layer of points.  The
> points are in GeoJSON format and are queried with Ajax using BBOX strategy.
> 
> I've been trying to get it working, but can't find any examples on how to do
> this, and I haven't been able to get it thus far.
> 
> Is this possible?  

I just got this working a couple of days ago, and I am still mystified by at 
least one issue, but hopefully the following advice will get you started. See 
the code below --

        var vec = new OpenLayers.Layer.Vector(
                "My Vector Layer", {
                        strategies: [new OpenLayers.Strategy.BBOX()],
                        protocol: new OpenLayers.Protocol.HTTP({
                    url: "http://webserver/path/to/geojson.json";,
                    params: {
                                        "a": "value of a",
                                        "b": function() {
                                                return a_value_for_b;
                                        }
                    format: new OpenLayers.Format.GeoJSON()
                }),
                        
                styleMap: new OpenLayers.StyleMap({
                    "default": defaultStyle,
                    "select": selectStyle
                })
            }
        );
        
The above code should just work. You can pass additional params to the query 
via the params key above. The only catch is, the data returned by the url has 
to be geojson at the root level. My data being returned is tucked inside a key. 
So, instead of getting back

        {a geojson packet}
        
I am getting

        {result: 
                info: {
                        value: "some value",
                        array: ["some", "array"]
                },
                geojson: {a geojson packet}
        }
        
and I don't quite know where to intercept that and tell the layer that, hey, 
grab result.geojson to make the vector layer.


--
Puneet Kishor_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to