[OpenLayers-Users] example for point vector needed
Tim Michelsen
timmichelsen at gmx-topmail.de
Wed Apr 22 17:08:01 EDT 2009
Hello,
thanks a lot for the answer.
> http://www.openlayers.org/dev/examples/sundials.html
>
> has everything you are requesting above.
Thanks for pointing to this file.
I tried to adapt the kml-layer.html (from examples) to use a marker
instead of a kml file. Please see below.
Why does the marker not show a popup on click?
Do you have an idea?
>> My markers shall use lat/lon variables taken from a database (not like
>> the text file example).
>>
>
> If you take them from a database, you have to format them in some way
> before transmitting to the client. Easiest options include GeoJSON and
> the text file you mentioned. Why don't you like that one?
I want to display a search result.
Using a text or KML file would mean that I would always have to write a
new file to disk when the search gets modified.
I do not yet know GeoJSON. I have to check how to create placemark-like
icons.
Thanks in advance and kind regards,
Timmie
#####
<script type="text/javascript">
var lon = 5;
var lat = 40;
var zoom = 5;
var map, layer;
function init(){
map = new OpenLayers.Map('map');
layer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", {layers:
'basic'} );
map.addLayer(layer);
var sundials = new OpenLayers.Layer.Markers("Project Sites");
map.addLayers(sundials);
var point = new
OpenLayers.LonLat(-112.292238941097,36.09520916122063);
var marker = new OpenLayers.Marker(point);
sundials.addMarker(marker);
/*
var sundials = new OpenLayers.Layer.GML("KML",
"kml/point.kml",
{
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: true,
extractAttributes: true,
maxDepth: 2
}
});
*/
map.addLayer(sundials)
select = new OpenLayers.Control.SelectFeature(sundials);
sundials.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(select);
select.activate();
map.zoomToExtent(new
OpenLayers.Bounds(-112.306698,36.017792,-112.03204,36.18087));
}
function onPopupClose(evt) {
select.unselectAll();
}
function onFeatureSelect(event) {
var feature = event.feature;
// Since KML is user-generated, do naive protection against
// Javascript.
var content = "<h2>TEST</h2>" + "some description";
popup = new OpenLayers.Popup.FramedCloud("chicken",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(100,100),
content,
null, true, onPopupClose);
feature.popup = popup;
map.addPopup(popup);
}
function onFeatureUnselect(event) {
var feature = event.feature;
if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
}
</script>
More information about the Users
mailing list