[Test] WFS bbox
by Francisco
HTML
<script src="https://mapea4-sigc.juntadeandalucia.es/js/mapea-5.1.0.ol.min.js"></script>
<link rel="stylesheet" href="https://mapea4-sigc.juntadeandalucia.es/assets/css/mapea-5.1.0.ol.min.css">
<script src="https://mapea4-sigc.juntadeandalucia.es/js/configuration-5.1.0.js"></script>
<div id="map"></div>
CSS
html,
body,
#map {
padding: 0;
margin: 0;
width: 100%;
height: 100%;
}
JavaScript
// En el constructor
var mapajs = M.map({
container: "map",
controls: ["layerswitcher","mouse"],
wmcfiles: ["mapa"],
bbox: [415783,4092656,441145,4112874]
});
let layer = new M.layer.GeoJSON({
name: "Provincias",
source: {}
});
mapajs.addLayers(layer);
// Pide de nuevo al WFS pero solo los features que intersecten con la vista actual
function recargaBbox(){
let features = M.remote.get("http://geostematicos-sigc.juntadeandalucia.es/geoserver/tematicos/ows?service=WFS&version=1.0.0&request=GetFeature&typename=tematicos:Provincias&outputFormat=application%2Fjson&srsname=EPSG%3A25830&CQL_FILTER=BBOX(the_geom,"+ mapajs.getBbox().x.min +","+ mapajs.getBbox().y.min + "," + mapajs.getBbox().x.max + "," + mapajs.getBbox().y.max + ")").then(function(res){
layer.clear();
let feats = JSON.parse(res.text).features;
console.log("Se han traido: " + feats.length + " features");
feats.forEach(function(feat){
let f = new M.Feature(feat.id,feat);
layer.addFeatures(f);
});
});
}
// Cada vez que cambie el bbox, se piden los features
mapajs.getMapImpl().on('moveend', function(){
recargaBbox();
});