Updating the sundials spherical mercator example a bit.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@9101 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2009-03-19 23:34:56 +00:00
parent 567d32f35f
commit 7e35022dff
+48 -28
View File
@@ -19,7 +19,7 @@
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(){
var options = { var options = {
@@ -40,42 +40,62 @@
attribution: '<a href="http://www.openstreetmap.org/">OpenStreetMap</a>' attribution: '<a href="http://www.openstreetmap.org/">OpenStreetMap</a>'
} }
); );
map.addLayer(mapnik); var gmap = new OpenLayers.Layer.Google("Google", {sphericalMercator:true});
map.addLayer(new OpenLayers.Layer.Google("Google",{sphericalMercator:true})); var sundials = new OpenLayers.Layer.Vector("KML", {
map.addLayer(new OpenLayers.Layer.GML("KML", "kml/sundials.kml",
{
format: OpenLayers.Format.KML,
projection: map.displayProjection, projection: map.displayProjection,
formatOptions: { strategies: [new OpenLayers.Strategy.Fixed()],
extractStyles: true, protocol: new OpenLayers.Protocol.HTTP({
extractAttributes: true url: "kml/sundials.kml",
} format: new OpenLayers.Format.KML({
})); extractStyles: true,
selectControl = new OpenLayers.Control.SelectFeature(map.layers[2], extractAttributes: true
{onSelect: onFeatureSelect, onUnselect: onFeatureUnselect}); })
})
});
map.addLayers([mapnik, gmap, sundials]);
select = new OpenLayers.Control.SelectFeature(sundials);
sundials.events.on({
"featureselected": onFeatureSelect,
"featureunselected": onFeatureUnselect
});
map.addControl(selectControl); map.addControl(select);
selectControl.activate(); select.activate();
map.zoomToExtent(new OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906).transform(map.displayProjection, map.projection));
map.addControl(new OpenLayers.Control.LayerSwitcher()); map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToExtent(
new OpenLayers.Bounds(
68.774414, 11.381836, 123.662109, 34.628906
).transform(map.displayProjection, map.projection)
);
} }
function onPopupClose(evt) { function onPopupClose(evt) {
selectControl.unselect(selectedFeature); select.unselectAll();
} }
function onFeatureSelect(feature) { function onFeatureSelect(event) {
selectedFeature = feature; var feature = event.feature;
popup = new OpenLayers.Popup.FramedCloud("chicken", var selectedFeature = feature;
feature.geometry.getBounds().getCenterLonLat(), var popup = new OpenLayers.Popup.FramedCloud("chicken",
new OpenLayers.Size(100,100), feature.geometry.getBounds().getCenterLonLat(),
"<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description, new OpenLayers.Size(100,100),
null, true, onPopupClose); "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description,
null, true, onPopupClose
);
feature.popup = popup; feature.popup = popup;
map.addPopup(popup); map.addPopup(popup);
} }
function onFeatureUnselect(feature) { function onFeatureUnselect(event) {
map.removePopup(feature.popup); console.log(event);
feature.popup.destroy(); var feature = event.feature;
feature.popup = null; if(feature.popup) {
map.removePopup(feature.popup);
feature.popup.destroy();
delete feature.popup;
}
} }
function osm_getTileURL(bounds) { function osm_getTileURL(bounds) {
var res = this.map.getResolution(); var res = this.map.getResolution();