Ways to Optimization OpenLayers
TODO add more to this page than what is below
WMS
buffer
- This is an option that allows the client to specify the amount of tiles that exist outside the visible area of the map (the map div). What this means to the client is, that if the user is anticipated to pan the map (left,right,up,down) then the image has been pre-loaded and the pan operation will be much smoother. The trade off in this situation is that if they are not panning around, then this is a waste of their bandwidth. For broadband users this is not a problem, and is also dependent on the image size in bytes that is being sent to the client.
- Optimize this to suit the navigation behaviour of your clients, and their bandwidth.
- Default is 2
- Example where a buffer of 0 (no buffer) is set
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms-c/Basic.py", {layers: 'basic'},{'buffer': 0} );
<insert image>
multiple URLs
- Since we are all here to get the best we can from what we've got here is a 'possible' optimization you should consider.
- BACKGROUND: Browsers have grown up in the world of dialup and NOTE many of them still run over dialup! Browsers limit the number of parallel request for resources per domain. In non-tech-terms... this means the browser will download two images at a time from http://domain.com, and will not request the third image on the page until one has finished. This is great for a dialup user because it limits flooding of their bandwidth... but it restricts broadband users who are perfectly capable of downloading MANY resources at once.
- In OpenLayers case, the browser naturally limits the map to load... two map image tiles at a time, per domain, you can even see the images load sequentially. There is away to get around this... but remember.. this was put in place ensure the quality of service for dialup users... so make sure you know what is most important to you, it is not for everyone. If it is for you, then here's how... If you are hosting your own map service you should host your map service on several domains. example http://map1.you.com http://map2.you.com http://mapX.you.com. As a consumer of maps you can use all of these domains with the browser still limiting to two map image tiles at a time (per domain) but since you have more domains, you have more tiles being requested in parallel. Providing an array of url's to the OpenLayers Layer is all you need to do as a consumer. See the example below.
- Browsers will only make several connections at a time, so if the URL is modified from....
var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", "http://labs.metacarta.com/wms-c/Basic.py", {layers: 'basic'} ); - to...
var urlArray = ["http://labs.metacarta.com/wms-c/Basic.py", "http://monitor.metacarta.com/wms-c/Basic.py"]; var wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", urlArray, {layers: 'basic'} );
