Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

did someone try highlight features using MapServer and OpenLayers? I tried to create map, where I display layer from MapServer by WMS using OpenLayers. It works, but I cannot highlight features to the vector layer. (Like in this example: http://openlayers.org/dev/examples/getfeatureinfo-control.html.) My data is from PostgreSQL database.

I don't know, where's problem. If in MapServer or in OpenLayers. Maybe some parametres are missing. When I click into the map, because of: "" infoControls.infoFormat = "text/html"; "", I can read attributes of the point (or line or polygon) except the geometry attribute (I can read ID, name, ..). Or because of: "" infoControls.infoFormat = "application/vnd.ogc.gml"; "", I can read some coordinates and all attributes. Anyway, when I want load coordinates to vector.addFeature(event.features), nothing happends and it writes undefined. It's complex problem, I have no idea if problem is in OpenLayers code, or MapServer code or someone else.

Could someone help me, please?

MapFile code:

MAP
  NAME "WMS Krovak Mapa"
  EXTENT -924416.812 -1207160 -411839 -943870
  UNITS meters
  SIZE 500 300
  IMAGETYPE png
  QUERYMAP
        STATUS ON  # the map is queryable by default
  END
  PROJECTION
    "init=epsg:102067"
  END  

  WEB
    TEMPLATE style/template.html
    IMAGEPATH "/var/www/tmp/"
    IMAGEURL "/tmp/"
    METADATA
       "wms_title"             "WMS Krovak Mapa"
       "wms_onlineresource"    "http://localhost/cgi-bin/mapserv?map=/var/www/work/my/pmapper_demo.map&"
       "wms_srs"               "EPSG:102067"
       "wms_encoding"          "utf-8"
       "wms_feature_info_mime_type"    "text/html"
       "wms_enable_request"    "GetMap GetFeatureInfo"
   END
  END 


   #== START OF LAYER SECTION ==#

   LAYER       ############################  LINIE ##
     NAME 'tlinie'  
     TYPE LINE
     CONNECTIONTYPE POSTGIS
     CONNECTION "host=localhost port=5432 dbname=*** user=postgres password=***"  
     DATA "the_geom from tlinie2 join atlinie on id_silnice=sid USING UNIQUE gid USING srid=102067"
     STATUS DEFAULT
     TOLERANCE 5
     TOLERANCEUNITS pixels
     TEMPLATE "style/blank.html"
     DUMP TRUE
     PROJECTION 
       "init=epsg:102067"
     END # Projection
     METADATA
         "wms_title"             "tlinie"
         "wms_onlineresource"    "http://localhost/cgi-bin/mapserv?"
         "wms_srs"               "EPSG:102067"
         "gml_geometries"        "THE_GEOM"
         "gml_[the_geom]_type"   "line"
         "WMS_INCLUDE_ITEMS"       'the_geom'
         "GML_INCLUDE_ITEMS"       'the_geom'
         "wms_encoding"          "utf-8"
         "wms_exceptions_format" "application/vnd.ogc.gml"
         "LAYER_ENCODING"        "UTF-8"
     END # Metadata
     CLASS
       name 'Dalnice'
       expression ([sid]=1 or [sid]=2)
       STYLE
        OUTLINECOLOR 0 0 0
        COLOR 255 0 0
        WIDTH 2
       END 
     END # Class
     CLASS
       name 'I. tridy'
       expression ([sid]=3)
       STYLE
        COLOR 255 153 0
        WIDTH 2
       END
     END
     CLASS
       name 'II. tridy'
       expression ([sid]=4 or [sid]=5)
       STYLE
        COLOR 255 204 153
        WIDTH 2
       END
     END
   END # Layer

  # + LAYER         ############### POINT ##
  # + LAYER         ############### POLYGON ##

END  #Map

And my OpenLayers's code:

     var vectors = new OpenLayers.Layer.Vector("Vector Layer", 
       {isBaseLayer: false}
     );

     var bounds = new OpenLayers.Bounds(-905000,-1230000,-400000,-900000);
     var options = {
            controls:[
                new OpenLayers.Control.LayerSwitcher(),
                new OpenLayers.Control.PanZoom(), 
                new OpenLayers.Control.MousePosition(),
                new OpenLayers.Control.OverviewMap(), //přehledová mapka
                new OpenLayers.Control.Navigation(), //posunutí mapy, zoom
                new OpenLayers.Control.NavToolbar(), // --- zvětšení podle nakresleného okna
                       ],
          maxExtent: bounds,
          projection: "epsg:102067",
          maxResolution: "auto",
          units: 'm',
          hover: true,//
          onSelect: serialize,//

            };


     var layer_sjtsk = new OpenLayers.Layer.WMS( 
            "MapServer WMS", 
            "http://localhost/cgi-bin/mapserv?map=/var/www/work/insert/mapfile_bp.map&SRS=EPSG:102067&",
            {layers:'tlinie,tbod,tpoly', transparent: true, format: 'image/gif'},
            {isBaseLayer: true}
            );

     var map = new OpenLayers.Map("map", options);
     map.addLayers([vectors, layer_sjtsk]);

     // modify feature reshape, drag, select 
     controls = {
          select: new OpenLayers.Control.SelectFeature(vectors, options), 
          drag: new OpenLayers.Control.DragFeature(vectors, options),
          point: new OpenLayers.Control.DrawFeature(vectors,
                      OpenLayers.Handler.Point),
          line: new OpenLayers.Control.DrawFeature(vectors,
                      OpenLayers.Handler.Path),
          polygon: new OpenLayers.Control.DrawFeature(vectors,
                      OpenLayers.Handler.Polygon),
          modify: new OpenLayers.Control.ModifyFeature(vectors)
     };

     for(var key in controls) {
          map.addControl(controls[key]);
     }

    document.getElementById('noneToggle').checked = true; // ?

     // souvisí s modify 
     controls.modify.mode = OpenLayers.Control.ModifyFeature.RESHAPE;
     controls.modify.createVertices = 1;

     function toggleControl(element) {
          for(key in controls) {
              var control = controls[key];
              if(element.value == key && element.checked) {
                  control.activate();
              } else {
                  control.deactivate();
              }
          }
     }

     // end modify

     map.zoomToExtent(bounds);

     infoControls = new OpenLayers.Control.WMSGetFeatureInfo({
              url: 'http://localhost/cgi-bin/mapserv?map=/var/www/work/insert/mapfile_bp.map&SRS=EPSG:102067&', 
              title: 'Identify features by clicking',
              queryVisible: true, 
              hover: false,
              eventListeners: {
                getfeatureinfo: function(event) {
                  vectors.destroyFeatures();
                  vectors.addFeatures(event.features);
                  vectors.drawFeature(event.features);
                  //vectors.redraw();
                document.getElementById('responseText').innerHTML = event.text;
                }
              } 
            });

     map.addControl(infoControls);

     infoControls.layers = null;

     function editel(element) {
       if (element.checked) { 
         infoControls.layers = null;
         infoControls.infoFormat = "application/vnd.ogc.gml";
         infoControls.activate(); 
         }
       else {
         infoControls.layers = null;
         infoControls.infoFormat = "text/html";
         infoControls.deactivate();
         }
     }              
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.