Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Openlayer carga GEOJSON desde una variable en lugar de una url

Tengo una representación de mapa, quiero agregar una capa basada en un GEOJSON, pero no quiero leerlo directamente desde un archivo GEOJSON, en cambio, tengo una variable que contiene la cadena exacta de GEOJSON que necesito, ¿Es posible cargarlo desde una variable en lugar de una url?

 var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Vector({ title: 'bikesRented', source: new ol.source.Vector({ url: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! format: new ol.format.GeoJSON() }), style: bikeStyle2 }) ], view: new ol.View({ center: ol.proj.fromLonLat([11.341868,44.494949]), zoom: 14 }) });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede leer las características de su cadena y agregarlas a la fuente

 var source = new ol.source.Vector(); var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Vector({ title: 'bikesRented', source: source, style: bikeStyle2 }) ], view: new ol.View({ center: ol.proj.fromLonLat([11.341868,44.494949]), zoom: 14 }) }); source.addFeatures( new ol.format.GeoJSON().readFeatures(geojsonstring, { dataProjection: 'EPSG:4326', featureProjection: map.getView().getProjection() }) );

o puede usar una URL de datos y dejar que OpenLayers la cargue

 var map = new ol.Map({ target: 'map', layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }), new ol.layer.Vector({ title: 'bikesRented', source: new ol.source.Vector({ url: 'data:,' + encodeURIComponent(geojsonstring), format: new ol.format.GeoJSON() }), style: bikeStyle2 }) ], view: new ol.View({ center: ol.proj.fromLonLat([11.341868,44.494949]), zoom: 14 }) });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!