首页 / 浏览问题 / WebGIS / 问题详情
官网示例 分段专题图 使用外部数据joinItem时专题图渲染不出来
8EXP 2025年01月16日

请问这段代码使用joinItem为什么渲染不出来专题图,也没有报错

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_themeRange"></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, themeService, themeRange, themeParameters, themeLayer,
        url = host + "/iserver/services/map-china400/rest/maps/China";
    // 外部表数据(Province_Statistics)
    var Province_Statistics = [
        { Province_Name: "河南省", GDP: 400000000000 },
        { Province_Name: "四川省", GDP: 300000000000 },
        { Province_Name: "山东省", GDP: 100000000000 },
        // 添加更多省份数据...
    ];
    map = L.map('map', {
        center: [30, 84],
        maxZoom: 18,
        zoom: 3
    });
    new L.supermap.TiledMapLayer(url, {noWrap: true, transparent: true}).addTo(map);
    createTheme();

    function createTheme() {
        themeService = new L.supermap.ThemeService(url);

        // 定义 JoinItem
        var joinItem = new L.supermap.JoinItem({
            foreignTableName: "Province_Statistics", // 外部属性数据表名
            joinFilter: "China_Province_pg.Name = Province_Statistics.Province_Name", // 关联条件
            joinType: "INNERJOIN" // 关联类型
        });

        // 定义范围分段专题图的项
        var themeRangeItem1 = new L.supermap.ThemeRangeItem({
            start: 0,
            end: 500000000000,
            style: new L.supermap.ServerStyle({
                fillForeColor: new L.supermap.ServerColor(211, 255, 250),
                lineColor: new L.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });
        var themeRangeItem2 = new L.supermap.ThemeRangeItem({
            start: 500000000000,
            end: 1000000000000,
            style: new L.supermap.ServerStyle({
                fillForeColor: new L.supermap.ServerColor(178, 218, 199),
                lineColor: new L.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });
        var themeRangeItem3 = new L.supermap.ThemeRangeItem({
            start: 1000000000000,
            end: 3000000000000,
            style: new L.supermap.ServerStyle({
                fillForeColor: new L.supermap.ServerColor(58, 178, 166),
                lineColor: new L.supermap.ServerColor(179, 209, 193),
                lineWidth: 0.1
            })
        });

        // 定义范围分段专题图
        themeRange = new L.supermap.ThemeRange({
            rangeExpression: "Province_Statistics.GDP", // 使用关联表中的 GDP 字段
            rangeMode: L.supermap.RangeMode.EQUALINTERVAL,
            items: [themeRangeItem1, themeRangeItem2, themeRangeItem3]
        });

        // 定义专题图参数
        themeParameters = new L.supermap.ThemeParameters({
            datasetNames: ["China_Province_pg"], // 空间数据集
            dataSourceNames: ["China"], // 数据源名称
            joinItems: [joinItem], // 加入 JoinItem
            themes: [themeRange] // 加入专题图
        });

        // 获取专题图信息并添加到地图
        themeService.getThemeInfo(themeParameters).then(function (serviceResult) {
            var result = serviceResult.result;
            if (result && result.newResourceID) {
                themeLayer = new L.supermap.TiledMapLayer(url, {
                    noWrap: true,
                    cacheEnabled: false,
                    transparent: true,
                    layersID: result.newResourceID
                }).addTo(map);
            }
        });
    }
</script>
</body>
</html>

1个回答

您好,这个外部数据不是加在JavaScript中,应该添加到数据源中才能使用

1,046EXP 2025年01月16日
...