Fossgis: common openlayers mistakes - Till Adams

Tags: fossgis, geo

He has scanned openlayers’ user mailinglist and extracted the top 5 problems/mistakes including the solutions. He gave a presentation two years ago about “openlayers, das Kartendingsbums fuer jede Webseite” and he’s surprised at the speed by which openlayers really became the map javascript thingy for every map website.

The most basic point with openlayers mistakes is discovering and debugging javascript errors. Infamous is internet explorer 6’s “some javascript error occured” which provides almost no debugging info. Nowadays it is better. Javascript is easier to debug. Basically: use firebug (or one of the alternatives for IE/chrome/safari).

Ok, on to the basic mistakes:

  • Cross-site scripting. Accessing WFS data from another server, for instance. It can violate javascript’s “same data origin” safety policy. A solution is to tell your webserver to proxy data from specific hosts via something provided by openlayers.

  • Showing own themes with google and so. Basically: reprojecting google’s maps into a different projection. That’s not possible. Your WMS data has to be requested using google’s projection. (The base layer is the boss).

  • Projections. Data showing up near the south pole. Or near the African coast. The problem: your coordinates don’t match your data’s projection. Using degrees (52 north, 5 east) doesn’t work when the projection is in meters… Use something like your_point.transform(map.displayProjection, map.projection) for instance.

  • Performance tips. Use yslow. It integrates into firebug and gives your page a grade. And it provides hints on improving your performance like “make fewer http requests” and “put your js at the end of the page”. A problem: we’re all using tiles to split up the map. But every tile means an http request. You can swamp your browser when your tiles are too small and the browser window is relatively big. For some sites, they’ve switched back to using single tiles. Also you can try and make your tiles bigger. And you can minimize your javascript data: throw out what you don’t need. And use tools to minimize the javascript by removing comments and so.

  • Pink tiles. (He didn’t have time for that anymore).

Along the Neckar river
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):