|
|
|
Aypes
|
Dear all,
I might open a topic in a wrong forum, because I do not know whether I should ask this question in Mapserver or OpenLayers forum. If I did, I feel sorry about that. I want to query the layer with using openlayers. However, I do not know how to 'call' the templates from mapfile to the html file.I have found topics about query using mapserver and openlayers, but I have still no idea how to code in html file. The query function is fine when using mapserver alone. In the mapfile, I have put metadata into web like this: WEB HEADER "/ms4w/Apache/htdocs/web_header.html" FOOTER "/ms4w/Apache/htdocs/web_footer.html" EMPTY "empty.html" Metadata "wms_title" "WMS" "wms_onlineresource" "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/Apache/htdocs/test.map&" "wms_srs" "EPSG:4269" "wms_feature_info_mime_type" "text/html" END template "/ms4w/Apache/htdocs/web.html" imagepath "/ms4w/Apache/htdocs/tmp/" imageurl "/tmp/" END PROJECTION "init=epsg:4269" END And in the layer, data from postgresql postgis (with attribute ID) was used with metadata: Name "Abc" metadata "wms_title" "Abc" "wms_srs" "EPSG:4269" End ..... I also have put header footer in layer and template in the class Class Name "abc" Template "/ms4w/Apache/htdocs/query.html" ...... END The code in html file: var layer = new OpenLayers.Layer.MapServer( "ABC WMS", "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/Apache/htdocs/test.map&", {layers: 'Abc'} ); I tried {layers: 'Abc', mode: 'query', params ='ID'} but it did not work. I found an example of query: http://www.co.sweet.wy.us/mapserver/map.html I want to query the layer by a click instead of dragging and a new window come out to display information. How can I make this in html file? Furthermore, I find many examples using new OpenLayers.Layer.WMS. But when I use it, it displays nothing. I can only use new OpenLayers.Layer.MapServer to display map. What is the problem? Thanks, Aypes |
||||||||||||||||
|
P Kishor
|
On Thu, Oct 29, 2009 at 1:13 AM, Aypes <[hidden email]> wrote:
> > Dear all, > > I might open a topic in a wrong forum, because I do not know whether I > should ask this question in Mapserver or OpenLayers forum. If I did, I feel > sorry about that. > > I want to query the layer with using openlayers. However, I do not know how > to 'call' the templates from mapfile to the html file.I have found topics > about query using mapserver and openlayers, but I have still no idea how to > code in html file. The query function is fine when using mapserver alone. > > In the mapfile, I have put metadata into web like this: > WEB > HEADER "/ms4w/Apache/htdocs/web_header.html" > FOOTER "/ms4w/Apache/htdocs/web_footer.html" > EMPTY "empty.html" > Metadata > "wms_title" "WMS" > "wms_onlineresource" > "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/Apache/htdocs/test.map&" > "wms_srs" "EPSG:4269" > "wms_feature_info_mime_type" "text/html" > END > template "/ms4w/Apache/htdocs/web.html" > imagepath "/ms4w/Apache/htdocs/tmp/" > imageurl "/tmp/" > END > PROJECTION > "init=epsg:4269" > END > > And in the layer, data from postgresql postgis (with attribute ID) was used > with metadata: > Name "Abc" > metadata > "wms_title" "Abc" > "wms_srs" "EPSG:4269" > End > ..... > > I also have put header footer in layer and template in the class > Class > Name "abc" > Template "/ms4w/Apache/htdocs/query.html" > ...... > END > > The code in html file: > var layer = new OpenLayers.Layer.MapServer( "ABC WMS", > > "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/Apache/htdocs/test.map&", > {layers: 'Abc'} ); > I tried {layers: 'Abc', mode: 'query', params ='ID'} but it did not work. > > I found an example of query: http://www.co.sweet.wy.us/mapserver/map.html > I want to query the layer by a click instead of dragging and a new window > come out to display information. > How can I make this in html file? > > Furthermore, I find many examples using new OpenLayers.Layer.WMS. But when I > use it, it displays nothing. I can only use new OpenLayers.Layer.MapServer > to display map. What is the problem? > Here is how I did it, and it worked for me (test for typing errors) Step 1: In the map file Step 1a: WEB WEB ,, # WMS server settings METADATA .. "wms_feature_info_mime_type" "text/html" END END # WEB Step 1b: LAYER to be queried LAYER NAME 'layer_name' .. METADATA .. 'wms_include_items' "FiEld_NaMe" # field name is possibly # case-sensitive in the case of # shape files END # METADATA DUMP true HEADER "/absolute/path/to/template_header.html" TEMPLATE "/absolute/path/to/template_body.html" FOOTER "/absolute/path/to/template_footer.html" END # LAYER Step 2: In your HTML templates Step 2a: in template_header.html <!-- MapServer Template --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/transitional.dtd"> <html> <head> <title>MapServer Template Sample</title> </head> Step 2b: in template_body.html <body> <b>FiEld_NaMe:</b> [FiEld_NaMe] </body> Step 2c: in template_footer.html </html> Step 3: In your HTML file with OpenLayers code map.addControl( new OpenLayers.Control.WMSGetFeatureInfo( function() { return { url: "/url/to/mapserv", maxFeatures: 1, title: 'Identify features by clicking', queryVisible: true, layers: [layer_name], vendorParams: { map: "/absolute/path/to/mapfile" }, eventListeners: { getfeatureinfo: function(event) { map.addPopup( new OpenLayers.Popup.FramedCloud( "chicken", map.getLonLatFromPixel(event.xy), null, event.text, null, true ), true ); // map.addPopup } // getfeatureinfo } // eventListeners } // return } ) ).activate(); -- Puneet Kishor http://www.punkish.org Carbon Model http://carbonmodel.org Charter Member, Open Source Geospatial Foundation http://www.osgeo.org Science Commons Fellow, http://sciencecommons.org/about/whoweare/kishor Nelson Institute, UW-Madison http://www.nelson.wisc.edu ----------------------------------------------------------------------- Assertions are politics; backing up assertions with evidence is science ======================================================================= Sent from Madison, WI, United States _______________________________________________ mapserver-users mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/mapserver-users |
||||||||||||||||
|
Aypes
|
P Kishor, Thank you for answering. But I have some problems. I want to know that in map file, [TEMPLATE "/absolute/path/to/template_body.html"] is ouside or inside the class of the layer? Secondly, for the part map.addPopup( new OpenLayers.Popup.FramedCloud( "chicken", map.getLonLatFromPixel(event.xy), null, event.text, null, true) I just do not understand the structure of it even though I have searched it on Internet. Should "chicken" change to the layer name, and where/what is event.txt? Thirdly there is some problem on activate(). I got an error of 'map.addControl(...)' is null or not an object. If I detele activate(), it works without the getfeatureinfo property. But I have no idea on how to activate it. And I am using OpenLayers.layer.Mapserver to render map, not OperLayers.layer.WMS. Does new OpenLayers.Control. WMSGetFeatureInfo still work? Thanks, Aypes |
||||
|
Aypes
|
I have solved the problem. There is the function code in my html:
map.events.register('click', map, function (e) { var url = "http://localhost/cgi-bin/mapserv.exe" + "?map=map/file/directory.map" + "&REQUEST=GetFeatureInfo" + "&VERSION=1.1.1" + "&EXCEPTIONS=application/vnd.ogc.se_xml" + "&BBOX=" + map.getExtent().toBBOX() + "&X=" + e.xy.x + "&Y=" + e.xy.y + "&INFO_FORMAT=text/html" + "&QUERY_LAYERS=querylayer" + "&LAYERS=querylayer" + "&FEATURE_COUNT=1" + "&SRS=EPSG:4269" + "&STYLES=" + "&WIDTH=" + map.size.w + "&HEIGHT=" + map.size.h; window.open(url, "getfeatureinfo", "location=0,status=0,scrollbars=1,width=600,height=400" ); But if I turn off the layer, I click on the map, a new window still come out. That is not the problem. The problem is the turned off layer can still be queried. I want that the turned off layer is not queryable. New window can still come out without any information. Please give me a hand. Thanks, Aypes |
||||||||||||||||
|
Arnd Wippermann
|
Hi,
Look for the visibility of your "querylayer" and decide what to do map.events.register('click', map, function (e) { var flag=map.getLayersBy("name", "querylayer")[0].visibility; if(flag) { var url = "http://localhost/cgi-bin/mapserv.exe" + "?map=map/file/directory.map" + "&REQUEST=GetFeatureInfo" + "&VERSION=1.1.1" + "&EXCEPTIONS=application/vnd.ogc.se_xml" + "&BBOX=" + map.getExtent().toBBOX() + "&X=" + e.xy.x + "&Y=" + e.xy.y + "&INFO_FORMAT=text/html" + "&QUERY_LAYERS=querylayer" + "&LAYERS=querylayer" + "&FEATURE_COUNT=1" + "&SRS=EPSG:4269" + "&STYLES=" + "&WIDTH=" + map.size.w + "&HEIGHT=" + map.size.h; window.open(url, "getfeatureinfo", "location=0,status=0,scrollbars=1,width=600,height=400"); } }); Regards, Arnd -----Ursprüngliche Nachricht----- Von: [hidden email] [mailto:[hidden email]] Im Auftrag von Aypes Gesendet: Dienstag, 3. November 2009 02:50 An: [hidden email] Betreff: Re: [mapserver-users] Query feature using openlayers and mapserver I have solved the problem. There is the function code in my html: map.events.register('click', map, function (e) { var url = "http://localhost/cgi-bin/mapserv.exe" + "?map=map/file/directory.map" + "&REQUEST=GetFeatureInfo" + "&VERSION=1.1.1" + "&EXCEPTIONS=application/vnd.ogc.se_xml" + "&BBOX=" + map.getExtent().toBBOX() + "&X=" + e.xy.x + "&Y=" + e.xy.y + "&INFO_FORMAT=text/html" + "&QUERY_LAYERS=querylayer" + "&LAYERS=querylayer" + "&FEATURE_COUNT=1" + "&SRS=EPSG:4269" + "&STYLES=" + "&WIDTH=" + map.size.w + "&HEIGHT=" + map.size.h; window.open(url, "getfeatureinfo", "location=0,status=0,scrollbars=1,width=600,height=400" ); But if I turn off the layer, I click on the map, a new window still come out. That is not the problem. The problem is the turned off layer can still be queried. I want that the turned off layer is not queryable. New window can still come out without any information. Please give me a hand. Thanks, Aypes -- View this message in context: http://n2.nabble.com/Query-feature-using-openlayers-and-mapserver-tp3910093p 3936077.html Sent from the Mapserver - User mailing list archive at Nabble.com. _______________________________________________ mapserver-users mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/mapserver-users _______________________________________________ mapserver-users mailing list [hidden email] http://lists.osgeo.org/mailman/listinfo/mapserver-users |
||||||||||||||||
|
Aypes
|
Arnd Wippermann, Thanks for your answer. I get your idea, but it does not work. It said "map.getLayersBy(...) is null or not an object. I want to ask in [map.getLayersBy("name", "querylayer")[0].visibility], what is the "name"? If I create a layer like that: var ABC_layer = new OpenLayers.Layer.MapServer( "ABC WMS", "http://localhost/cgi-bin/mapserv.exe?map=c:/ms4w/Apache/htdocs/map.map&", {layers: 'ABC'} ); The "name" is ABC WMS, ABC or ABC_layer? Actually I have written in this way: .....function (e) { if (ABC_layer.visibility == true) { var url..... It works but this part of codes only for one layer only. If there are many layers, the html file would be looked clumsy. Thanks, Aypes |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |