首页 / 浏览问题 / 云GIS / 问题详情
测面积和距离,弹出undefined?
9EXP 2019年05月09日
var map, interaction, vectorLayer, feature,
    url = (window.isLocal ? window.server : "http://support.supermap.com.cn:8090") + "/iserver/services/map-world/rest/maps/World";
//初始化地图
var map = new ol.Map({
    target: 'map',
    controls: ol.control.defaults({
            attributionOptions: {
                collapsed: false
            }
        })
        .extend([new ol.supermap.control.Logo()]),
    view: new ol.View({
        center: [12911600, 4359823],
        minZoom: 3,
        zoom: 12,
    })
});
var layer = new ol.layer.Tile({
    source: new ol.source.SuperMapCloud()
});
map.addLayer(layer);


//-----------------------------------------------------------
//地图比例尺
var zoomControl = new ol.control.ScaleLine();
map.addControl(zoomControl);
//--------------------------------------------------

$('#measure_distance').click((function() {
    var source = new ol.source.Vector({ wrapX: false });
    vectorLayer = new ol.layer.Vector({
        source: source
    });
    map.addLayer(vectorLayer);

    var interaction = new ol.interaction.Draw({
        source: source,
        type: "LineString"
    });

    interaction.on('drawstart', function(evt) {
        feature = evt.feature;
    });
    interaction.on('drawend', function() {
        var distanceMeasureParam = new SuperMap.MeasureParameters(feature.getGeometry());
        new ol.supermap.MeasureService(url, { measureMode: "" }).measureDistance(distanceMeasureParam, function(serviceResult) {
          
                alert(serviceResult.result.distance , true);
        });
    });
    map.addInteraction(interaction);



}));

1个回答

您好,如果是function undefined就是引用有问题,没有正确加载js文件
5,668EXP 2019年05月09日
我只是引入了include-openlayers.js  用alert 弹出结果 这样  浏览器没报错   弹窗里只显示了undefined  用alert( serviceResult.result.distance + resources.msg_m)这样会出错  ,

用alert( serviceResult.result.distance )弹窗显示undefined
??????
...