鹰眼图控件
鹰眼图控件示例。 鹰眼 鹰眼图
本示例演示了 OverviewMap 控件的用法。主地图和鹰眼图都配置了使用同一数据源的图层。请注意,必须为鹰眼图显式配置图层。
main.js
js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import OverviewMap from 'ol/control/OverviewMap.js';
import {defaults as defaultControls} from 'ol/control/defaults.js';
import TileLayer from 'ol/layer/Tile.js';
import OSM from 'ol/source/OSM.js';
const source = new OSM();
const overviewMapControl = new OverviewMap({
layers: [
new TileLayer({
source: source,
}),
],
});
const map = new Map({
controls: defaultControls().extend([overviewMapControl]),
layers: [
new TileLayer({
source: source,
}),
],
target: 'map',
view: new View({
center: [500000, 6000000],
zoom: 7,
}),
});index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>鹰眼图控件</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script type="module" src="main.js"></script>
</body>
</html>package.json
json
{
"name": "overviewmap",
"dependencies": {
"ol": "10.11.0"
},
"devDependencies": {
"vite": "^8.1.5"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}