<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18812"><LINK rel=stylesheet
href="BLOCKQUOTE{margin-Top: 0px; margin-Bottom: 0px; margin-Left: 2em}"></HEAD>
<BODY style="MARGIN: 10px; FONT-FAMILY: verdana; FONT-SIZE: 10pt">
<DIV><FONT size=3>Hi:</FONT></DIV>
<DIV><FONT size=2><FONT size=3><FONT color=#000080> I also write the
kml examples like </FONT><FONT color=#ff0000>sundial </FONT><FONT
color=#000000>on openlayers web. I can,t achieve the same result to use
geoserver's 'topp: states'. The following is the code, I don,t know what,s
wrong. Thanks.</FONT></FONT>
<DIV> </DIV>
<DIV><FONT color=#000080>
<DIV><html xmlns="http://www.w3.org/1999/xhtml"></DIV>
<DIV> <head></DIV>
<DIV> <link rel="stylesheet" href="source/style1.css" type="text/css" /></DIV>
<DIV> <link rel="stylesheet" href="source/style.css" type="text/css" /></DIV>
<DIV></DIV>
<DIV> <style type="text/css"></DIV>
<DIV> #map {</DIV>
<DIV> width: 100%;</DIV>
<DIV> height: 80%;</DIV>
<DIV> border: 1px solid black;</DIV>
<DIV> }</DIV>
<DIV> .olPopup p { margin:0px; font-size: .9em;}</DIV>
<DIV> .olPopup h2 { font-size:1.2em; }</DIV>
<DIV> </style></DIV>
<DIV> <script src="OpenLayers/OpenLayers.js"></script></DIV>
<DIV> <script type="text/javascript"></DIV>
<DIV> var lon = -100;</DIV>
<DIV> var lat = 60;</DIV>
<DIV> var zoom = 5;</DIV>
<DIV> var map, select;</DIV>
<DIV></DIV>
<DIV> function init(){</DIV>
<DIV> map = new OpenLayers.Map('map');</DIV>
<DIV></DIV>
<DIV> var wms = new OpenLayers.Layer.WMS(</DIV>
<DIV> "OpenLayers WMS",</DIV>
<DIV> "http://localhost:8081/geoserver/wms",</DIV>
<DIV> {layers: 'topp:states'}</DIV>
<DIV> );</DIV>
<DIV> </DIV>
<DIV> var sundials = new OpenLayers.Layer.Vector("KML",{</DIV>
<DIV> projection: map.displayProjection,</DIV>
<DIV> strategies: [new OpenLayers.Strategy.Fixed()],</DIV>
<DIV> protocol: new OpenLayers.Protocol.HTTP({</DIV>
<DIV> url: "states.kml",</DIV>
<DIV> format: new OpenLayers.Format.KML({</DIV>
<DIV> extractStyles: true,</DIV>
<DIV> extractAttributes: true</DIV>
<DIV> })</DIV>
<DIV> })</DIV>
<DIV> });</DIV>
<DIV> </DIV>
<DIV> map.addLayers([wms, sundials]);</DIV>
<DIV> </DIV>
<DIV> select = new OpenLayers.Control.SelectFeature(sundials);</DIV>
<DIV> </DIV>
<DIV> sundials.events.on({</DIV>
<DIV> "featureselected": onFeatureSelect,</DIV>
<DIV> "featureunselected": onFeatureUnselect</DIV>
<DIV> });</DIV>
<DIV></DIV>
<DIV> map.addControl(select);</DIV>
<DIV> select.activate(); </DIV>
<DIV> map.zoomToExtent(new OpenLayers.Bounds(-127.61950064999999, 23.7351786,-64.08177035, 50.5925234000000056));</DIV>
<DIV> }</DIV>
<DIV> function onPopupClose(evt) {</DIV>
<DIV> select.unselectAll();</DIV>
<DIV> }</DIV>
<DIV> function onFeatureSelect(event) {</DIV>
<DIV> var feature = event.feature;</DIV>
<DIV> // Since KML is user-generated, do naive protection against</DIV>
<DIV> // Javascript.</DIV>
<DIV> var content = "<h2>"+feature.attributes.name + "</h2>" + feature.attributes.description;</DIV>
<DIV> if (content.search("<script") != -1) {</DIV>
<DIV> content = "Content contained Javascript! Escaped content below.<br/>" + content.replace(/</g, "&lt;");</DIV>
<DIV> }</DIV>
<DIV> popup = new OpenLayers.Popup.FramedCloud("chicken", </DIV>
<DIV> feature.geometry.getBounds().getCenterLonLat(),</DIV>
<DIV> new OpenLayers.Size(100,100),</DIV>
<DIV> content,</DIV>
<DIV> null, true, onPopupClose);</DIV>
<DIV> feature.popup = popup;</DIV>
<DIV> map.addPopup(popup);</DIV>
<DIV> }</DIV>
<DIV> function onFeatureUnselect(event) {</DIV>
<DIV> var feature = event.feature;</DIV>
<DIV> if(feature.popup) {</DIV>
<DIV> map.removePopup(feature.popup);</DIV>
<DIV> feature.popup.destroy();</DIV>
<DIV> delete feature.popup;</DIV>
<DIV> }</DIV>
<DIV> }</DIV>
<DIV> </script></DIV>
<DIV> </head></DIV>
<DIV> <body onload="init()"></DIV>
<DIV> <h1 id="title">KML Layer Example</h1></DIV>
<DIV></DIV>
<DIV> <div id="tags"></div></DIV>
<DIV></DIV>
<DIV> <p id="shortdesc"></DIV>
<DIV> Demonstrates loading and displaying a KML file on top of a basemap.</DIV>
<DIV> </p></DIV>
<DIV></DIV>
<DIV> <div id="map" class="smallmap"></div></DIV>
<DIV></DIV>
<DIV> <div id="docs"></div></DIV>
<DIV> </body></DIV>
<DIV></html></DIV>
<DIV> </DIV>
<DIV><FONT color=#000000 size=3> I am making a digital map with
Openlayers+geoserver+postgis. But It is my first time to use openlayers, I need
some guides. I am Chinese, and my MSN is
<STRONG>zhoujianab@hotmail.com</STRONG>. Thanks for your viewing, I need
your help. If you can, please give me a way to contact, just like MSN,
ICQ or QQ and so on. thank you. I am looking forward your
reply.</FONT> </DIV>
<DIV> </DIV></FONT></DIV></FONT></DIV>
<DIV align=left><FONT color=#c0c0c0 size=2>2009-10-09 </FONT></DIV><FONT size=2>
<HR style="WIDTH: 122px; HEIGHT: 2px" align=left SIZE=2>
<DIV><FONT color=#c0c0c0 size=2><SPAN>zhoujian_ab</SPAN>
</FONT></DIV></FONT></BODY></HTML>