You are not logged in.
- Topics: Active | Unanswered
Announcement
Please create new topics on the new site at community.openstreetmap.org. We expect the migration of data will take a few weeks, you can follow its progress here.***
Pages: 1
#1 2010-11-02 10:47:24
- wyo
- Member

- From: Thalwil
- Registered: 2010-08-04
- Posts: 667
- Website
OpenLayers: Popup message on map click
I'd like to popup a message when a user clicks anywhere on the map. Unfortunately any sample code I found depends on either a marker or a polygon etc. Does anybody have code which just shows how to use the popup control with a simple single click? So far I've successful used sample "click.html" yet instead of a alert I'd like to popup a message box.
Wyo
Offline
#2 2010-11-02 13:34:45
- !i!
- Member

- Registered: 2009-11-28
- Posts: 3,313
- Website
Re: OpenLayers: Popup message on map click
Have a look at www.bestofosm.org (JS without "minimized" Filename). It shows you how to add a so called 'feature' that is a represantation on the vector layer. I guess this is what you want?
privater Account von KVLA-HRO-Mei
Offline
#3 2010-11-02 20:00:49
- wyo
- Member

- From: Thalwil
- Registered: 2010-08-04
- Posts: 667
- Website
Re: OpenLayers: Popup message on map click
I guess this is what you want?
Not quite. Your sample depends on certain features outlined on the map, you can only click a feature. Mine allows to click anywhere on the map (http://www.orpatec.ch/osm/tools/main.php) yet then I have no feature I can link the popup with. I tried
trigger: function(evt) {
var lonlat = map.getLonLatFromViewPortPx (evt.xy).transform (projMercator, projLonLat);
alert ("You clicked near " + lonlat.lat + " N, " + lonlat.lon + " E");
feature = evt.feature;
popup = new OpenLayers.Popup.FramedCloud ("info", lonlat, null,
"<h2>"+ "Test" + "</h2>", null, true, onPopupClose);
feature.popup = popup;
popup.feature = feature;
map.addPopup (popup);
}
I guess the "feature = evt.feature;" is wrong but I don't know how to fix it.
Wyo
Offline
Pages: 1