五章-55-鼠标拖拽以旋转和缩放地图
2020-03-27 本文已影响0人
彩云飘过
本文基于腾讯课堂老胡的课《跟我学Openlayers--基础实例详解》做的学习笔记,使用的openlayers 5.3.x api。
源码 见 1055.html ,对应的 官网示例
https://openlayers.org/en/latest/examples/drag-rotate-and-zoom.html?q=drag
https://openlayers.org/en/latest/examples/full-screen-drag-rotate-and-zoom.html?q=drag
按住Shift并使用鼠标拖拽可以旋转、缩放地图
image.png image.png<!DOCTYPE html>
<html>
<head>
<title>鼠标拖拽</title>
<link rel="stylesheet" href="../include/ol.css" type="text/css" />
<script src="../include/ol.js"></script>
</head>
<style></style>
<body>
<div>  按住Shift并使用鼠标拖拽可以旋转、缩放地图</div>
<div id="map" class="map"></div>
<script>
var map = new ol.Map({
interactions: ol.interaction.defaults().extend([new ol.interaction.DragRotateAndZoom()]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: "map",
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
</script>
</body>
</html>