You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I currently try to implement the SLD Reader into my own openlayers project. I checked the live examples as well as the API, but I am still not able to implement it.
I implemented the code into my project as follows:
html file: <head> <script src="node_modules\@nieuwlandgeo\sldreader\docs\assets\sldreader.js"></script> </head>
javascript file:
`var linien = new ol.layer.Vector({
title: 'Linienmaßnahmen',
source: new ol.source.Vector({
url: 'data/Linienmassnahmen.geojson',
format: new ol.format.GeoJSON()
}),
style: new ol.style.Style ({
stroke: new ol.style.Stroke ({
color: [0, 0, 0, 1.0],
width: 3.5
})
})
});
"massnahmen_linien" is the name of my sld file (I also attached it as a textfile). But I'm not sure if I use the applySLD() command right. If I run the code I get the error TypeError: n.getAttribute is not a function.
I currently try to implement the SLD Reader into my own openlayers project. I checked the live examples as well as the API, but I am still not able to implement it.
I implemented the code into my project as follows:
html file:
<head> <script src="node_modules\@nieuwlandgeo\sldreader\docs\assets\sldreader.js"></script> </head>
javascript file:
`var linien = new ol.layer.Vector({
title: 'Linienmaßnahmen',
source: new ol.source.Vector({
url: 'data/Linienmassnahmen.geojson',
format: new ol.format.GeoJSON()
}),
style: new ol.style.Style ({
stroke: new ol.style.Stroke ({
color: [0, 0, 0, 1.0],
width: 3.5
})
})
});
function applySLD(vectorLayer, text) {
const sldObject = SLDReader.Reader(text);
window.sldObject = sldObject;
const sldLayer = SLDReader.getLayer(sldObject);
const style = SLDReader.getStyle(sldLayer, 'Maßnahmen_Linien');
const featureTypeStyle = style.featuretypestyles[0];
const viewProjection = map.getView().getProjection();
vectorLayer.setStyle(SLDReader.createOlStyleFunction(featureTypeStyle, {
convertResolution: viewResolution => {
const viewCenter = map.getView().getCenter();
return ol.proj.getPointResolution(viewProjection, viewResolution, viewCenter);
},
}));
}
applySLD(linien, 'massnahmen_linien.sld');`
"massnahmen_linien" is the name of my sld file (I also attached it as a textfile). But I'm not sure if I use the
applySLD()
command right. If I run the code I get the errorTypeError: n.getAttribute is not a function
.massnahmen_linien.txt
The text was updated successfully, but these errors were encountered: