OpenLayers入门①(引入的是一个高德地图)

 OpenLayers入门(一) - 知乎

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
    <style>
        .ol-zoomslider {
            top: 7.5em;
        }
    </style>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 14,
                projection: "EPSG:4326"
            })
        })
        // 视图跳转控件
        const ZoomToExtent = new ol.control.ZoomToExtent({
            extent: [126.4, 45.7, 126.7, 45.9]
        })
        map.addControl(ZoomToExtent)

        // 放大缩小控件
        const zoomslider = new ol.control.ZoomSlider();
        map.addControl(zoomslider)

        // 全屏控件
        const fullScreen = new ol.control.FullScreen();
        map.addControl(fullScreen);



        // 1.通用样式信息和几何信息构建点要素
        // 几何
        const point = new ol.Feature({
            geometry: new ol.geom.Point([126.5350, 45.8021])
        });

        let style = new ol.style.Style({
            // image属性设置点要素的样式
            image: new ol.style.Circle({
                // radius设置点的半径 单位degree
                radius: 10,
                fill: new ol.style.Fill({
                    color: "#ff2d51"
                }),
                stroke:new ol.style.Stroke({
                    width:2,
                    color:"#333"
                })
            })
        })
        point.setStyle(style);
        // 2.将要素添加到矢量数据源
        let source = new ol.source.Vector({
            features: [point]
        })
        // 3.将矢量数据源添加到矢量图层
        let layer = new ol.layer.Vector({
            source
        })
        // 4.添加矢量图层到地图容器
        map.addLayer(layer)
    </script>

</body>

</html>

geojson

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
    <style>
        .ol-zoomslider {
            top: 7.5em;
        }
    </style>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 14,
                projection: "EPSG:4326"
            })
        })
        // 视图跳转控件
        const ZoomToExtent = new ol.control.ZoomToExtent({
            extent: [126.4, 45.7, 126.7, 45.9]
        })
        map.addControl(ZoomToExtent)

        // 放大缩小控件
        const zoomslider = new ol.control.ZoomSlider();
        map.addControl(zoomslider)

        // 全屏控件
        const fullScreen = new ol.control.FullScreen();
        map.addControl(fullScreen);



        // 创建geojson数据
        var data = {
            type:"FeatureCollection",
            features:[
                {
                    type:"Feature",
                    geometry:{
                        type:"Point",
                        coordinates:[114.30,30.50]
                    }
                }
            ]
        }
        // 将数据添加到矢量数据源中
        var source = new ol.source.Vector({
            features:new ol.format.GeoJSON().readFeatures(data)
        })
        // 设置矢量图层
        var layer = new ol.layer.Vector({
            source
        })
        const style = new ol.style.Style({
            image:new ol.style.Circle({
                radius:10,
                fill:new ol.style.Fill({
                    color:"#ff2d51"
                }),
                stroke:new ol.style.Stroke({
                    color:"#333"
                })
            })
        })
        layer.setStyle(style)
        // 添加矢量图层到地图容器
        map.addLayer(layer)
    </script>

</body>

</html>

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 14,
                projection: "EPSG:4326"
            })
        })


    // 区域要素
        // 设置line要素的geojson数据
        var data = {
            type:"FeatureCollection",
            features:[{
                type:"Feature",
                geometry:{
                    type:"LineString",
                    coordinates:[
                        [114.30,30.50],
                        [116,30.31]
                    ]
                }
            },{
                type:"Feature",
                geometry:{
                    type:"Polygon",
                    coordinates:[[
                        [114.30,30.50],
                        [116,30.50],
                        [116,30]
                    ]]
                }
            }]
        }
        // 设置矢量数据源读取数据
        let source = new ol.source.Vector({
            features:new ol.format.GeoJSON().readFeatures(data)
        })
        // 设置矢量图层
        let layer = new ol.layer.Vector({
            source
        })
        let style = new ol.style.Style({
            // stroke线设置样式
            stroke: new ol.style.Stroke({
                color:"#ff2d51",
                width:3
            }),
            fill:new ol.style.Fill({
                color:"rgba(50,50,50,0.3)"
            })
        })
        layer.setStyle(style)
        // 添加到地图容器
        map.addLayer(layer)
    </script>

</body>

</html>

加载本地的geojson数据

 

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 14,
                projection: "EPSG:4326"
            })
        })


        // 设置矢量数据源加载geojson数据
        var source = new ol.source.Vector({
            url:"./data/map.geojson",
            format:new ol.format.GeoJSON()
        })
        // 设置矢量图层
        var layer = new ol.layer.Vector({
            source
        })
        const style = new ol.style.Style({
            image:new ol.style.Circle({
                radius:8,
                fill:new ol.style.Fill({
                    color:"#ff2d51"
                })
            })
        })
        layer.setStyle(style)
        // map
        map.addLayer(layer)
    </script>

</body>

</html>

 


<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 4,
                projection: "EPSG:4326"
            })
        })

        // 加载网络geojson数据
        const china_source = new ol.source.Vector({
            url:"https://geo.datav.aliyun.com/areas_v3/bound/100000_full.json",
            format:new ol.format.GeoJSON()
        })
        const china_layer = new ol.layer.Vector({
            source:china_source
        })
        const china_style = new ol.style.Style({
            fill:new ol.style.Fill({
                color:'rgba(50,50,50,0.4)'
            }),
            stroke:new ol.style.Stroke({
                color:"#ff2d5180",
                width:2
            })
        })
        china_layer.setStyle(china_style)
        map.addLayer(china_layer)


        // 湖北
        const huibei_source = new ol.source.Vector({
            url:"https://geo.datav.aliyun.com/areas_v3/bound/420000_full.json",
            format:new ol.format.GeoJSON()
        })
        const huibei_layer = new ol.layer.Vector({
            source:huibei_source
        })
        const huibei_style = new ol.style.Style({
            fill:new ol.style.Fill({
                color:'#333'
            }),
        })
        huibei_layer.setStyle(huibei_style)
        map.addLayer(huibei_layer)
    </script>

</body>

</html>

地图事件及漫游

地图事件及漫游-CSDN直播

<!DOCTYPE html>
<html lang="en">

<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>Document</title>
    <!-- 1.导入ol依赖 -->
    <link rel="stylesheet" href="https://lib.baomitu.com/ol3/4.6.5/ol.css">
    <script src="https://lib.baomitu.com/ol3/4.6.5/ol.js"></script>
    <style>
        .btn{
            position: fixed;
            z-index: 100;
            top: 30px;
            right: 50px;
        }
    </style>
</head>

<body>
    <!-- 2.设置地图的挂载点 -->
    <div id="map">

    </div>
    <button class="btn">复位地图</button>
    <script>
        // 3.初始化一个高德图层
        const gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });

        // 4.初始化openlayer地图
        const map = new ol.Map({
            // 将初始化的地图设置到id为map的DOM元素上
            target: "map",
            // 设置图层
            layers: [gaode],
            view: new ol.View({
                center: [114.30, 30.50],
                // 设置地图放大级别
                zoom: 14,
                projection: "EPSG:4326"
            })
        })

        // source-layer
        var source = new ol.source.Vector({})
        var layer = new ol.layer.Vector({
            source
        })
        map.addLayer(layer);
        // 给地图绑定一个点击事件
        map.on("click", (evt) => {
            var { coordinate } = evt;
            console.log(coordinate)
            var point = new ol.Feature({
                geometry: new ol.geom.Point(coordinate)
            })
            source.addFeature(point);



            // 实现飞行视角--漫游
            const view = map.getView();
            view.animate({
                center: coordinate
            })
        })


        // 复位按钮
        var btn = document.querySelector(".btn");
        btn.onclick = function () {
            map.getView().animate({
                center:[114.30,30.50],
                zoom:6,
                duration:3000
            })
        }
    </script>

</body>

</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/584121.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

使用 LooperPrinter 监控 Android 应用的卡顿

在 Android 开发中&#xff0c;主线程&#xff08;UI线程&#xff09;的卡顿直接影响用户体验。LooperPrinter 是一种有效的工具&#xff0c;可以帮助我们监测和识别这些卡顿。下面是如何实现 LooperPrinter 监控的详细步骤和相应的 Kotlin 代码示例。 步骤 1: 创建自定义的 P…

【java超方便的导入导出工具类】SpringBoot操作Excel导入和导出

Excel导入和导出 一、前期准备 1、首先导入主要的依赖 <dependencies><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.7.0</version></dependency><depende…

Stable Diffusion 模型分享:Counterfeit-V3.0(动漫)

本文收录于《AI绘画从入门到精通》专栏&#xff0c;专栏总目录&#xff1a;点这里&#xff0c;订阅后可阅读专栏内所有文章。 文章目录 模型介绍生成案例案例一案例二案例三案例四案例五案例六案例七案例八 下载地址 模型介绍 高质量动漫风格模型。 条目内容类型大模型基础模…

关于使用SpringSecurity框架发起JSON请求,但因登陆失效导致响应403的问题。

这里记录一个生产中遇到的一个问题。 现有环境是基于SpringBoot 2.6.8&#xff0c;然后是前后台一体化的项目。 安全框架使用的是内置版本的SpringSecurity。 在实际使用过程中遇到一个问题。 就是当用户登陆失效后&#xff0c;前端操作JSON请求获取列表数据&#xff0c;但…

【知识学习/复习】损失函数篇,包含理解应用与分类:回归、分类、排序、生成等任务

损失函数总结 一、损失函数理解二、不同任务的损失函数的应用1.图像分类2.目标检测3.语义分割4.自然语言处理&#xff08;NLP&#xff09;5.图神经网络&#xff08;GNN&#xff09;6.生成式网络 三、损失函数1. 回归任务损失函数常见损失函数IoU系列损失函数1. IoU损失函数&…

微信开发api、微信视频号开发

接口地址&#xff1a; http://api.videostui.com/finder/v2/api/login/checkLogin 接口说明 获取到登录二维码后需每间隔5s调用本接口来判断是否登录成功新设备登录平台&#xff0c;次日凌晨会掉线一次&#xff0c;重新登录时需调用获取二维码且传appId取码&#xff0c;登录成…

Outlook邮箱如何撤回一封已发送邮件?~网页版上

点【已发送邮件】 双击要撤回的已发送的那个邮件 点【…】 点击【撤回消息】 点【确定】 结束&#xff01;

使用LocalGPT+cpolar打造可远程访问的本地私有类chatgpt服务

文章目录 前言环境准备1. localGPT部署2. 启动和使用3. 安装cpolar 内网穿透4. 创建公网地址5. 公网地址访问6. 固定公网地址 前言 本文主要介绍如何本地部署LocalGPT并实现远程访问&#xff0c;由于localGPT只能通过本地局域网IP地址端口号的形式访问&#xff0c;实现远程访问…

【源代码】使用Vision Pro远程操控机器人

1、OpenTeleVision 是一个开源项目&#xff0c;提供远程操作功能 2、可以从 VisionPro 或 Meta Quest 3 中流式传输头部、手部和腕部数据 3、可以将实时立体视频从摄像头流式传输到 VR 设备 4、需要在 Ubuntu 机器上安装 Zed SDK 和 mkcert&#xff0c;以便在本地进行测试 …

全新突破:「Paraverse平行云」实现3D/XR企业级应用全面接入Apple Vision Pro

在前不久举行的GTC开发者大会上&#xff0c;英伟达引领行业风向&#xff0c;宣布其Omniverse平台能够助力企业将3D/XR应用流畅传输至Apple Vision Pro混合现实头显。在英伟达与苹果这两大科技巨头的合作下,此举标志着3D/XR技术迈向新纪元的关键一步。「Paraverse平行云」实时云…

基于STM32单片机的汽车胎压、速度及状态监测系统设计与实现

基于STM32单片机的汽车胎压、速度及状态监测系统设计与实现 摘要&#xff1a; 随着汽车电子技术的快速发展&#xff0c;车辆状态实时监控系统的需求日益增长。本文设计并实现了一种基于STM32单片机的汽车胎压、速度及状态监测系统。该系统能够实时监测汽车的胎压、速度以及其他…

算法设计与分析4.1 迷宫问题 栈与队列解法、打印矩阵、三壶问题、蛮力匹配

1.ROSE矩阵 实现&#xff1a; 使用算法2 分析&#xff1a; 每半圈元素值的增长规律变换一次 设增量为t&#xff0c;每半圈变换一次t <— -t . 设矩阵边长为i&#xff0c;每半圈的元素个数是2*(i-1)个&#xff0c;hc为记数变量&#xff0c;则1≤hc<2i-1&#xff0c;前1/…

ChatGLM2-6B的部署步骤_A3

ChatGLM2-6B 下载地址 一、VisualGLM-6B环境安装 1、硬件配置 操作系统&#xff1a;Ubuntu_64&#xff08;ubuntu22.04.3&#xff09; GPU&#xff1a;4050 显存&#xff1a;16G 2、配置环境 建议最好自己新建一个conda环境 conda create -n chatglm2 python3.8pip …

【go项目01_学习记录day01】

博客系统 1 vscode开发go项目插件推荐1.1 CtrlShiftP&#xff08;俗称万能键&#xff09; &#xff1a;打开命令面板。在打开的输入框内&#xff0c;可以输入任何命令。1.2 开发时&#xff0c;我们需要经常查阅 Go 语言官方文档&#xff0c;可惜因国内访问外网不稳定&#xff0…

STM32开启停止模式,用外部中断唤醒程序运行

今天学习了一下STM32的停止模式&#xff0c;停止模式下&#xff0c;所有外设的时钟和CPU的电源都会被关闭&#xff0c;所以会很省电&#xff0c;打破这种停止模式的方式就是外部中断可以唤醒停止模式。要想实现这个功能&#xff0c;其实设置很简单的&#xff0c;总共就需要两步…

《C语言深度解剖》(10):数组指针、指针数组和数组指针数组

&#x1f921;博客主页&#xff1a;醉竺 &#x1f970;本文专栏&#xff1a;《C语言深度解剖》《精通C指针》 &#x1f63b;欢迎关注&#xff1a;感谢大家的点赞评论关注&#xff0c;祝您学有所成&#xff01; ✨✨&#x1f49c;&#x1f49b;想要学习更多C语言深度解剖点击专栏…

情感类ppt素材

小清新手绘插画风毕业季毕业相册同学录画册纪念册PPT下载 - 觅知网这是一张关于清新毕业相册的PPT模板&#xff0c;清新风格设计&#xff0c;加上风为装饰元素&#xff0c;包含毕业相册、毕业季、毕业、同学、纪念等主题内容&#xff0c;也可用作毕业相册PPT、毕业季PPT、毕业P…

陪诊小程序:温情陪伴,就医无忧

在快节奏的现代生活中&#xff0c;健康问题时常困扰着我们。每当身体出现不适&#xff0c;前往医院就诊便成为了一项必要的任务。然而&#xff0c;面对陌生的医院环境、繁琐的就诊流程&#xff0c;许多人往往会感到无助和困惑。此时&#xff0c;一款贴心的陪诊小程序便显得尤为…

国内首个图计算平台团体标准发布,创邻科技参与编撰

2024年&#xff0c;由中国通信标准协会批准的团体标准《大数据 图计算平台技术要求与测试方法》&#xff08;编号&#xff1a;T/CCSA 470—2023&#xff09;&#xff08;下称&#xff1a;标准&#xff09;正式实施。该标准于1月4日在全国团体标准信息平台&#xff08;https://w…

AI系列:大语言模型的RAG(检索增强生成)技术(上)

前言 大型语言模型&#xff08;LLM&#xff09;虽然在生成文本方面表现出色&#xff0c;但仍然存在一些局限性&#xff1a;数据是静态的&#xff0c;而且缺乏垂直细分领域的知识。为了克服这些限制&#xff0c;有时候会进行进一步的模型训练和微调。在实际应用中&#xff0c;我…
最新文章