首页 / 浏览问题 / WebGIS / 问题详情
iclient for leaflet调用地图服务加载不出来
11EXP 2023年08月23日
<!--********************************************************************
* Copyright© 2000 - 2023 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!--********************************************************************
* 该示例需要引入
* Leaflet.draw (https://github.com/Leaflet/Leaflet.draw/)
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_drawFeatures"></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="width: 100%;height:100%"></div>
<script type="text/javascript" include="leaflet.draw" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "https://iserver.supermap.io";
    var map, url = host + "/iserver/services/map-china400/rest/maps/China_4326";
    map = L.map('map', {
        center: [33, 114],
        zoom: 4
    });
    new L.supermap.TiledMapLayer(url).addTo(map);

    var editableLayers = new L.FeatureGroup();
    map.addLayer(editableLayers);
    var options = {
        position: 'topleft',
        draw: {
            polyline: {},
            polygon: {},
            circle: {},
            rectangle: {},
            marker: {},
            remove: {}
        },
        edit: {
            featureGroup: editableLayers,
            remove: true
        }
    };
    var drawControl = new L.Control.Draw(options);
    map.addControl(drawControl);
    handleMapEvent(drawControl._container, map);
    map.on(L.Draw.Event.CREATED, function (e) {
        var type = e.layerType,
            layer = e.layer;
        if (type === 'marker') {
            layer.bindPopup('A popup!');
        }
        editableLayers.addLayer(layer);
    });

    function handleMapEvent(div, map) {
        if (!div || !map) {
            return;
        }
        div.addEventListener('mouseover', function () {
            map.scrollWheelZoom.disable();
            map.doubleClickZoom.disable();
        });
        div.addEventListener('mouseout', function () {
            map.scrollWheelZoom.enable();
            map.doubleClickZoom.enable();
        });
    }
</script>

我将路径换为调用China_4326底图服务后地图就显示不出来了。

2 个回答

您好,

您需要在map中设定坐标系,如下所示

希望可以帮到您

280EXP 2023年08月23日

您好,

根据您的代码发现,在进行地图实例化时,未进行坐标系的设置。

建议您可以参见Leaflet文档中地图实例化的指南,以及官网中的示例,对相关参数进行设置:

https://leafletjs.com/

iClient for Leaflet 示范程序 (supermap.io)

希望可以帮助到您!

460EXP 2023年08月28日
...