当前位置:网站首页>【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>
边栏推荐
- 【MySQL系列】 MySQL表的增删改查(进阶)
- 【2023校招刷题】常见面试问题总结(七、常见总线协议篇)(随后续面试不断更新....)
- NetWorker Knowledge Corner|Easy to get an offer [Networker Interview Questions] What is the difference between a Layer 3 switch and a router?
- 玻璃表面修饰DNA|DNA修饰的上转换纳米材料|DNA-UCNPs实验原理
- 云计算1+X之openstack篇
- 地狱挖掘者系列#1
- The Sandbox 与 Gravity 达成合作,将《RO仙境传说》带入元宇宙
- SAP ABAP Netweaver 容器化的一些前沿性研究工作分享
- 【面试:并发篇29:多线程:volatile】原理
- Mysql内外连接
猜你喜欢
Mysql8.0新特性之详细版本
LabVIEW为什么在存储VI时死机
The first round of the real offer harvester~ How does the big factory inspect the candidates?(with detailed answer)
一个print函数,挺会玩啊?
Super RVRT
MQTT over QUIC: The Next-Generation IoT Standard Protocol Brings New Impetus to Messaging Scenarios
MySQL数据库进阶篇
J9数字论:为什么我们需要Web3?
Farmers on the assembly line: I grow vegetables in a factory
【无标题】清空吗
随机推荐
J9数字论:为什么我们需要Web3?
Farmers on the assembly line: I grow vegetables in a factory
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
Three chess (written in C language)
Super RVRT
【openlayers】地图【二】
y81.第四章 Prometheus大厂监控体系及实战 -- 监控扩展(十二)
JetsonNano学习(六)Jetson踩过的大坑及解决方法___持续更新
WeChat applet sliding navigation bar (how to set the floating window of the webpage)
DNA修饰的上转换纳米材料|聚胞苷酸Poly-C DNA修饰的氧化石墨烯|解析说明
esp12f + tft display picture problem
BGP Federal Comprehensive Experiment
资源集合
50. Leetcode 】 【 Pow (x, n) (medium) (power) quickly
[leetcode] 80. Delete duplicates in sorted array II (medium) (double pointer, in-place modification)
SAP ABAP 守护进程的实现方式
WSDM‘22推荐系统论文梳理
「大厂必备」系列之Redis主从、持久化、哨兵
使用 Neuron 接入 Modbus TCP 及 Modbus RTU 协议设备
MySQL active/standby switch