[OpenLayers-Users] the code of getfeatureinfo-popup and kml layer example(sundial)

Alexandre Dube adube at mapgears.com
Fri Oct 9 08:17:25 EDT 2009


Hi Zhoujian,

Please, reply to the list. More people may help you that way.

First step : do you use firebug ? It's a great way to find errors on 
your page. See if your getfeatureinfo requests are sent. What's the 
response. etc.

Regards,

Alexandre

zhoujian_ab wrote:
> Hi:
> I am following the example of getfeatureinfo-popup to write down the 
> code. And I want to use geoservers example to get the feature in my 
> local computer like the example when click the object I can see its 
> feature in a popup window. However, I can't. I don't know why. Please 
> help me . Thanks a lot.
> <html>
> <head>
> <title>GetFeatureInfo Popup</title>
> <script src="openlayers/OpenLayers.js"></script>
> <link rel="stylesheet" href="source/style1.css" type="text/css" />
> <link rel="stylesheet" href="source/style.css" type="text/css" />
> <script>
> OpenLayers.ProxyHost = "proxy.cgi?url=";
> var map, info;
> function load() {
> map = new OpenLayers.Map({
> div: "map",
> maxExtent: new OpenLayers.Bounds(143.834,-43.648,148.479,-39.573)
> });
> var political = new OpenLayers.Layer.WMS("State Boundaries",
> "http://localhost:8081/geoserver/wms",
> {'layers': 'topp:tasmania_state_boundaries', transparent: true, 
> format: 'image/gif'},
> {isBaseLayer: true}
> );
> var water = new OpenLayers.Layer.WMS("Bodies of Water",
> "http://localhost:8081/geoserver/wms",
> {'layers': 'topp:tasmania_water_bodies', transparent: true, format: 
> 'image/gif'},
> {isBaseLayer: false}
> );
> var highlight = new OpenLayers.Layer.Vector("Highlighted Features", {
> displayInLayerSwitcher: false,
> isBaseLayer: false
> });
> map.addLayers([political,water, highlight]);
> info = new OpenLayers.Control.WMSGetFeatureInfo({
> url: 'http://localhost:8081/geoserver/wms',
> 'layers': 'topp:tasmania_water_bodies',
> queryVisible: true,
> eventListeners: {
> getfeatureinfo: function(event) {
> map.addPopup(new OpenLayers.Popup.FramedCloud(
> "chicken",
> map.getLonLatFromPixel(event.xy),
> null,
> event.text,
> null,
> true
> ));
> }
> }
> });
> map.addControl(info);
> info.activate();
> map.addControl(new OpenLayers.Control.LayerSwitcher());
> map.zoomToMaxExtent();
> }
> </script>
> </head>
> <body onload="load()">
> <h1 id="title">Feature Info in Popup</h1>
> <div id="tags"></div>
> <p id="shortdesc">
> Demonstrates the WMSGetFeatureInfo control for fetching information
> about a position from WMS (via GetFeatureInfo request). Results
> are displayed in a popup.
> </p>
> <div id="map" class="smallmap"></div>
> <div id="docs"></div>
> </body>
> </html>
> And I also write the kml examples like sundial on openlayers web. I 
> can,t achieve the same result. The following is the code, I don,t know 
> what,s wrong. Thanks.
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <link rel="stylesheet" href="source/style1.css" type="text/css" />
> <link rel="stylesheet" href="source/style.css" type="text/css" />
> <style type="text/css">
> #map {
> width: 100%;
> height: 80%;
> border: 1px solid black;
> }
> .olPopup p { margin:0px; font-size: .9em;}
> .olPopup h2 { font-size:1.2em; }
> </style>
> <script src="OpenLayers/OpenLayers.js"></script>
> <script type="text/javascript">
> var lon = -100;
> var lat = 60;
> var zoom = 5;
> var map, select;
> function init(){
> map = new OpenLayers.Map('map');
> var wms = new OpenLayers.Layer.WMS(
> "OpenLayers WMS",
> "http://localhost:8081/geoserver/wms",
> {layers: 'topp:states'}
> );
> var sundials = new OpenLayers.Layer.Vector("KML",{
> projection: map.displayProjection,
> strategies: [new OpenLayers.Strategy.Fixed()],
> protocol: new OpenLayers.Protocol.HTTP({
> url: "states.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(-127.61950064999999, 
> 23.7351786,-64.08177035, 50.5925234000000056));
> }
> function onPopupClose(evt) {
> select.unselectAll();
> }
> 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;
> if (content.search("<script") != -1) {
> content = "Content contained Javascript! Escaped content below.<br/>" 
> + content.replace(/</g, "&lt;");
> }
> popup = new OpenLayers.Popup.FramedCloud("chicken",
> feature.geometry.getBounds().getCenterLonLat(),
> new OpenLayers.Size(100,100),
> content,
> null, true, onPopupClose);
> feature.popup = popup;
> map.addPopup(popup);
> }
> function onFeatureUnselect(event) {
> var feature = event.feature;
> if(feature.popup) {
> map.removePopup(feature.popup);
> feature.popup.destroy();
> delete feature.popup;
> }
> }
> </script>
> </head>
> <body onload="init()">
> <h1 id="title">KML Layer Example</h1>
> <div id="tags"></div>
> <p id="shortdesc">
> Demonstrates loading and displaying a KML file on top of a basemap.
> </p>
> <div id="map" class="smallmap"></div>
> <div id="docs"></div>
> </body>
> </html>
> 2009-10-09
> ------------------------------------------------------------------------
> zhoujian_ab
> ------------------------------------------------------------------------
> *发件人:* Alexandre Dube
> *发送时间:* 2009-10-08 22:35:58
> *收件人:* zhoujian_ab
> *抄送:* Users
> *主题:* Re: [OpenLayers-Users] HELP:some problem
> Hi Zhoujian,
> Could you show you code or (even better) an small online example of what
> you're doing ? It would be easier to help.
> Regards,
> Alexandre
> zhoujian_ab wrote:
> > 2009-10-08
> > ------------------------------------------------------------------------
> > zhoujian_ab
> > ------------------------------------------------------------------------
> > *发件人:* zhoujian_ab
> > *发送时间:* 2009-10-08 21:07:28
> > *收件人:* users
> > *抄送:*
> > *主题:* HELP:some problem
> > hello:
> > I am making a digital map with Openlayers+geoserver+postgis. But It is
> > my first time to use openlayers, I have some problems. First: how to
> > add a kml file with openlayers in geoserver? I have read the
> > examples(kml layer example on the openlayers.org) lots of times, and I
> > practise many times but I can't get the same results like the picture.
> > Second problem: how to use the popup functiong? can you give me a code
> > to use geoserver's examples. I don't understand the examples on
> > openlayers.org. I have compared my code with the example, but I also
> > can't achieve the same results like the picture.
> > I am Chinese, and my MSN is *zhoujianab at hotmail.com*. 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.
> > 2009-10-08
> > ------------------------------------------------------------------------
> > zhoujian_ab
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Users mailing list
> > Users at openlayers.org
> > http://openlayers.org/mailman/listinfo/users
> >
> -- 
> Alexandre Dubé
> Mapgears
> www.mapgears.com
> __________ Information from ESET Smart Security, version of virus 
> signature database 4490 (20091008) __________
> The message was checked by ESET Smart Security.
> http://www.eset.com


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list