Skip to content

Commit

Permalink
Merge pull request #142 from MIERUNE/feat/anchor-point
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanahiro authored Aug 25, 2023
2 parents 34568bf + aae0fec commit a490426
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
"outline_width": 2,
"asset_name": "some.svg",
"offset": [0.0, 0.0],
"anchor_x": "center", // 配置のX原点: left | center | right
"anchor_y": "middle", // 配置のY原点: top | middle | bottom
"rotation": 0.0, // degrees, 時計回り
"level": 0,
"opacity": 0.5 // 透過度: 0.0 ~ 1.0
Expand Down
6 changes: 6 additions & 0 deletions docs/SYMBOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
},
"shape": "circle", //square | diamond | pentagon | hexagon | triangle | equilateraltriangle | star | arrow | circle | cross | crossfill | cross2 | line | arrowhead | arrowheadfilled | semicircle | thirdcircle | quartercircle | quartersquare | halfsquare | diagonalhalfsquare | righthalftriangle | lefthalftriangle | trapezoid | parallelogramleft | parallelogramright | shield | octagon | decagon | squarecorners | squarerounded | diamondstar | heart | halfarc | thirdarc | quarterarc | asteriskfill
"offset": [0.0, 0.0],
"anchor_x": "center", // 配置のX原点: left | center | right
"anchor_y": "middle", // 配置のY原点: top | middle | bottom
"rotation": 0.0, //degrees, 時計回り
"level": 0,
"opacity": 1.0 // 透過度: 0.0 ~ 1.0
Expand All @@ -45,6 +47,8 @@
"outline_width": 2,
"asset_name": "some.svg",
"offset": [0.0, 0.0],
"anchor_x": "center", // 配置のX原点: left | center | right
"anchor_y": "middle", // 配置のY原点: top | middle | bottom
"rotation": 180.0, //degrees, 時計回り
"level": 0,
"opacity": 1.0 // 透過度: 0.0 ~ 1.0
Expand All @@ -62,6 +66,8 @@
"height": 5,
"asset_name": "some.png",
"offset": [0.0, 0.0],
"anchor_x": "center", // 配置のX原点: left | center | right
"anchor_y": "middle", // 配置のY原点: top | middle | bottom
"rotation": 0.0, // degrees, 時計回り
"level": 1,
"opacity": 1.0 // 透過度: 0.0 ~ 1.0
Expand Down
30 changes: 30 additions & 0 deletions translator/vector/symbol/marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ def _get_markershape_from(symbol_shape: QgsSimpleMarkerSymbolLayerBase.Shape) ->
)


def _get_x_position_from(
symbol_anchor_x: QgsMarkerSymbolLayer.HorizontalAnchorPoint,
) -> str:
return {
QgsMarkerSymbolLayer.HorizontalAnchorPoint.Left: "left",
QgsMarkerSymbolLayer.HorizontalAnchorPoint.HCenter: "center",
QgsMarkerSymbolLayer.HorizontalAnchorPoint.Right: "right",
}.get(
symbol_anchor_x, "center" # fallback
)


def _get_y_position_from(
symbol_anchor_y: QgsMarkerSymbolLayer.VerticalAnchorPoint,
) -> str:
return {
QgsMarkerSymbolLayer.VerticalAnchorPoint.Top: "top",
QgsMarkerSymbolLayer.VerticalAnchorPoint.VCenter: "middle",
QgsMarkerSymbolLayer.VerticalAnchorPoint.Bottom: "bottom",
}.get(
symbol_anchor_y, "middle" # fallback
)


def _get_svg_param(
symbol_layer: QgsSvgMarkerSymbolLayer,
) -> Tuple[Union[str, None], Union[float, None], Union[str, None]]:
Expand Down Expand Up @@ -113,6 +137,8 @@ def get_point_symbol_data(
convert_to_point(symbol_layer.offset().x(), symbol_layer.offsetUnit()),
convert_to_point(symbol_layer.offset().y(), symbol_layer.offsetUnit()),
],
"anchor_x": _get_x_position_from(symbol_layer.horizontalAnchorPoint()),
"anchor_y": _get_y_position_from(symbol_layer.verticalAnchorPoint()),
"rotation": symbol_layer.angle(),
"level": symbol_layer.renderingPass(), # renderingPass means symbolLevels
# https://github.com/qgis/QGIS/blob/65d40ee0ce59e761ee2de366ca9a963f35adfcfd/src/core/vector/qgsvectorlayerrenderer.cpp#L702
Expand All @@ -136,6 +162,8 @@ def get_point_symbol_data(
convert_to_point(symbol_layer.offset().x(), symbol_layer.offsetUnit()),
convert_to_point(symbol_layer.offset().y(), symbol_layer.offsetUnit()),
],
"anchor_x": _get_x_position_from(symbol_layer.horizontalAnchorPoint()),
"anchor_y": _get_y_position_from(symbol_layer.verticalAnchorPoint()),
"rotation": symbol_layer.angle(),
"level": symbol_layer.renderingPass(),
"opacity": symbol_opacity,
Expand All @@ -156,6 +184,8 @@ def get_point_symbol_data(
convert_to_point(symbol_layer.offset().x(), symbol_layer.offsetUnit()),
convert_to_point(symbol_layer.offset().y(), symbol_layer.offsetUnit()),
],
"anchor_x": _get_x_position_from(symbol_layer.horizontalAnchorPoint()),
"anchor_y": _get_y_position_from(symbol_layer.verticalAnchorPoint()),
"rotation": symbol_layer.angle(),
"level": symbol_layer.renderingPass(),
"opacity": symbol_opacity,
Expand Down

0 comments on commit a490426

Please sign in to comment.