0

I use openlayers 4 and gml layer is file type, but when i add gml layer to map using ol4, i have a ploblem. Gml is polygon but it appear as some point in map. Can not anybody help me?

Below is my code.

  var map = new ol.Map({
    layers: [
      new ol.layer.Tile({
        source: new ol.source.OSM()
      })
    ],
    target: 'map',
    view: new ol.View({
      center: [13884240,4543150],
      zoom: 2
    })
  });

  const vectorSource = new ol.source.Vector({
      url: 'deac.gml',
      format: new ol.format.WFS({
        srsName: 'EPSG:3857'
      })
  });
  var vector = new ol.layer.Vector({
    source: vectorSource
  });

        map.addLayer(vector);

  vectorSource.on('change', e => {
    if (vectorSource.getState() === 'ready') {
      map.getView().fit(vectorSource.getExtent());
    }
  })

Below is my gml file (sample).

<?xml version='1.0' encoding='utf-8' ?>
<ogcwfs:FeatureCollection xmlns="http://www.erdas.com/wfs" xmlns:sf="http://www.erdas.com/wfs" xmlns:gml="http://www.opengis.net/gml" xmlns:iwfs="http://www.erdas.com/wfs" xmlns:ogcwfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wfs http://192.168.0.1:80/erdas-apollo/vector/DEAC_JIJUKDO?REQUEST=DescribeFeatureType&amp;REQUEST=DescribeAllFeatureType&amp;SERVICE=WFS">
  <gml:boundedBy>
    <gml:Envelope srsName="EPSG:3857">
      <gml:lowerCorner>1.3877003968399527E7 4544227.497314737</gml:lowerCorner>
      <gml:upperCorner>1.3890435607534818E7 4558178.171019333</gml:upperCorner>
    </gml:Envelope>
  </gml:boundedBy>
<gml:featureMember>
  <iwfs:DEAC_JIJUKDO gml:id="DEAC_JIJUKDO.2">
    <iwfs:ID>16.0</iwfs:ID>
    <iwfs:PNU>2872034021200160062</iwfs:PNU>
    <iwfs:JIBUN>산16-62 임</iwfs:JIBUN>
    <iwfs:BCHK>1</iwfs:BCHK>
    <iwfs:OFFICE>옹진군</iwfs:OFFICE>
    <iwfs:EMD>대청면</iwfs:EMD>
    <iwfs:RI>대청리</iwfs:RI>
    <iwfs:JIMOK>05-임야</iwfs:JIMOK>
    <iwfs:AREA>1650</iwfs:AREA>
    <iwfs:OWN_GB>1-개인</iwfs:OWN_GB>
    <iwfs:GEOMETRY>
      <gml:Surface srsName="EPSG:3857">
        <gml:patches>
          <gml:PolygonPatch>
            <gml:exterior>
              <gml:LinearRing srsName="EPSG:3857">
                <gml:pos>1.3882784404422123E7 4556539.67241085</gml:pos>
                <gml:pos>1.3882775033688568E7 4556506.334812806</gml:pos>
                <gml:pos>1.3882701762750646E7 4556525.641706498</gml:pos>
                <gml:pos>1.3882705950053368E7 4556545.40452471</gml:pos>
                <gml:pos>1.388270932403736E7 4556559.13161291</gml:pos>
                <gml:pos>1.3882784404422123E7 4556539.67241085</gml:pos>
              </gml:LinearRing>
            </gml:exterior>
          </gml:PolygonPatch>
        </gml:patches>
      </gml:Surface>
    </iwfs:GEOMETRY>
  </iwfs:DEAC_JIJUKDO>
</gml:featureMember>
<gml:featureMember>
  <iwfs:DEAC_JIJUKDO gml:id="DEAC_JIJUKDO.3">
    <iwfs:ID>22.0</iwfs:ID>
    <iwfs:PNU>2872034021200160063</iwfs:PNU>
    <iwfs:JIBUN>산16-63 임</iwfs:JIBUN>
    <iwfs:BCHK>1</iwfs:BCHK>
    <iwfs:OFFICE>옹진군</iwfs:OFFICE>
    <iwfs:EMD>대청면</iwfs:EMD>
    <iwfs:RI>대청리</iwfs:RI>
    <iwfs:JIMOK>05-임야</iwfs:JIMOK>
    <iwfs:AREA>1650</iwfs:AREA>
    <iwfs:OWN_GB>1-개인</iwfs:OWN_GB>
    <iwfs:GEOMETRY>
      <gml:Surface srsName="EPSG:3857">
        <gml:patches>
          <gml:PolygonPatch>
            <gml:exterior>
              <gml:LinearRing srsName="EPSG:3857">
                <gml:pos>1.3882775033688568E7 4556506.334812806</gml:pos>
                <gml:pos>1.3882765437292634E7 4556472.196941427</gml:pos>
                <gml:pos>1.3882694395941742E7 4556490.870527174</gml:pos>
                <gml:pos>1.3882701762750646E7 4556525.641706498</gml:pos>
                <gml:pos>1.3882775033688568E7 4556506.334812806</gml:pos>
              </gml:LinearRing>
            </gml:exterior>
          </gml:PolygonPatch>
        </gml:patches>
      </gml:Surface>
    </iwfs:GEOMETRY>
  </iwfs:DEAC_JIJUKDO>
</gml:featureMember>
</ogcwfs:FeatureCollection>
  • Linear rings usually contain a single gml:posList element. gml:pos is normally used in point geometry and OpenLayers seems unable to correctly parse the polygon – Mike Feb 20 at 22:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.