Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Obtener datos de la fuente en openlayers

¿Cómo hago para que los datos de origen se carguen automáticamente, incluso sin agregar la capa al mapa? Tengo el siguiente código:

 var layer1 = new ol.layer.Vector({ title: 'Layer1', visible: true, name: 'layer1', style: new ol.style.Style({ image: new ol.style.Icon( ({ anchor: [0.5, 26], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src: 'legend/layer1.png' })) }), source: new ol.source.Vector({ format: new ol.format.GeoJSON(), url: function(extent) { return urlGeoserver + 'wfs?service=WFS&' + 'version='+versionGeoserver+'&request=GetFeature&typename=geo:LAYER1&' + 'outputFormat=application/json&srsname=EPSG:4326&' + 'all=' + extent.join(',') + ',EPSG:4326'; }, strategy: ol.loadingstrategy.all }) }); layer1.getSource().on('featuresloadend', (vectorSourceEvent) => { alert(vectorSourceEvent.features?.length); //return 0 })

De esta manera devuelve 0, pero hay varias características. Solo devuelve correcto si la capa se agrega al mapa: map.addLayer(layer1); ¿Cómo resolver, para que pueda tener acceso a la fuente, incluso sin haber agregado la capa?

[EDITAR]: siguiendo un consejo de Mike, con buscar, todavía no muestra los datos.

 var vectorSource = new ol.source.Vector(); var layer1 = new ol.layer.Vector({ title: 'Layer1', visible: true, name: 'layer1', style: new ol.style.Style({ image: new ol.style.Icon( ({ anchor: [0.5, 26], anchorXUnits: 'fraction', anchorYUnits: 'pixels', src: 'legend/layer1.png' })) }), source: vectorSource, }); var url = urlGeoserver + 'wfs?service=WFS&' + 'version='+versionGeoserver+'&request=GetFeature&typename=geo:LAYER1&' + 'outputFormat=application/json&srsname=EPSG:4326'; fetch(url) .then(function (response) { return response.json(); }) .then(function (json) { const features = new ol.format.GeoJSON().readFeatures(json); vectorSource.addFeatures(features); }); map.addLayer(layer1); //not return in map
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Puede completar una fuente de vectores obteniendo la URL, analizando las funciones y agregándolas a la fuente.

 var vectorSource = new ol.source.Vector(); fetch(url) .then(function (response) { return response.json(); }) .then(function (json) { const features = new ol.format.GeoJSON().readFeatures(json); vectorSource.addFeatures(features); alert(features.length); });
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda