New control for openlayer, building legend from sources.
git clone [email protected]:SDaron/olLegend.git
npm start
import {Map, View} from 'ol';
import {Fill, Stroke, Style} from 'ol/style';
import {Vector as VectorSource} from 'ol/source.js';
import {Vector as VectorLayer} from 'ol/layer.js';
import controlLegend from './Legend.js';
import './legend.css';
const layer = new VectorLayer({
source: new VectorSource({
}),
});
layer.getSource().set('title',"Hydrologie");
layer.getSource().getLegends = function(){
const legends = [
{
label:'bassin versant',
geometry: 'Polygon',
style:new Style({
fill: new Fill({color: 'white'}),
stroke: new Stroke({color: 'red', width: '2'}),
})
},
{
label:'rivière',
geometry: 'LineString',
style:new Style({
stroke: new Stroke({color: 'red', width: '2'}),
})
}
];
return legends;
};
const map = new Map({
controls:[olLegend],
layers: [layer],
target: 'map'
});