当前位置:网站首页>【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>
边栏推荐
- 玻璃表面修饰DNA|DNA修饰的上转换纳米材料|DNA-UCNPs实验原理
- 树莓派上安装 wiringPi 2.6 解决 gpio readall 命令的错误
- JetsonNano learning (6) Big pits and solutions that Jetson stepped on___Continuously updated
- JetsonNano学习(六)Jetson踩过的大坑及解决方法___持续更新
- 浅析即时通讯移动端开发DNS域名劫持等杂症
- MySQL数据库进阶篇
- The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
- cached_network_image 多个图片卡顿崩溃
- 真offer收割机 第二弹~大厂如何考察候选人?(附答案详解)
- 高数下|三重积分的计算3|高数叔|手写笔记
猜你喜欢

2022年最新甘肃建筑八大员(材料员)模拟考试试题及答案

MQTT over QUIC:下一代物联网标准协议为消息传输场景注入新动力

Foxmail是什么邮箱?

PyCharm使用教程(详细版 - 图文结合)

Gao Shu Xia|Triple Integral Exercises|Uncle Gao Shu|Handwritten Notes

We launched a "developer lab"

高数下|三重积分的计算3|高数叔|手写笔记

MySQL Interview Questions: Detailed Explanation of User Amount Recharge Interview Questions

DNA修饰碱基5-甲基胞嘧啶和8-羟基鸟嘌呤|DNA修饰量子点|规格信息

MQTT over QUIC: The Next-Generation IoT Standard Protocol Brings New Impetus to Messaging Scenarios
随机推荐
通过 FileUploader 的初始化,了解 SAP UI5 应用的 StaticArea 初始化逻辑
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
浅析即时通讯移动端开发DNS域名劫持等杂症
地狱挖掘者系列#1
DNA脱氧核糖核酸修饰四氧化三铁|DNA修饰氧化锌|使用方法
Foxmail是什么邮箱?
How to make labview an application (labview program recognizes shapes)
[leetcode] 82. Delete duplicate elements in sorted linked list II (medium)
暴力递归到动态规划 03 (背包问题)
JetsonNano learning (6) Big pits and solutions that Jetson stepped on___Continuously updated
2022年最新甘肃建筑施工焊工(建筑特种作业)模拟题库及答案解析
@Autowired与@Resource区别
BGP Federal Comprehensive Experiment
The Sandbox Partners with Gravity to Bring RO Ragnarok to the Metaverse
DNA脱氧核糖核酸修饰石墨粉末|DNA修饰还原石墨烯功能材料|保存温度
The sequence table of the linear table (the dry goods are full of sharing ~ contains all the function codes of the sequence table~
[C] list explanation (headless ChanXiangFei cycle)
【2023校招刷题】笔试及面试中常考知识点、手撕代码总结
Elementary C language - first understanding of C language
在树莓派上安装 PyCharm