[OpenLayers-Users] using Request.GET vs. Layer with strategy, protocol, format

Scott Chapman scott at mischko.com
Fri Mar 2 14:18:23 EST 2012


Here's my current code.  "A" works. "B" doesn't.
Is there something else I need to add to make the features actually show up?

//A:
       var vector_layer = new OpenLayers.Layer.Vector("Stores");
       map.addLayer(vector_layer);

       OpenLayers.Request.GET({
              url: "/kiosks_status_geoJSON/",
              headers: {'Accept':'application/json'},
              success: function (req)
                       {
                       var g = new OpenLayers.Format.GeoJSON();
                       var feature_collection = g.read(req.responseText);
                       //console.log(feature_collection);
                       vector_layer.destroyFeatures();
                       vector_layer.addFeatures(feature_collection);
                       }
          });
//vs:

//B:
       var vector_layer = new OpenLayers.Layer.Vector("Stores", {
         strategies: [new OpenLayers.Strategy.Cluster(), new
OpenLayers.Strategy.Fixed()],
           protocol: new OpenLayers.Protocol.HTTP({
                     url: "/kiosks_status_geoJSON/",
                 headers: {'Accept':'application/json'},
                  format: new OpenLayers.Format.GeoJSON()
           })
       });
       map.addLayer(vector_layer);



On Thu, Mar 1, 2012 at 11:47 AM, Scott Chapman <scott at mischko.com> wrote:
> Cool! That fetched the XHR request.  Nothing showed up on the map!  >sigh< :)
>
>
> On Wed, Feb 29, 2012 at 9:36 PM, Eric Lemoine
> <eric.lemoine at camptocamp.com> wrote:
>>
>>
>> On Thursday, March 1, 2012, Scott Chapman wrote:
>>>
>>> The commented out code here works fine.  It kicks off an XHR request
>>> to my server and fetches back points of interest and plots them.
>>>
>>> The uncommented versions here don't work.  The XHR is never kicked off.
>>>
>>> I thought these would be equivalent.  Can someone please tell me what
>>> I'm missing?
>>>
>>>
>>>       //var vector_layer = new OpenLayers.Layer.Vector("Stores");
>>>       var vector_layer = new OpenLayers.Layer.Vector("Stores", {
>>>         strategies: [new OpenLayers.Strategy.Cluster()],
>>
>>
>>
>> The Cluster strategy won't fetch data for you. It is a data manipulation
>> strategy, not a data fetching strategy. Add a Fixed strategy to the
>> strategies array and it should work.
>>


More information about the Users mailing list