NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hi, I want to read some POIs from text file, so I looked at Openlayers example how to do it and its great. But now I need to add new POI manually (when user clicks on the map). It can be done with map.addMarker and it works great, but this marker is different from one I get from text file.

Marker from text file has a popup when I click on it, with description. But I cant find any way how to add new marker with description to map. So how can I do this?

I load POIs like this:

markers = new OpenLayers.Layer.Text( "My Points",
                    { location:"poi.txt",
                      projection: map.displayProjection

Content of poi.txt:

lat lon title   description icon    iconSize    iconOffset
48.9459301  9.6075669   Title One   Description one<br>Second line.<br><br>(click again to close)   Ol/img/marker-green.png 24,24   0,-24
48.9899851  9.5382032   Title Two   Description two.    Ol/img/marker-green.png 16,16   -8,-8

And I add new marker after click like this:

var size = new OpenLayers.Size(21,25);
var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
var icon = new OpenLayers.Icon('',size,offset);
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(lon,lat),icon));

asked 08 Feb '12, 15:06

Pirozek's gravatar image

accept rate: 0%

closed 20 Dec '12, 12:30

Frederik%20Ramm's gravatar image

Frederik Ramm ♦

The question has been closed for the following reason "This is not an OpenLayers help site and your question is not about anything OSM-specific." by Frederik Ramm 20 Dec '12, 12:30

This is not an OpenLayers help system and especially not a coding site. You will probably get more help from an OpenLayers forum or OpenLayers mailing list.

permanent link

answered 08 Feb '12, 16:23

ChrisH's gravatar image

accept rate: 15%

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 08 Feb '12, 15:06

question was seen: 6,596 times

last updated: 20 Dec '12, 12:30

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum