首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenLayers中的卫星视图-如何设置?

问OpenLayers中的卫星视图-如何设置?
EN

Stack Overflow用户
提问于 2021-04-25 00:15:25
回答 1查看 72关注 0票数 0

是否可以将卫星视图添加到OpenLayers?

这是我初始化OpenLayers的方法:

代码语言:javascript
复制
setupMap() {
                    this.map = new OpenLayers.Map("mapdiv");
                    this.map.addLayer(new OpenLayers.Layer.OSM(
                        "OpenStreetMap", [
                            "https://a.tile.openstreetmap.org/${z}/${x}/${y}.png",
                            "https://b.tile.openstreetmap.org/${z}/${x}/${y}.png",
                            "https://c.tile.openstreetmap.org/${z}/${x}/${y}.png"
                        ]))

                    var lonLat = new OpenLayers.LonLat(9.5788, 48.9773).transform(
                        new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                        this.map.getProjectionObject() // to Spherical Mercator Projection
                    );
                    var zoom = 11;
                    this.map.setCenter(lonLat, zoom);
                }

我试过了,但上面写着a is null

代码语言:javascript
复制
            setupMap() {
                this.map = new OpenLayers.Map("mapdiv");

                this.map.addLayer(new OpenLayers.Layer.XYZ({
                    attributions: ['Powered by Esri',
                        'Source: Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community'],
                    attributionsCollapsible: false,
                    url: 'https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
                    maxZoom: 23
                }))

                var lonLat = new OpenLayers.LonLat(9.5788, 48.9773).transform(
                    new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
                    this.map.getProjectionObject() // to Spherical Mercator Projection
                );
                var zoom = 11;
                this.map.setCenter(lonLat, zoom);
            },

错误

代码语言:javascript
复制
TypeError: a is null
    format http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:59
    getURL http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:608
    queueTileDraw http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:1351
    triggerEvent http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:138
    draw http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:486
    draw http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:488
    initGriddedTiles http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:514
    moveTo http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:502
    moveTo http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:190
    setCenter http://127.0.0.1:8000/static/main/openlayers/OpenLayers.js:184
    setupMap http://127.0.0.1:8000/dashboard/?tab=realestates:2997
    mounted http://127.0.0.1:8000/dashboard/?tab=realestates:2373
    VueJS 7
    <anonymous> http://127.0.0.1:8000/dashboard/?tab=realestates:2250
vue.js:1897:15
    VueJS 10
    <anonymous> http://127.0.0.1:8000/dashboard/?tab=realestates:2250
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-25 01:09:19

OpenLayers 2 XYZ语法类似于OSM,但添加了attribution (单数)、numZoomLevels (缩放级别从0开始时比OpenLayers 3中的maxZoom大1)和标准球形墨卡托OSM兼容平铺栅格的选项。

代码语言:javascript
复制
            this.map.addLayer(new OpenLayers.Layer.XYZ(
                "Satellite", [
                    "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/${z}/${y}/${x}"
                ], {
                    attribution: "Powered by Esri. " + 
                        "Source: Esri, DigitalGlobe, GeoEye, Earthstar Geographics, CNES/Airbus DS, USDA, USGS, AeroGRID, IGN, and the GIS User Community",
                    numZoomLevels: 24,
                    sphericalMercator: true
                }))
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67244906

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档