I am trying to load markers from a text file using OpenLayers text layer, but no marker is shown, text file and icons are in same directory. However I am able to show markers using marker layer. My code is here and text file is also attached.

function init()
Create a new Map with Basic controls which are passed as
var map= new OpenLayers.Map('map_element',
    new OpenLayers.Control.Navigation(),
    new OpenLayers.Control.PanZoomBar(),
    new OpenLayers.Control.LayerSwitcher(),
    //new OpenLayers.Control.Attribution()

 // default lan/lat projection in which points will be provided
 var epsg4326 = new OpenLayers.Projection("EPSG:4326");
Create Basic Layers to show on map
// openstreetmap layer
var osm_map_layer = new OpenLayers.Layer.OSM (
'Open Street Maps'
// google map layer
var google_map_layer = new OpenLayers.Layer.Google(
'Google Street Maps',
{sphericalMercator: true,
maxExtent: new OpenLayers.Bounds(
-20037508.34,-20037508.34, 20037508.34, 20037508.34)}

vector layer to draw custom shapes on map
var vectors = new OpenLayers.Layer.Vector("Vectors");
markers layer will be used to insert markers on map
var markers = new OpenLayers.Layer.Markers( "Markers");
layers are added to map
pois = new OpenLayers.Layer.Text( "My points", { location:"./pois.txt", projection:     map.displayProjection});

var lonlat = new OpenLayers.LonLat(48.9459301,9.6075669);
lonlat.transform(epsg4326, map.getProjectionObject());
map.setCenter(lonlat, 15);
markers.addMarker(new OpenLayers.Marker(lonlat));

} // last closing bracket

and text file

lat lon title description icon iconSize

48.9459301 9.6075669 Title One Description

Second line.

(click again to close)

Ol_icon_blue_example.png 24,24 0,-24
48.9899851 9.5382032 Title Two Description

two. Ol_icon_red_example.png 16,16 -8,-8


1 Answer 1


I had this problem like you! You should write your data in each rows with spacing between columns by Tabs.. and also, it is important that fill the last row by spaces as strings and tabs.. it should be work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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