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:
+40
-23
@@ -17,33 +17,47 @@
|
|||||||
var lon = 5;
|
var lon = 5;
|
||||||
var lat = 40;
|
var lat = 40;
|
||||||
var zoom = 5;
|
var zoom = 5;
|
||||||
var map, layer;
|
var map, select;
|
||||||
|
|
||||||
function init(){
|
function init(){
|
||||||
map = new OpenLayers.Map('map');
|
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);
|
var wms = new OpenLayers.Layer.WMS(
|
||||||
selectControl.activate();
|
"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));
|
map.zoomToExtent(new OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906));
|
||||||
}
|
}
|
||||||
function onPopupClose(evt) {
|
function onPopupClose(evt) {
|
||||||
selectControl.unselect(selectedFeature);
|
select.unselectAll();
|
||||||
}
|
}
|
||||||
function onFeatureSelect(feature) {
|
function onFeatureSelect(event) {
|
||||||
selectedFeature = feature;
|
var feature = event.feature;
|
||||||
// Since KML is user-generated, do naive protection against
|
// Since KML is user-generated, do naive protection against
|
||||||
// Javascript.
|
// Javascript.
|
||||||
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
|
var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
|
||||||
@@ -58,10 +72,13 @@
|
|||||||
feature.popup = popup;
|
feature.popup = popup;
|
||||||
map.addPopup(popup);
|
map.addPopup(popup);
|
||||||
}
|
}
|
||||||
function onFeatureUnselect(feature) {
|
function onFeatureUnselect(event) {
|
||||||
map.removePopup(feature.popup);
|
var feature = event.feature;
|
||||||
feature.popup.destroy();
|
if(feature.popup) {
|
||||||
feature.popup = null;
|
map.removePopup(feature.popup);
|
||||||
|
feature.popup.destroy();
|
||||||
|
delete feature.popup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user