首页 / 浏览问题 / WebGIS / 问题详情
iClient for leaflet地物编辑问题
20EXP 2024年04月05日

参考示例改了代码,出现了以下问题:

1.这个随机点生成的位置并不在我指定的浮点数范围里,我想要能在我的地图范围中生成随机点这应该怎么修改。

2.只出现了maker,但是不能让这个maker在地图上生成真正的点并添加到我发布的rest数据服务中,这个是我发布的数据有什么问题的原因吗?

以下是我的代码:

function add(){
    var xmax = 118.82349554, xmin = 118.80992062, ymax = 32.08487901, ymin = 32.07325265
    var point = [];
    if (!marker || !featureGroup.hasLayer(marker)) {
        point = [
            Math.floor(Math.random() * (ymax - ymin + 1) + ymin),
            Math.floor(Math.random() * (xmax - xmin + 1) + xmin)
        ];
        marker = L.circleMarker(point, {color: "blue"});
        featureGroup.addLayer(marker);
        featureGroup.addTo(map);
        map.flyTo(point, 18);
    } else {
        featureGroup.clearLayers();
        point = [
            Math.floor(Math.random() * (ymax - ymin + 1) + ymin),
            Math.floor(Math.random() * (xmax - xmin + 1) + xmin)
        ];
        marker = L.circleMarker(point, {color: "blue"});
        featureGroup.addLayer(marker);
        featureGroup.addTo(map);
        map.flyTo(point, 18);
    }

    if (marker && featureGroup.hasLayer(marker)) {
        marker = marker.toGeoJSON();
        marker.properties = {POP: 1, CAPITAL: 'test'};
        var addFeatureParams = new L.supermap.EditFeaturesParameters({
            dataSourceName: "siy",
            dataSetName: "zwd",
            features: marker,
            editType: "add",
            returnContent: true
        });
        featureService.editFeatures(addFeatureParams, function (serviceResult) {
            if (serviceResult.result.succeed) {
                featureGroup.clearLayers();
                marker = null;
                if (resultLayer) {
                    map.removeLayer(resultLayer);
                    resultLayer = null;
                }
                widgets.alert.showAlert(resources.msg_submitSuccess, true);
            }
        });
    } else {
        widgets.alert.showAlert(resources.msg_addMarker, false);
    }
}

1个回答

您好,

1.随机点的范围您按需调整点坐标部分的代码即可

        point = [
            Math.floor(Math.random() * (ymax - ymin + 1) + ymin),
            Math.floor(Math.random() * (xmax - xmin + 1) + xmin)
        ]

2.数据服务本身被编辑添加成功,需要您数据服务开启允许编辑才可以,您可以查看对数据服务add数据时请求返回的结果。

参考:

https://iclient.supermap.io/examples/leaflet/editor.html#02_editFeatures

https://iclient.supermap.io/docs/leaflet/FeatureService.html

https://iclient.supermap.io/docs/leaflet/EditFeaturesParameters.html

http://support.supermap.com.cn/DataWarehouse/WebDocHelp/iServer/mergedProjects/SuperMapiServerRESTAPI/StatusCodeDescription.htm

希望可以帮到您。

9,728EXP 2024年04月07日
...