1 <html xmlns="http://www.w3.org/1999/xhtml">
3 <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
4 <link rel="stylesheet" href="style.css" type="text/css" />
6 <style type="text/css">
10 border: 1px solid black;
12 .olPopup p { margin:0px; font-size: .9em;}
13 .olPopup h2 { font-size:1.2em; }
15 <script src="../lib/OpenLayers.js"></script>
16 <script type="text/javascript">
23 map = new OpenLayers.Map('map');
25 var wms = new OpenLayers.Layer.WMS(
27 "http://labs.metacarta.com/wms/vmap0",
31 var sundials = new OpenLayers.Layer.Vector("KML", {
32 projection: map.displayProjection,
33 strategies: [new OpenLayers.Strategy.Fixed()],
34 protocol: new OpenLayers.Protocol.HTTP({
35 url: "kml/sundials.kml",
36 format: new OpenLayers.Format.KML({
38 extractAttributes: true
43 map.addLayers([wms, sundials]);
45 select = new OpenLayers.Control.SelectFeature(sundials);
48 "featureselected": onFeatureSelect,
49 "featureunselected": onFeatureUnselect
52 map.addControl(select);
54 map.zoomToExtent(new OpenLayers.Bounds(68.774414,11.381836,123.662109,34.628906));
56 function onPopupClose(evt) {
59 function onFeatureSelect(event) {
60 var feature = event.feature;
61 // Since KML is user-generated, do naive protection against
63 var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;
64 if (content.search("<script") != -1) {
65 content = "Content contained Javascript! Escaped content below.<br />" + content.replace(/</g, "<");
67 popup = new OpenLayers.Popup.FramedCloud("chicken",
68 feature.geometry.getBounds().getCenterLonLat(),
69 new OpenLayers.Size(100,100),
71 null, true, onPopupClose);
72 feature.popup = popup;
75 function onFeatureUnselect(event) {
76 var feature = event.feature;
78 map.removePopup(feature.popup);
79 feature.popup.destroy();
85 <body onload="init()">
86 <h1 id="title">KML Layer Example</h1>
91 Demonstrates loading and displaying a KML file on top of a basemap.
94 <div id="map" class="smallmap"></div>