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.

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, kindly help me out.

function init()
{   
 /*
Create a new Map with Basic controls which are passed as
arguments
*/
var map= new OpenLayers.Map('map_element',
{
    controls:[
    new OpenLayers.Control.Navigation(),
    new OpenLayers.Control.PanZoomBar(),
    new OpenLayers.Control.LayerSwitcher(),
    //new OpenLayers.Control.Attribution()
    ],
    numZoomLevels:19,
    units:'m'
}
);

 // 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});
map.addLayer(pois);
map.addLayers(
[
osm_map_layer,
//google_map_layer,
//vectors,
markers,
pois
]
);  
//

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

iconOffset
48.9459301 9.6075669 Title One Description

one
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

share|improve this question
1  
Open the debug console on your browser (F12 on Chrome/Chromium & IE) reload your page and see if there is any errors. Also, check your addLayer(s); you create your txt layer, add in the next function and then appear to include it again in the array when you add all your other layers. –  RomaH Nov 25 '12 at 8:37
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.