[OpenLayers-Users] KML and Popup window problem
Xin
xin at zenpow.com
Wed Mar 12 11:26:24 EDT 2008
Hi,
I have a KML layer which I want to be able to click and see a pop up. I am
following the following examples, but it's not working for me.
http://openlayers.org/dev/examples/select-feature.html
http://openlayers.org/dev/examples/select-feature-openpopup.html
My map is projected. The init code is:
var options = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326"),
units: "m",
maxResolution: 156543.0339,
maxExtent: new OpenLayers.Bounds(-20037508, -20037508,
20037508, 20037508.34),
restrictedExtent: new OpenLayers.Bounds(-102731.36592167988,-
3815736.451414842,3869548.1192908203,-1311047.9090148422)
};
map = new OpenLayers.Map('map', options);
My KML is therefore also projected. The code:
kmlLayer = new OpenLayers.Layer.GML("KML", kmlFeedUrl,
{
projection: new OpenLayers.Projection("EPSG:4326"),
format: OpenLayers.Format.KML,
formatOptions: {
extractStyles: true,
extractAttributes: true
}
});
map.addLayer(kmlLayer);
This is all working so far, and I'm pretty happy about it. Thanks goes out
to Chris and the community.
My KML consist of points.
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<Style id="marker">
<IconStyle>
<Icon>
<href>http://localhost:3000/openlayers/img/marker-green.png</href>
</Icon>
</IconStyle>
</Style>
<Placemark id="13856">
<name>place name</name>
<description>NULL::character varying</description>
<styleUrl>#marker</styleUrl>
<Point>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>23.29555556,-17.98611111</coordinates>
</Point>
</Placemark>
<Placemark id="13852">
<name>place name 2</name>
<description>NULL::character varying</description>
<styleUrl>#marker</styleUrl>
<Point>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>24.56638889,-17.54027778</coordinates>
</Point>
</Placemark>
</Document>
</kml>
I would like the user to be able to click on these points, and see a popup
window consisting of name and description. After this KML layer is added, I
add a select control as suggested from Vector file popup examples.
selectControl = new OpenLayers.Control.SelectFeature( kmlLayer,
{onSelect: onFeatureSelect, onUnselect:
onFeatureUnselect});
I also copied over onFeatureSelect and onFeatureUnselect.
When I click on a marker, nothing happens. Do I need to project
SelectFeature? Does SelectFeature work with Points from a KML file?
Sorry for the long post! Any help is much appreciated.
Xin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20080312/4f512cfd/attachment.html
More information about the Users
mailing list