0

I'm kinda new to OpenLayers and I would like to ask whats the problem in my code. This is actually just from the examples I got from the internet but I seem can't make it work. All I want to do is to make POIs using Openlayers.layers.text.

map = new OpenLayers.Map("mapdiv");
map.addLayer(new OpenLayers.Layer.OSM());
var pois = new OpenLayers.Layer.Text( "My Points",
                { location:"./textfile.txt",
                  projection: map.displayProjection
                });
map.addLayer(pois);

and in my textfile is

lat lon title   description iconSize    iconOffset  icon
10  20  title   description 21,25   -10,-25 http://www.openlayers.org/dev/img/marker.png

I've been trying to figure out whats wrong with my codes all day but i cant make it work. Can anyone help me to figure out whats wrong with my code? only the map will be shown with no popup/marker..

3
  • i really want to make something like this link
    – jim5421
    Commented Dec 18, 2012 at 12:32
  • What do you mean by "can't make it work"? what is the bug/error you are facing?
    – Shai
    Commented Dec 18, 2012 at 12:49
  • Are you getting any errors? If so, can you include them in your question via the edit button.
    – Ren
    Commented Dec 18, 2012 at 12:49

1 Answer 1

0

Ensure that your textfile.txt file fit the following requirements:

  • The first row of the data file should be a header line with the column names of the data. Each column should be delimited by a tab space.
  • The last row of textfile.txt should be an empty string.
  • textfile.txt should be placed on the same host as original application.
  • OpenLayers.Layer.Text doesn't work if you try to run your application from file system. Use web server.

See my LIVE DEMO. Example of .txt file: enter image description here

1
  • I made it work now. Thank. Though I have done this a while back but nothing happened.
    – jim5421
    Commented Dec 19, 2012 at 5:29

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.