Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

All,

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,

share|improve this question
add comment

2 Answers

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) Shapefiles to Text

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}
    );

    map.addControl(highlightCtrl);
    map.addControl(selectCtrl);

    highlightCtrl.activate();
    selectCtrl.activate();

http://openlayers.org/dev/examples/highlight-feature.html

share|improve this answer
    
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
add comment

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

http://thematicmapping.org/downloads/world_borders.php

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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