3

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 requirements 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!

Can you break down the basics and show a basic example of what I'm after?

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
JasonMHirst
  • 193
  • 2
  • 7

2 Answers2

3

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

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

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

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

Mapperz
  • 49,701
  • 9
  • 73
  • 132
  • 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
2

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.

Rayner
  • 3,721
  • 1
  • 23
  • 30
  • 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