Plot features onto multiple layers from one HTTP request

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Plot features onto multiple layers from one HTTP request

khanh703
I would like to plot features onto multiple layers from one HTTP request ie (Burgers, Hot Dogs, etc...)

I can achieve what I want by making multiple request but would rather make one request.

How can I achieve plotting on different layers:
1. Change the protocol attributes to read from local ARRAY and do a while loop
or
2. Change my FeatureCollection structure

This below works but all features are plotted on the same layer:
markers = new OpenLayers.Layer.Vector(thisLayer, {
            preFeatureInsert: preFeatureInsert,
            strategies: [
                new OpenLayers.Strategy.Fixed(),
                new OpenLayers.Strategy.Cluster({
                    distance: 20
                })
            ],
            protocol: new OpenLayers.Protocol.HTTP({
                url: protocolUrl,
                format: protocolFormat
            }),
            projection: MapProj,
            formatOptions: {
                extractStyles: true,
                extractAttributes: true
            },
            styleMap: new OpenLayers.StyleMap({
                "default": style,
                "select": style
            }),
            catID: 0
        });

with this collection:
{
    "type": "FeatureCollection",
    "features": [{
        "type": "feature",
        "properties": {
            "id": "7943",
            "name": "Bobs Burger",
            "category": "57",
            "color": "9875c3",
            "timestamp": "1400149988"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [-76.437099, 39.041711]
        }
    }, {
        "type": "feature",
        "properties": {
            "id": "7944",
            "name": "Hot Diggity",
            "category": "54",
            "color": "b33838",
            "timestamp": "1400150184"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [-76.436586, 39.041696]
        }
    }]
}
Reply | Threaded
Open this post in threaded view
|

Re: Plot features onto multiple layers from one HTTP request

ivan.price
perform your own ajax call, requesting the 2 layers and getting the single return dictionary/object in something like geojson, then add them to the target layer manually ?

or some knick-nack where there is a 'master layer' that is connected to a url, and another that receives features from it based on an attribute value.

-i



-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de khanh703
Envoyé : Wednesday, 4 June 2014 16:50
À : [hidden email]
Objet : [OpenLayers-Dev] Plot features onto multiple layers from one HTTP request

I would like to plot features onto multiple layers from one HTTP request ie (Burgers, Hot Dogs, etc...)

I can achieve what I want by making multiple request but would rather make one request.

How can I achieve plotting on different layers:
1. Change the protocol attributes to read from local ARRAY and do a while loop or 2. Change my FeatureCollection structure

This below works but all features are plotted on the same layer:
markers = new OpenLayers.Layer.Vector(thisLayer, {
            preFeatureInsert: preFeatureInsert,
            strategies: [
                new OpenLayers.Strategy.Fixed(),
                new OpenLayers.Strategy.Cluster({
                    distance: 20
                })
            ],
            protocol: new OpenLayers.Protocol.HTTP({
                url: protocolUrl,
                format: protocolFormat
            }),
            projection: MapProj,
            formatOptions: {
                extractStyles: true,
                extractAttributes: true
            },
            styleMap: new OpenLayers.StyleMap({
                "default": style,
                "select": style
            }),
            catID: 0
        });

with this collection:
{
    "type": "FeatureCollection",
    "features": [{
        "type": "feature",
        "properties": {
            "id": "7943",
            "name": "Bobs Burger",
            "category": "57",
            "color": "9875c3",
            "timestamp": "1400149988"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [-76.437099, 39.041711]
        }
    }, {
        "type": "feature",
        "properties": {
            "id": "7944",
            "name": "Hot Diggity",
            "category": "54",
            "color": "b33838",
            "timestamp": "1400150184"
        },
        "geometry": {
            "type": "Point",
            "coordinates": [-76.436586, 39.041696]
        }
    }]
}



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Plot-features-onto-multiple-layers-from-one-HTTP-request-tp5144030.html
Sent from the OpenLayers Dev mailing list archive at Nabble.com.
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
_______________________________________________
Dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/openlayers-dev
Reply | Threaded
Open this post in threaded view
|

Re: Plot features onto multiple layers from one HTTP request

khanh703
I can make a single Ajax requesting the two layers "Burgers" and "Hot Dogs" into a single JSON return like below.
{
    "type": "FeatureCollection",
    "collections": [
        {
            "name": "Burgers",
            "features": [
                {
                    "type": "feature",
                    "properties": {
                        "id": "7943",
                        "name": "Bobs Burger",
                        .....
                },
               {
                    "type": "feature",
                    "properties": {
                        "id": "7947",
                        "name": "Jons Burger",
                        .....
                }
            ]
        },
        {
            "name": "Hot Dogs",
            "features": [
                {
                    "type": "feature",
                    "properties": {
                        "id": "7913",
                        "name": "Doggies",
                        ...
                }
            ]
        }
    ]
}

My addMarkers function uses Protocol.HTTP to get the data like so:
protocol: new OpenLayers.Protocol.HTTP({
                url: protocolUrl
                format: protocolFormat
            })

Instead  "url: protocolUrl", is there an equivalent of "data: myData[i]

Does OpenLayers have the ability to read features from a local array? What I mean is, after I make the Ajax request, I store that collections array locally and do a while loop?