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

I show over lon/lat my position with a icon(PIN) on the map....and I want to add a little popup to the marker with some GeoInfo like City and Country....but if I add a normal popup (new OpenLayers.Popup) it only appears on the top left corner of the page, but I want it at my position or next to my icon(Pin) on the map.... can anyone help or tell me what is wrong with my code....

//ADD LAYER MARKERS
var markers = new OpenLayers.Layer.Markers( "Markers" );
    map.addLayer(markers);
    markers.addMarker(new OpenLayers.Marker(lonLat,icon));

//POPUP
var popup = new OpenLayers.Popup("test1",
                             markers.lonLat,
                             null,
                            "GeoInfo",
                             true);
                  map.addPopup(popup);

like I said it only appears in the TOP LEFT Corner of the map.....and if I change markers.lonLat to new Openlayers.LonLat(5,40) no popup is shown....

and if I change new.Openlayers.Popup to new.Openlayers.Popup.AnchoredBubble oder new.Openlayers.Popup.Anchored no PopUp appers as well :(

Any ideas?!?!

asked 26 Oct '10, 08:28

BabyPowder's gravatar image

BabyPowder
15111
accept rate: 0%

edited 26 Oct '10, 11:37

Andy%20Allan's gravatar image

Andy Allan
12.5k23128153


I know that this is fairly old, but I thought I may as well answer it because it comes up a lot in general OpenLayers marker/popup searches quite a lot.

Create a method to add the marker (I use addMarkers) and then within that, create a variable reference to each marker, var marker = new OpenLayers.Marker(ll, etc), then call the .lonlat property of that variable, rather than the layer itself. That way you know you're getting the appropriate projection and all. You might also want to make the popup a child of the marker, so that you can reference each marker's popup easily in the future.

A nice example of popups can be seen here: http://openlayers.org/dev/examples/popupMatrix.html

Check out the source code. It provides a lot of examples, and approaches it a bit differently, although more effectively I feel.

permanent link

answered 20 Apr '11, 06:38

mricci's gravatar image

mricci
3112
accept rate: 0%

This is a help system for the OpenStreetMap project, but your question is quite a technical one regarding OpenLayers, which is an independent software project. If you don't get any other answers here, you would be better looking at the OpenLayers site for support queries.

permanent link

answered 26 Oct '10, 11:39

Andy%20Allan's gravatar image

Andy Allan
12.5k23128153
accept rate: 28%

-1

This can be closed.......

somehow I did nothing different in my eyes but today exactly what I wanted to do worked for me.......

this thread can be closed

permanent link

answered 29 Oct '10, 13:42

BabyPowder's gravatar image

BabyPowder
15111
accept rate: 0%

edited 29 Oct '10, 13:47

Andy%20Allan's gravatar image

Andy Allan
12.5k23128153

-2

I am using the OpenStreetMap so I thought that I can ask my question here......

permanent link

answered 26 Oct '10, 12:33

BabyPowder's gravatar image

BabyPowder
15111
accept rate: 0%

You can ask your question here, it's just more likely to get a helpful answer if you ask the people of OpenLayers.

However note that your code never makes a connection between the individual marker and the popup. You're somehow trying to couple the markers layer and the popup instead of the marker and the popup. See the OpenLayers examples page for working code.

(26 Oct '10, 12:55) Augustus Kling

Example 11 of http://php-baustelle.de/openlayers/step-by-step/ might also provide some guidance. However you should rework the variable scope.

(27 Oct '10, 07:08) Augustus Kling
Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×122
×98
×54
×23

question asked: 26 Oct '10, 08:28

question was seen: 35,465 times

last updated: 20 Apr '11, 06:38

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