[OpenLayers-Users] WFS Popup Attributes undefined

Jian Zhou zhoujian_ab at 163.com
Fri Oct 9 05:41:07 EDT 2009


I have the same questiong like you. So your OpenLayers application is running
and all layers are displayed fine? 
What's the output after clicking on an object?Can you see the popup fine?
Regards

Cress B. wrote:
> 
> I'm fairly new to OpenLayers and have been trying to get the attributes
> from my WFS mapfile to display in a popup window.  I would like the user
> to be able to click on a polygon and have the attributes display as a list
> in a popup.   I've started with the select-feature-openpoup.html example
> and have inserted by own WFS mapfile.  I can load my polygon shapefile as
> a WFS service and see them load as orange polygons - although they load
> REAL slow.  When I activate the popup option and click on a polygon the
> popup window comes up and the polygon is highlighted in blue.  The popup
> is returning the area of the polygon as part of the
> 'feature.geometry.getArea()' parameter; but the other attributes in my
> shapefile are "undefined" in the popup.  I've hacked away for several
> days, reading almost all the posts dealing with popup, WFS, attributes...
> and still can't figure out what I'm doing wrong.  So I'm not sure if my
> WFS mapfile is wonky or if my script in OpenLayers is missing something.
> 
> Below is my Mapfile:
> 
> 
> MAP
>   NAME           'TAXLOT'
>   STATUS         ON
>   IMAGETYPE      PNG24
>   TRANSPARENT    ON
>   EXTENT         4239905 896089 4247235 902911
>   SIZE           1000 800
>   IMAGECOLOR     152 252 210
>   UNITS			 Feet
>   SHAPEPATH      "/ms4w/apps/tutorial/data"
>   FONTSET        "/ms4w/apps/tutorial/fonts/fonts.list"
>   SYMBOLSET      "/ms4w/apps/tutorial/symbols/symbols35.sym"
>    WEB
>     IMAGEPATH "/ms4w/tmp/ms_tmp/"
>     IMAGEURL  "/ms_tmp/"
> 	   METADATA
> 	   "wfs_title"           "TAXLOT"
> 	   "wfs_onlineresource"  "http://localhost/cgi_bin/mapserv.exe?&" 
> #map=homeinfo_wfs.map&"
> 	   "wms_srs"             "EPSG:32127"
>        END #end metadata
> 	END #end web
>     PROJECTION
>     "init=epsg:32127"
>     END #end projection
>    
>   LAYER # Taxlots polygon layer begins here
>     NAME         "taxlots"
> 	CONNECTIONTYPE WFS
> 	METADATA
> 	  "wfs_typename"       "taxlots"
> 	  "wfs_request_method" "GET"
> 	  "gml_featureid"      "FID"
> 	  "gml_include_items"  "all"
> 	  "queryable" "true"
>     END
>     DATA         'HomeTaxlots'
>     TYPE         POLYGON
>     STATUS       ON
> 	  PROJECTION
> 	   "init=epsg:32127"
> 	  END
> 	DUMP         TRUE
> 	TEMPLATE     /ms4w/apps/template/foo.html
>     CLASS
>       NAME       "lots"
>       STYLE
>         COLOR    155 155 255
> 		OUTLINECOLOR 0 15 27
>       END
> 	  TEMPLATE "ttt_query.html"
>     END
>   END # Taxlots polygon layer ends here
> END # All map files must come to an end just as all other things must come
> to...
> 
> And this is the OpenLayers script piece for the popup:
> 
>     <script type="text/javascript">
>         var map, drawControls, selectControl, selectedFeature;
>         var lon = 4243545;
>         var lat = 900150;
>         var zoom = 0;
>         var map, test_wfs, layer;
> 		
> 		
>         function onPopupClose(evt) {
>             selectControl.unselect(selectedFeature);
>         }
>         function onFeatureSelect(feature) {
>             selectedFeature = feature;
> 					var maplot = selectedFeature.attributes['MAPLOT'];
> 					var lot = selectedFeature.attributes['LOT'];
> 					var acres = selectedFeature.attributes['ACRES'];
> 					var taxcode = selectedFeature.attributes['TAXCODE'];
>             popup = new OpenLayers.Popup.FramedCloud("info", 
>                                     
> feature.geometry.getBounds().getCenterLonLat(),
>                                      null,
>                                      "<div style='font-size:.8em'>TaxLot:
> " + maplot +"<br />Lot: " + lot+"<br />Acres: " +acres +"<br/>Taxcode: "
> +taxcode+"<br/>Area: " + feature.geometry.getArea()+"</div>",
>                                      null, true,onPopupClose);
>             feature.popup = popup;
>             map.addPopup(popup);
>         }
> 		
>         function onFeatureUnselect(feature) {
>             map.removePopup(feature.popup);
>             feature.popup.destroy();
>             feature.popup = null;
>         }    
>         function init(){
> 		
> 		var options = { 
>                 projection: new OpenLayers.Projection("EPSG:32127"), 
>                 displayProjection: new
> OpenLayers.Projection("epsg:32127"), 
>                 units: "feet", 
>                 maxResolution: "auto",
> 				allOverlays: true,
>                 maxExtent: new OpenLayers.Bounds(4239905, 895089, 
>                                                  4247235, 906500) 
>             }; 
> 			
>             map = new OpenLayers.Map("map",options
> 					);
>             var polygonLayer = new OpenLayers.Layer.WFS( "TAXLOT", 
>                
> "http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apache/htdocs/homeinfo_wfs_good.map&", 
> 				{typename: 'taxlots'}); 
> 
>             //var polygonLayer = new OpenLayers.Layer.Vector("Polygon
> Layer");
> 
>             map.addLayers([polygonLayer]);
> 			
>             map.addControl(new OpenLayers.Control.LayerSwitcher());
>             map.addControl(new OpenLayers.Control.MousePosition());
>             
>             selectControl = new
> OpenLayers.Control.SelectFeature(polygonLayer,
>                 {onSelect: onFeatureSelect, onUnselect:
> onFeatureUnselect});
>             drawControls = {
>                 polygon: new OpenLayers.Control.DrawFeature(polygonLayer,
>                             OpenLayers.Handler.Polygon),
>                 select: selectControl
>             };
>             
>             for(var key in drawControls) {
>                 map.addControl(drawControls[key]);
>             }
> 
>             
>             map.setCenter(new OpenLayers.LonLat(0, 0), 3);
> 
>         }
> 
>         function toggleControl(element) {
>             for(key in drawControls) {
>                 var control = drawControls[key];
>                 if(element.value == key && element.checked) {
>                     control.activate();
>                 } else {
>                     control.deactivate();
>                 }
>             }
>         }
> 
:handshake::handshake::handshake:
-- 
View this message in context: http://n2.nabble.com/WFS-Popup-Attributes-undefined-tp3778098p3793430.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list