Skip to content
February 15, 2012 / Gagan

Tile Feature Strategy in OpenLayers

No doubt there is a huge requirement for client side vector rendering capabilities. The reason being the user interaction with features can be enhanced that can not be thought in case of tile images.

One critical point for heavy traffic sites is caching of the data. Caching can be considered at server side (http cache) and browser cache to reduce the load on servers. So for caching the vector data requests, we  need to request the data from server in predefined extent or tile wise.

I have implemented the client side handling of the tiled vector data request with OpenLayers. OpenLayers has different strategies for requesting the data from server like Fixed, BBOX. Similar way I created a strategy to request the features tile wise and to handle the response, named as Tile Feature Strategy TFS. Here is the working example of TFS with OpenLayers

You can check the TFS class source code that is inherited from OpenLayers Strategy class. I have used GeoJSON format for features. There is slight modification in protocol as well as, check here Protocal_TFS.

Well in this example features returned are not the real features ( as I dont have the data). These features I create for each tile on ad hoc basis but each time in a  tile features are same.  This is achieved with Knuth algo, check the php code for simulated tile feature service here. The response for given tile is GeoJSON feature collection. Well for your actual data, you need to implement a tile feature service at your own at server end. Can take help of TileStache to generate tile wise GeoJSON.

This approach is not new many efforts have been done earlier also. I see ticket for tiled WFS in  OpenLayers. There is microsoft research project for TiledVectors. And there is very nice implementation by Polymaps for Vector Tiles.  Here is another open source arcstache for ArcGIS Server.



Leave a Comment
  1. Homme Zwaagstra / Jul 25 2012 4:34 pm

    This looks really interesting! I’ve been searching for some OpenLayers code that replicates the excellent vector tiling in Polymaps, as I also feel there are many strong use cases for this functionality. Kothic JS ( implements a similar vector tile format (, as does GIS Cloud (

    Have you submitted an OpenLayers pull request for this in GitHub?

  2. ol_user / Aug 8 2012 1:59 pm

    Great work! Thanks a lot!

    • Gagan / Aug 12 2012 10:53 am

      Thanks, Hope its useful to you.

  3. Marc / Aug 20 2012 6:22 pm

    When using a base layer that has a projection other than 4326 it fails to calculate the tile coordinates. At least it failed with the 900913. Not sure it is the best approach, but at line 159 I changed it to take the resolution from the layer, not the map. Unlike the map, this layer is set to be 4326, so the resolution given by getResolution is the proper one and now it works fine with the OSM base layer.

    this.resolution = this.layer.getResolution();

    Instead of:

    this.resolution =;

    • Gagan / Sep 11 2012 11:03 am

      Hi Mark,

      Thanks for the bug fixing and posting the same here.


  4. Peter / Aug 12 2014 3:45 pm

    Gagan, Thanks for this. Can you remember why you decided to move readTile from strategy to protocol, and to bypass entirely? It causes problems should the user want to change the format of the GET request.

    • Gagan / Aug 13 2014 7:33 am

      Hi Peter,
      I have created a protocol ‘Protocol_TFS.js’ modifying the HTTP.js protocol. And the standard is that format should be specified in protocol.
      You can change the format while initiating the object from Protocol_TFS class. For any further clarification please feel free to contact me.

      Recently I have introduced in it zoom level caching as per the requirement i.e you can specify the zoom levels for that tile features would not be requested from server. While rendering of features would be done from the previous zoom level tiles. Please check it here (( This is not documented but you can make out from example ‘.examples/strategy-tfs.html’


  5. Gagan / Aug 12 2014 5:44 pm

    Hi Peter,
    Good you are using it, certainly I’ll check this in few hours and let you know. Some changes recently I have done, but not related to protocol. If you are interested in modifying the code please fork it (

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: