Over the past several days I've read as much as possible regarding the OpenLayers API (within a JavaScript/jQuery environment), yet I'm still having trouble in getting my head around what I believe to be basic features.

I can successfully place maps on my page, set bounds, etc, etc, but I'm having an incredibly hard time in the following:

My requriements are extremely simple, I want a 'file' (KML, JS, I don't know) of each country and it's borders so that I can simply (as an example) select a country from a dropdown list and OpenLayers highlight that country!

I did think it would be a simple task, have gone through all 220 examples of the OpenLayers website and can't see anything remotely close.

I've been here: http://thematicmapping.org/downloads/world_borders.php

Downloaded the WorldData which I thought would have the vector co-ordinates for the worlds countries borders, it looks to be a database file but haven't a clue what to do with this!

If someone can break down the basics, I'd be incredibly grateful and better still show a basic example of what I'm after, I should be able to learn from it.

Many thanks,


To Select and Highlight an feature in Openlayers

You can use the WKT format (convert your shapefiles to this format) (QGIS will do this if save the shapefile as csv) Converting Shapefiles to Text (ASCII) files?

enter image description here

    var highlightCtrl = new OpenLayers.Control.SelectFeature(vectors, {
        hover: true,
        highlightOnly: true,
        renderIntent: "temporary",
        eventListeners: {
            beforefeaturehighlighted: report,
            featurehighlighted: report,
            featureunhighlighted: report

    var selectCtrl = new OpenLayers.Control.SelectFeature(vectors,
        {clickout: true}




  • Again thanks, having merged the above with your help here, I've managed to successfully achieve a mock-up of the final product. Again many thanks for your help. – JasonMHirst Oct 10 '12 at 14:25

The link you refer to points to a zip file that contains a shapefile.


A shapefile is a group of files (SHP, DBF, SHX, PRJ, etc.) that stores geographic features (points, lines or polygons) and associated attribute data.

This shapefile needs to be stored somewhere on your computer so that OpenLayers can access it.

  • That helps a great deal, have managed to download a program called "QuantumGIS" which has exported the borders into (a large) TXT file with polygon data. – JasonMHirst Oct 10 '12 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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