基于openlayers3调用来自geoserver的切片地图服务

本文介绍如何使用OpenLayers3加载并显示来自GeoServer的切片地图服务,通过具体代码示例展示了配置地图层、设置投影、定义边界范围及调整视图等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于openlayers3调用来自geoserver的切片地图服务

<!DOCTYPE html>
<html>
  <head>
    <title>Simple Map</title>
    <link rel="stylesheet" href="https://openlayers.org/en/v3.20.1/css/ol.css" type="text/css">
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v3.20.1/build/ol.js"></script>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>

    //WMS的边界范围
    var extent=[-8380176.806709324, 4846475.643831644,-8344030.356053375, 4886005.70620772];

    //添加切片数据源
    var map = new ol.Map({
        layers: [
          new ol.layer.Tile({
            source: new ol.source.XYZ({
              //切片数据已经部署在../tomcat/webapps/ 下
              url: 'http://localhost:8081/PhillyBaseMap/{z}/{x}/{y}.png'
            })
          })
        ],
        target: 'map',
        view: new ol.View({
          projection: 'EPSG:3857', //定义墨卡托投影
          zoom:4
        })
    });

    //重要
    map.getView().fit(extent, map.getSize());
    </script>
  </body>
</html>

示例

Done

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值