Как ограничить поля или получить конкретное поле в запросе GetFeatureInfo? - PullRequest
1 голос
/ 28 марта 2012

На самом деле я использую этот код для GetFeatureInfo с примером всплывающего окна, теперь я хочу ограничить поля во всплывающем окне.

<html>
  <head>
    <title>GetFeatureInfo Popup</title>
    <script src="ol/OpenLayers.js"></script>
    <link rel="stylesheet" href="ol/theme/default/style.css" type="text/css" />
    <link rel="stylesheet" href="ol/examples/style.css" type="text/css" />
    <script>
    OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";
    /*Same as identifier*/  
    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:8080/geoserver/wms", 
            {'layers': 'topp:tasmania_state_boundaries', transparent: true, format: 'image/gif'},
            {isBaseLayer: true}
        );

        var roads = new OpenLayers.Layer.WMS("Roads",
            "http://localhost:8080/geoserver/wms", 
            {'layers': 'topp:tasmania_roads', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );

        var cities = new OpenLayers.Layer.WMS("Cities",
            "http://localhost:8080/geoserver/wms", 
            {'layers': 'topp:tasmania_cities', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );

        var water = new OpenLayers.Layer.WMS("Bodies of Water",
            "http://localhost:8080/geoserver/wms", 
            {'layers': 'topp:tasmania_water_bodies', transparent: true, format: 'image/gif'},
            {isBaseLayer: false}
        );



        map.addLayers([political, roads, cities, water]); 

        info = new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost:8080/geoserver/wms', 
            title: 'Identify features by clicking',
            queryVisible: true,
            eventListeners: {
                getfeatureinfo: function(event) {
                    map.addPopup(new OpenLayers.Popup.FramedCloud(
                        "chicken",      
                        //document.getElementById('get').innerHTML = xmlResponse.attribute.state;
                        map.getLonLatFromPixel(event.xy),
                        null,
                        event.text,
                        null,
                        true
                    ));
                    xmlResponse = new OpenLayers.Format.XML().read(event.text); 
                    document.getElementById('h').innerHTML = xmlResponse.attribute.STATE; 
                }
            }
        });
        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>
      <form>
      <input type="lable" id="h">
      </form>

    <div id="docs"></div>
  </body>
</html>

Теперь я хочу только определенное поле или ограничить поля во всплывающем окне. Пожалуйста, дайте мне знать, я новичок в этом.

Ответы [ 2 ]

6 голосов
/ 09 апреля 2012

Если вы используете GeoServer для создания своей WMS, вы можете создавать собственные шаблоны GetFeatureInfo, следуя этому руководству: http://docs.geoserver.org/latest/en/user/tutorials/GetFeatureInfo/index.html

0 голосов
/ 17 июля 2018

Вы должны использовать функцию propertyName параметров getGetFeatureInfoUrl. Например, если вам нужны функции name и id, вы должны сделать что-то вроде этого:

var url = source.getGetFeatureInfoUrl(
           evt.coordinate, viewResolution, view.getProjection(),
           {'INFO_FORMAT': 'application/json','propertyName':'name,id'});
...