Updating the meaninglessly named sundials example.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9254 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -17,33 +17,47 @@
|
||||
var lon = 5;
|
||||
var lat = 40;
|
||||
var zoom = 5;
|
||||
var map, layer;
|
||||
var map, select;
|
||||
|
||||
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);
|
||||
map.addLayer(new OpenLayers.Layer.GML("KML", "kml/sundials.kml",
|
||||
{
|
||||
format: OpenLayers.Format.KML,
|
||||
formatOptions: {
|
||||
extractStyles: true,
|
||||
extractAttributes: true
|
||||
}
|
||||
}));
|
||||
selectControl = new OpenLayers.Control.SelectFeature(map.layers[1],
|
||||
{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect});
|
||||
|
||||
map.addControl(selectControl);
|
||||
selectControl.activate();
|
||||
|
||||
var wms = new OpenLayers.Layer.WMS(
|
||||
"OpenLayers WMS",
|
||||
"http://labs.metacarta.com/wms/vmap0",
|
||||
{layers: 'basic'}
|
||||
);
|
||||
|
||||
var sundials = new OpenLayers.Layer.Vector("KML", {
|
||||
projection: map.displayProjection,
|
||||
strategies: [new OpenLayers.Strategy.Fixed()],
|
||||
protocol: new OpenLayers.Protocol.HTTP({
|
||||
url: "kml/sundials.kml",
|
||||
format: new OpenLayers.Format.KML({
|
||||
extractStyles: true,
|
||||
extractAttributes: true
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
map.addLayers([wms, sundials]);
|
||||
|
||||
select = new OpenLayers.Control.SelectFeature(sundials);
|
||||
|
||||
sundials.events.on({
|
||||
"featureselected": onFeatureSelect,
|
||||
"featureunselected": onFeatureUnselect
|
||||
});
|
||||
|
||||
map.addControl(select);
|
||||
select.activate();
|
||||
map.zoomToExtent(new OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906));
|
||||
}
|
||||
function onPopupClose(evt) {
|
||||
selectControl.unselect(selectedFeature);
|
||||
select.unselectAll();
|
||||
}
|
||||
function onFeatureSelect(feature) {
|
||||
selectedFeature = feature;
|
||||
function onFeatureSelect(event) {
|
||||
var feature = event.feature;
|
||||
// Since KML is user-generated, do naive protection against
|
||||
// Javascript.
|
||||
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
|
||||
@@ -58,10 +72,13 @@
|
||||
feature.popup = popup;
|
||||
map.addPopup(popup);
|
||||
}
|
||||
function onFeatureUnselect(feature) {
|
||||
map.removePopup(feature.popup);
|
||||
feature.popup.destroy();
|
||||
feature.popup = null;
|
||||
function onFeatureUnselect(event) {
|
||||
var feature = event.feature;
|
||||
if(feature.popup) {
|
||||
map.removePopup(feature.popup);
|
||||
feature.popup.destroy();
|
||||
delete feature.popup;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
Reference in New Issue
Block a user