首页 / 浏览问题 / WebGIS / 问题详情
获取折线polyLine长度,报错
Lsk
10EXP 2023年02月21日
var distanceMeasureParam = new SuperMap.MeasureParameters(polyLine);         console.log(distanceMeasureParam);         L.supermap             .measureService(url1)             .measureDistance(distanceMeasureParam, function (serviceResult) {                 console.log(serviceResult);             }); 然后打印错误信息:error: {code: 400, errorMsg: "A JSONObject text must begin with '{' at 1 [character 2 line 1]"} 如下: {element: null error: {code: 400, errorMsg: "A JSONObject text must begin with '{' at 1 [character 2 line 1]"} object: MeasureService {EVENT_TYPES: Array(2), events: Events, eventListeners: {…}, url: 'http://192.168.4.20:8090/iserver/services/map-ZKGQ/rest/maps/ZKYZT/distance', urls: null, …} type: "processFailed"}

1个回答

您好,请问您具体使用的是iClient的什么产品呢。

如果是leaflet的话,我这里测试是正常的。


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_measureDistance"></title>
<script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, resultLayer, url = host + "/iserver/services/map-world/rest/maps/World";
    map = L.map('map', {
        preferCanvas: true,
        crs: L.CRS.EPSG4326,
        center: [34, 108],
        maxZoom: 18,
        zoom: 3
    });
    new L.supermap.TiledMapLayer(url).addTo(map);
    resultLayer = L.featureGroup().addTo(map);
    measureDistance();

    function measureDistance() {
        var polyLine = L.polyline([[25, 102], [40, 116],[60, 116]], {color: "red"});
        var marker1 = L.marker([25, 102]), marker2 = L.marker([40, 116]), marker3 = L.marker([60, 116]);
        
        resultLayer.addLayer(polyLine);
        resultLayer.addLayer(marker1);
        resultLayer.addLayer(marker2);
        resultLayer.addLayer(marker3);
        var distanceMeasureParam = new L.supermap.MeasureParameters(polyLine);
        new L.supermap
            .MeasureService(url)
            .measureDistance(distanceMeasureParam, function (serviceResult) {
                var content = resources.text_distance+":" + serviceResult.result.distance + resources.msg_m;
                marker1.bindPopup(content).openPopup(marker1.getLatLng());
            });


    }
</script>
</body>
</html>

希望可以帮助到您。

10,418EXP 2023年02月21日
您好,请问这个new L.supermap.MeasureParameters(polyLine)中的参数polyLine,生成polyLine的点最多又限制吗?我测试如果生成pulyLine的点超过9个就会报错,9个以内是正常的
补充一下就是,在超图示例中填入我的点是正常获取长度,在我自己的代码中是会报错,new L.supermap .MeasureService(url)中的url有什么要求吗
节点数量没有限制
...