[Wiki] Mapea 4 - GeoJSON
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
var mapajs = M.map({
container: "map",
wmcfiles: ["mapa"]
});
let layer = new M.layer.GeoJSON({
source: {
crs: {
properties: {
name: "EPSG:4326"
},
type: "name"
},
features: [],
type: "FeatureCollection"
},
name: 'prueba'
});
//GeoJSON local
mapajs.addLayers(layer);
// Añadimos features cuando la capa esté en el mapa
layer.on(M.evt.LOAD, () => {
let f1 = new M.Feature(1, {
properties: {
nombre: 'Feature-1'
},
type: "Feature",
id: 1,
geometry_name: "geometry",
geometry: {
type: "Point",
coordinates: [284469, 4142704]
}
});
let f2 = new M.Feature(2, {
properties: {
nombre: 'Feature-2'
},
type: "Feature",
id: 2,
geometry_name: "geometry",
geometry: {
type: "Point",
coordinates: [303597, 4159135]
}
})
layer.addFeatures([f1, f2]);
})