Using OpenLayers with Bing maps, I'm trying to load JSON data from a service URL and assign an array of clustering strategies to the resulting layer. There are plenty of examples of using cluster strategies with OpenLayers.Format.GeoJSON loaded via OpenLayers.Protocol.HTTP, but my data is Plain Ol' JSON, not GeoJSON (and I have no control over the format of it).

So using this code, the points load on the map correctly. But I get an error: "Uncaught TypeError: Cannot call method 'read' of null". When I open up the OpenLayers source code to the error-causing line, it's this:


and indeed, protocol is null.

So my question is: How to use OpenLayers cluster strategies without using a Protocol?

Here's the code I'm using:

map = new OpenLayers.Map("project-map");
osm = new OpenLayers.Layer.Bing({ name: 'street', type: 'Road', key : bingApiKey});
var cp = new OpenLayers.LonLat(0,20).transform(fromProj, toProj);

var pointLayer = new OpenLayers.Layer.Vector("Markers",{
            strategies: [new OpenLayers.Strategy.Fixed(), 
            new OpenLayers.Strategy.Cluster({distance: 25})]

    url: "ServiceHandler.json", 
    success: function(response) {
      var jsonReader = new OpenLayers.Format.JSON();
      var sparkle = jsonReader.read(response.responseText);
        $.each(sparkle, function(i,f){
          var point = 
             new OpenLayers.Geometry.Point(f.Long, f.Lat).transform(fromProj, toProj);
          var pointFeature = new OpenLayers.Feature.Vector(point, null, 
          externalGraphic: "http://localhost:8081/Icons/175.png",
          pointRadius: 8
            pointFeature.attributes = f;


1 Answer 1


You get error message by reason of using Fixed strategy. Remove this item from strategies array:

strategies: [new OpenLayers.Strategy.Cluster({distance: 25})]

It is not neccesary use Fixed strategy for manually added features.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.