Documentation/Dev/TextLayerToGmlLayer

Many OL-applications make use of OpenLayers.Layer.Text which parses a TSV-file (tabulator separated values) and displays markers on the given coordinates. When clicking on one of the markers a popup opens and displays the content of the name and description column of that file. Things will work with only two lines:

pois = new OpenLayers.Layer.Text( "My points", { location:"./pois.txt", projection: map.displayProjection});
map.addLayer(pois);

But there are scenarios where it's not desired to open a popup within the map. In this case one can make use of OpenLayers.Layer.GML. The above code is just replaced by:

pois = new OpenLayers.Layer.GML("My points", "./pois.txt", {format: OpenLayers.Format.Text, projection: map.displayProjection});
map.addLayer(pois);

In contrast to Textlayer, Gmllayer is very dependent on a clean pois.txt (name and ending are of no relevance). It's necessary to define the Icon (which must also be existent), the iconSize and iconOffset. (Textlayer defaults to the standard OL-Marker when none is specified)

Since no popup will open when klicking on such a marker it's necessary to introduce another control to catch the mouse click (event). This is done via OpenLayers.Control. SelectFeature, which supports various events. In the following example a simple click (onSelect) calls a customised function (onFeatureSelect). Functions for different events can be defined simultaneously, separated by commas.

selectControl = new OpenLayers.Control.SelectFeature(pois,{onSelect: onFeatureSelect});

map.addControl(selectControl);
selectControl.activate();

The control is then added to the map and activated.

The defined function could look like this:

function onFeatureSelect(feature) {
            selectedFeature = feature;
            parent.detail.location.href = "./detail.php?id=" + feature.attributes.title;
        }

The value of the text-file's title-column is available as feature.attributes.title and passed as GET-parameter to a PHP-script, which is loaded in a separate frame.