当前位置:网站首页>【openlayers】Map【1】
【openlayers】Map【1】
2022-07-29 23:22:00 【A row with orange】

基本概念
Map地图
OpenLayers的核心组件是map(ol/map),is rendered into the target container(例如,on the web page that contains the mapdiv元素);All map elements either configure all map properties at construction time
The following markup can be used to create the included map div 元素:
<div id="map" style="width: 100%, height: 400px"></div>
Viewview layer
ViewRefers to the map view layer,Including the center point、缩放等级、Data such as resolution is displayed by layers;
import View from 'ol/View';
map.setView(new View({
center: [0, 0],
zoom: 2
}));
Source数据源
为了获取层的远程数据,OpenLayers使用ol/source/source子类.这些可用于OpenStreetMap或Bingand other free and commercial map tiling services、WMS或WMT等OGC源以及GeoJSON或KML等格式的矢量数据.
import OSM from 'ol/source/OSM';
var osmSource = OSM();
Layer图层
Layers are visual representations of source data,OpenLayers有四种基本类型的层:
ol/layer/Tile:瓦片图层——平铺-The source that provides the tiled image in the render grid,The grid is organized by zoom levels for a specific resolution.
ol/layer/Image:图像——渲染以任意范围和分辨率提供地图图像的源.
ol/layer/Vector:矢量图层——Render vector data on the client side.
ol/layer/VectorTile:矢量瓦片——Data presented as vector tiles.
import TileLayer from 'ol/layer/Tile';
var osmLayer = new TileLayer({
source: osmSource});
map.addLayer(osmLayer);
vue openlayers应用
<template>
<div>
<div class="ol-map" ref="olMap"></div>
<!--可以给元素设置一些样式-->
<div class="ol-popup" ref="olPopup">{
{
olPopupText }}</div>
</div>
</template>
<script>
import Map from "ol/Map";
import View from "ol/View";
import {
Tile as TileLayer } from "ol/layer";
import {
OSM, XYZ, WMTS } from "ol/source";
import {
fromLonLat } from "ol/proj";
import {
defaults as defaultInteractions,
DragRotateAndZoom,
} from "ol/interaction";
import {
defaults, FullScreen, MousePosition, ScaleLine } from "ol/control";
import Overlay from "ol/Overlay";
import {
Vector as VectorLayer } from "ol/layer";
import {
Vector as VectorSource } from "ol/source";
import {
Style, Icon } from "ol/style";
import Feature from "ol/Feature";
import Point from "ol/geom/Point";
import {
Translate } from "ol/interaction";
import {
Draw } from "ol/interaction";
import GeometryType from "ol/geom/GeometryType";
import {
createRegularPolygon, createBox } from "ol/interaction/Draw";
import {
Modify } from "ol/interaction"
export default {
name: "exm1",
data () {
return {
olPopupText: "default text"
}
},
created () {
},
mounted () {
// 使用内置的osm
// const tileLayer = new TileLayer({
// source: new OSM()
// });
// 使用 天地图 的瓦片数据
// const tileLayer = new TileLayer({
// source: new XYZ({
// url: "http://t0.tianditu.gov.cn/img_w/wmts?SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles&TILEMATRIX={z}&TILEROW={x}&TILECOL={y}&tk=9b21fa580b77ebbb20ee6245e2fc96eb"
// })
// })
// ??? 如何加载 wmts 服务, Below is the problematic code
// const tileLayer = new TileLayer({
// source: new WMTS({
// url: "http://t1.tianditu.gov.cn/vec_c/wmts?tk=9b21fa580b77ebbb20ee6245e2fc96eb"
// })
// })
// 使用 高德 的瓦片数据
const tileLayer = new TileLayer({
source: new XYZ({
url: "https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
}),
});
let map = new Map({
layers: [tileLayer],
view: new View({
center: fromLonLat([120.771441, 30.756433]), // 地图中心点
zoom: 15, // 缩放级别
minZoom: 0,
maxZoom: 18,
constrainRotation: true, // 因为存在非整数的缩放级别,所以设置参数true来让每次缩放结束后自动缩放到距离最近的一个整数级别,这个必须要设置,当缩放在非整数级别时地图会糊
}),
target: this.$refs.olMap,
controls: defaults().extend([
new FullScreen(), // 显示全屏
new MousePosition(), // 显示鼠标当前位置的经纬度
new ScaleLine(), // 显示比例尺
]),
});
map.on("click", (e) => {
console.log("地图点击", e);
});
},
};
</script>
<style scope>
.ol-map {
height: 90vh;
}
.ol-popup {
width: 40px;
height: 30px;
font-size: 14px;
text-align: center;
}
</style>
边栏推荐
- 树莓派上安装 wiringPi 2.6 解决 gpio readall 命令的错误
- The second round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
- Analysis of miscellaneous diseases such as DNS domain name hijacking in instant messaging mobile terminal development
- Embedded system driver primary [1] - kernel module _ compilation method
- DNA偶联二维过渡金属硫化物|DNA修饰贵金属纳米颗粒|使用方法
- C语言实现扫雷(9*9)游戏——详解
- SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
- MySQL数据库进阶篇
- 流水线上的农民:我在工厂种蔬菜
- 卧槽,2行代码,让接口性能提升10倍
猜你喜欢

2022年最新甘肃建筑施工焊工(建筑特种作业)模拟题库及答案解析

【微信小程序】一文解忧,事件绑定

Topics in Dynamic Programming

BGP联邦综合实验

一文参透分布式存储系统Ceph的架构设计、集群搭建(手把手)

「大厂必备」系列之Redis主从、持久化、哨兵

Implementation and implementation of Any to Any real-time voice change丨RTC Dev Meetup

运动步数抽奖小程序开发

ah?Now the primary test recruitment requirements will be automated?
![[leetcode] 75. Color classification (medium) (double pointer, in-situ modification)](/img/0e/e4ed76902194755a3b075a73f272f3.png)
[leetcode] 75. Color classification (medium) (double pointer, in-situ modification)
随机推荐
In 2022, the latest Gansu construction staff (material staff) mock exam questions and answers
玻璃表面修饰DNA|DNA修饰的上转换纳米材料|DNA-UCNPs实验原理
How to realize object selection in canvas (5)
C语言实现扫雷(9*9)游戏——详解
pnpm + workspace + changesets 构建你的 monorepo 工程
MQTT over QUIC:下一代物联网标准协议为消息传输场景注入新动力
桌面软件开发框架大赏
SAP UI5 FileUploader 的隐藏 iframe 设计明细
浅析即时通讯移动端开发DNS域名劫持等杂症
[C] list explanation (headless ChanXiangFei cycle)
文档贡献与写作必读-OpenHarmony开发者文档风格指南
纳米金颗粒修饰核酸产品|碳纳米管载核酸-DNA/RNA材料|解析说明
我们上线了一个「开发者实验室」
卧槽,2行代码,让接口性能提升10倍
Mysql8.0新特性之详细版本
流水线上的农民:我在工厂种蔬菜
高数下|三重积分的计算3|高数叔|手写笔记
BGP Federal Comprehensive Experiment
canvas 中如何实现物体的点选(五)
Super RVRT