关于#openlayers#的问题,如何解决?


html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Documenttitle>
    <script src="https://cdn.jsdelivr.net/npm/ol@v7.1.0/dist/ol.js">script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@v7.1.0/ol.css">
    <style>
        #map {
            width: 100%;
            height: 600px;
            position: absolute;
        }
    style>
head>

<body>
    <div id="map">div>
    <script>
        const map = new ol.Map({
            view: new ol.View({
                center: [116.399669, 39.921354],
                zoom: 5,
                projection: 'EPSG:4326'
            }),
            layers: [
                new ol.layer.Tile({
                    source: new ol.source.OSM()
                })
            ],
            target: 'map'
        });
    script>
body>

html>

#为什么加载不出地图
#一直报这个错误Failed to load resource: net::ERR_CONNECTION_TIMED_OUT tile.openstreetmap.org/5/29/13.png:1

img


你需要传递一个地图服务的地址在source的参数上