Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix get style on drawing. Fix missing styles for points. #84

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions src/OpenLayers.Blazor/wwwroot/openlayers_interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,18 +1056,29 @@ MapOL.prototype.getCoordinates = function(layerId, featureId) {
return null;
};

MapOL.prototype.getShapeStyleAsync = async function(feature, layer_id) {
var shape;
if (ol.render.Feature.prototype.isPrototypeOf(feature))
shape = this.mapFeatureToInternalFeature(feature);
else
shape = this.mapFeatureToShape(feature);
delete shape.coordinates;
const style = await this.Instance.invokeMethodAsync("OnGetShapeStyleAsync", shape, layer_id);
return this.mapStyleOptionsToStyle(style, shape.geometryType);
};

MapOL.prototype.getShapeStyle = function(feature, layer_id) {
var shape;
if (ol.render.Feature.prototype.isPrototypeOf(feature))
shape = this.mapFeatureToInternalFeature(feature);
else
shape = this.mapFeatureToShape(feature);
delete shape.coordinates;
const style = this.Instance.invokeMethod("OnGetShapeStyle", shape, layer_id);
return this.mapStyleOptionsToStyle(style);
const style = this.Instance.invokeMethod("OnGetShapeStyle", shape, layer_id); // will fail on blazor server
return this.mapStyleOptionsToStyle(style, shape.geometryType);
};

MapOL.prototype.mapStyleOptionsToStyle = function(style) {
MapOL.prototype.mapStyleOptionsToStyle = function(style, geometryType = null) {

style = MapOL.transformNullToUndefined(style);

Expand Down Expand Up @@ -1101,6 +1112,15 @@ MapOL.prototype.mapStyleOptionsToStyle = function(style) {
if (style.text.backgroundStroke) style.text.backgroundStroke = new ol.style.Stroke(style.text.backgroundStroke);
}

// fix point style if circle not set
if (geometryType == 'Point' && !style.circle) {
style.circle = {
fill: new ol.style.Fill(style.fill),
stroke: new ol.style.Stroke(style.stroke),
radius: style.stroke.width * 2
};
}

const styleObject = new ol.style.Style({
stroke: style.stroke ? new ol.style.Stroke(style.stroke) : undefined,
fill: style.fill ? new ol.style.Fill(style.fill) : undefined,
Expand Down
Loading