首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >QML:在QML地图上绘制地质区域

QML:在QML地图上绘制地质区域
EN

Stack Overflow用户
提问于 2022-07-28 17:48:04
回答 1查看 132关注 0票数 -1

任何关于如何在QML (Qt位置模块)中绘制自定义地理区域的想法都与此类似:

类似于MapCircleMapPolygon但在该地区以外的地方填充的东西?还有定制的填充模式吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-30 07:24:25

您可能可以使用MapItems之一,例如,MapQuickItem允许您将任何QML项放入其中,例如,我使用Canvas

代码语言:javascript
运行
复制
Plugin {
    id: mapPlugin
    name: "osm"
}

Map {
    id: map
    anchors.fill: parent
    plugin: mapPlugin
    center: QtPositioning.coordinate(59.91, 10.75)
    zoomLevel: 14

    MapQuickItem {
        id: marker
        anchorPoint.x: image.width / 2
        anchorPoint.y: image.height / 2
        coordinate: map.center
        sourceItem: Canvas {
            id: image
            width: map.width
            height:  map.height
            onPaint: {
                var ctx = getContext("2d");
                ctx.beginPath();
                ctx.moveTo(0, 0);
                ctx.lineTo(image.width, 0);
                ctx.lineTo(image.width, image.height);
                ctx.lineTo(0, image.height);
                ctx.lineTo(0, 0);
                ctx.moveTo(image.width/2 + 50, image.height/2);
                ctx.arc(image.width/2, image.height/2, 50, 0, 2 * Math.PI,0, true);
                ctx.closePath();
                ctx.fillStyle = Qt.rgba(1.0, 0, 0, 0.5);
                ctx.strokeStyle = "red"
                ctx.lineWidth = 10;
                ctx.fill();
                ctx.stroke();
            }
        }
    }
}

注意,弧线的逆时针方向是真能造个洞。同样,您也可以添加图像等,但在实际项目中,我会使用一些基于QQuickItem的定制项,以获得更好的性能。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73157176

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档