0

I try to load my gml file with this code but it doesn't work. Did I forgot something ?

import Map from 'ol/Map'
import Layer_Tile from 'ol/layer/Tile'
import source_OSM from 'ol/source/OSM'
import View from 'ol/View'
import VectorS from 'ol/source/Vector'
import VectorL from 'ol/layer/Vector'
import WFS from 'ol/format/WFS'
import GML from 'ol/format/GML32'
import proj4 from 'proj4';
import {get as getProjection} from 'ol/proj';
import {register} from 'ol/proj/proj4'


proj4.defs('EPSG:3947', '+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 ' +
    '+x_0=400000 +y_0=-100000 +ellps=airy ' +
    '+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 ' +
    '+units=m +no_defs');

register(proj4);    

var proj3947 = getProjection('EPSG:3947');

proj3947.setExtent([-4194304, -4194304, 4194304, 4194304]);

var map = new Map({
  layers: [
    new Layer_Tile({
      source: new source_OSM()
    })
  ],
  target: 'map',
  view: new View({
    projection: 'EPSG:3947',
    center: [0, 0],
    zoom: 2
  })
});

const vectorSource = new VectorS({
    url: 'test.gml',
    format: new WFS({
      gmlFormat: new GML({
        srsName: 'EPSG:3947' 
      })
    }), 
});
var vector = new VectorL({
  source: vectorSource
});
map.addLayer(vector);
vectorSource.on('change', e => {
  if (vectorSource.getState() === 'ready') {
    map.getView().fit(vectorSource.getExtent());
  }
})

My GML file :

<?xml version="1.0" encoding="UTF-8"?>
<pcrs:PlanCorpsRueSimplifie xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gss="http://www.isotc211.org/2005/gss" xmlns:pcrs="http://cnig.gouv.fr/pcrs" xmlns:gsr="http://www.isotc211.org/2005/gsr" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:pcrs-i="http://cnig.gouv.fr/pcrs-information" xmlns:gts="http://www.isotc211.org/2005/gts" version="2.0" gml:id="SchemaPCRSv2">
<pcrs:featureMember>
<pcrs:AffleurantPCRS gml:id="AffleurantEnveloppePCRS_49015.14">
<pcrs:idObjet>AffleurantEnveloppePCRS_49015.14</pcrs:idObjet>
<pcrs:thematique>10</pcrs:thematique>
<pcrs:qualiteCategorisation>01</pcrs:qualiteCategorisation>
<pcrs:precisionPlanimetrique>010</pcrs:precisionPlanimetrique>
<pcrs:precisionAltimetrique>010</pcrs:precisionAltimetrique>
<pcrs:producteur>SIEML</pcrs:producteur>
<pcrs:gestionnaire>Gestionnaire de l'affleurant</pcrs:gestionnaire>
<pcrs:nature>03</pcrs:nature>
<pcrs:reseau>ASSA</pcrs:reseau>
<pcrs:representation>
<pcrs:AffleurantGeometriquePCRS gml:id="GEOMETRIE.AffleurantEnveloppePCRS_49015.14">
<pcrs:enveloppe>
<pcrs:AffleurantEnveloppePCRS gml:id="GEOMETRIE.ENV.AffleurantEnveloppePCRS_49015.14">
<pcrs:geometrie><gml:Polygon gml:id="id-f78dbfa0-67b4-4f1b-8ef3-cb09d9c89f44-0" srsName="EPSG:3947" srsDimension="3"><gml:exterior><gml:Ring><gml:curveMember><gml:LineString gml:id="id-f78dbfa0-67b4-4f1b-8ef3-cb09d9c89f44-1"><gml:posList>1429379.9137071301 6261378.782823057 49.20578684257577 1429379.9401083528 6261378.772486777 49.20651550341891 1429379.9673111148 6261378.764490929 49.20720133682967 1429379.9951083863 6261378.758896369 49.20783912320168 1429380.0232886137 6261378.755745672 49.20842400859553 1429380.051637328 6261378.755062818 49.208951541680214 1429380.079938779 6261378.756853003 49.209417707610434 1429380.107977575 6261378.761102605 49.20981895858197 1429380.135540324 6261378.767779279 49.210152240832656 1429380.162417257 6261378.776832214 49.210415017883314 1429380.1884038239 6261378.788192509 49.21060528984193 1429380.2133022517 6261378.801773707 49.210721608624 1429380.2369230483 6261378.817472448 49.21076308897336 1429380.2590864447 6261378.835169253 49.2107294151995 1429380.2796237646 6261378.85472944 49.21062084358019 1429380.2983787064 6261378.876004143 49.210438200410984 1429380.3152085335 6261378.898831449 49.210182875716704 1429380.329985161 6261378.92303763 49.209856812672435 1429380.34259613 6261378.94843846 49.20946249281482 1429380.3529454628 6261378.974840624 49.20900291715609 1429380.3609543953 6261379.002043187 49.208481583344486 1429380.3665619744 6261379.029839119 49.20790245904512 1429380.369725523 6261379.058016878 49.207269951743584 1429380.370420965 6261379.086362013 49.20658887520237 1429380.368643007 6261379.114658801 49.2058644128252 1429380.3644051808 6261379.142691886 49.2051020782082 1429380.357739739 6261379.17024792 49.20430767317812 1429380.348697409 6261379.197117184 49.20348724363692 1429380.3373470088 6261379.223095188 49.202647033548786 1429380.323774922 6261379.247984222 49.20179343741983 1429380.3080844397 6261379.271594866 49.200932951632 1429380.2903949767 6261379.29374743 49.200072125001725 1429380.27084116 6261379.314273318 49.19921750893944 1429380.2495718063 6261379.333016316 49.19837560758942 1429380.2267487878 6261379.349833779 49.19755282832927 1429380.2025458019 6261379.364597715 49.19675543300599 1429380.1771470476 6261379.377195763 49.19598949027945 1429380.150745825 6261379.387532043 49.19526082943631 1429380.123543063 6261379.395527891 49.19457499602555 1429380.0957457914 6261379.401122452 49.19393720965354 1429380.067565564 6261379.404273149 49.19335232425969 1429380.0392168497 6261379.404956003 49.192824791175006 1429380.0109153988 6261379.403165817 49.192358625244786 1429379.9828766028 6261379.398916216 49.19195737427325 1429379.9553138537 6261379.392239542 49.191624092022565 1429379.9284369207 6261379.383186607 49.19136131497191 1429379.9024503538 6261379.371826312 49.19117104301329 1429379.877551926 6261379.358245113 49.19105472423122 1429379.8539311294 6261379.342546373 49.19101324388186 1429379.831767733 6261379.324849567 49.19104691765572 1429379.8112304132 6261379.30528938 49.19115548927503 1429379.7924754713 6261379.284014678 49.19133813244424 1429379.7756456442 6261379.261187371 49.19159345713852 1429379.7608690166 6261379.236981191 49.191919520182786 1429379.7482580477 6261379.21158036 49.1923138400404 1429379.737908715 6261379.185178196 49.19277341569913 1429379.7298997825 6261379.157975634 49.193294749510734 1429379.7242922033 6261379.130179701 49.1938738738101 1429379.7211286547 6261379.102001943 49.19450638111164 1429379.7204332128 6261379.073656808 49.19518745765285 1429379.7222111707 6261379.045360019 49.19591192003002 1429379.726448997 6261379.017326934 49.19667425464702 1429379.7331144388 6261378.9897709 49.1974686596771 1429379.7421567687 6261378.962901636 49.1982890892183 1429379.753507169 6261378.936923632 49.199129299306435 1429379.7670792558 6261378.912034598 49.19998289543539 1429379.782769738 6261378.888423954 49.20084338122322 1429379.800459201 6261378.866271391 49.201704207853496 1429379.8200130176 6261378.845745502 49.20255882391578 1429379.8412823714 6261378.827002504 49.2034007252658 1429379.86410539 6261378.810185041 49.20422350452595 1429379.8883083758 6261378.795421105 49.20502089984923 1429379.9137071301 6261378.782823057 49.20578684257577</gml:posList></gml:LineString></gml:curveMember></gml:Ring></gml:exterior></gml:Polygon>
</pcrs:geometrie>
</pcrs:AffleurantEnveloppePCRS>
</pcrs:enveloppe>
</pcrs:AffleurantGeometriquePCRS>
</pcrs:representation>
</pcrs:AffleurantPCRS>
</pcrs:featureMember>
  • 1
    In what way "it doesn't work"? Do you get any errors in the debugger console? – TomazicM May 10 at 18:20
  • @TomazicM actually my debugger said only : Failed to load resource: net::ERR_FAILED – programmation1994 May 10 at 18:27
  • There is syntax error in your GML, missing is closing <\pcrs:PlanCorpsRueSimplifie>. But even if you add that, it still does not work, no mater which GML format I tried (GML2, GML3, GML32). From here on I can't help you, this is not my area. – TomazicM May 11 at 19:44

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.