240102kkk

本文介绍了如何在HTML页面中利用OpenLayers库创建基础地图,集成WMS数据源,创建并添加WMS图层,展示世界省份地图,包括比例尺和鹰眼功能。
摘要由CSDN通过智能技术生成

第三个

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" type="text/css" href="css/ol.css">
        <script type="text/javascript" src="js/ol.js"></script>
        <style type="text/css">
            body{
                margin: 0px;
            }
            html,body,#map{height:100%;}
            
            #mapbar{
                position : absolute; 
                right: 15px;
                top: 15px;
                width:150px;
                height:20px;
            }
        </style>
    </head>
    <body>
        <div id="map" class="map"></div>
        <div id="mapbar"></div>
        <script>
        /**
         * 1、创建基础地图,增加比例尺控件和鹰眼控件
         * 2、创建WMS数据源
         * 3、创建WMS图层,连接数据源
         * 4、将WMS图层添加到地图当中
         */
            //1、创建基础地图,增加比例尺控件和鹰眼控件
            var map = new ol.Map({
                target:"map",
                layers:[new ol.layer.Tile({
                    source:new ol.source.OSM()
                })],
                view:new ol.View({
                    center:[0,0],
                    zoom:3
                })
            })
            var scaleControl = new ol.control.ScaleLine({
                target : "mapbar",
                units : "metric",
                bar : true
            });
            map.addControl(scaleControl);
            
            var eagleEyeControl = new ol.control.OverviewMap({
                collapsed : "true"
            });
            map.addControl(eagleEyeControl);
            
            //2、创建WMS数据源
            var worldSource = new ol.source.ImageWMS({
                url : "http://localhost:8080/geoserver/wms",
                params:{
                    "layers":"world"
                }
            })
            //3、创建WMS图层,连接数据源
            var provinceLayer = new ol.layer.Image({
                source : worldSource
            });
            //4、将WMS图层添加到地图当中
            map.addLayer(provinceLayer);
        </script>
    </body>
</html>

  • 6
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值