OpenLayers地图控件controls

1) fullscreen全屏控件

OpenLayers地图控件controls

 

 

写法一

 

import { FullScreen } from "ol/control";

this.map.addControl(new FullScreen());

 

写法二

 

import { defaults as defaultControls, FullScreen } from "ol/control";

controls: defaultControls({
    zoom: false,
    rotate: false,
    attribution: false 
}).extend([
    new FullScreen()
]

 

2) mouseposition鼠标位置控件

OpenLayers地图控件controls

import MousePosition from "ol/control/MousePosition";
import { createStringXY } from "ol/coordinate";
var mousePositionControl = new MousePosition({
    //坐标格式
    coordinateFormat: createStringXY(5),
    //地图投影坐标系(若未设置则输出为默认投影坐标系下的坐标)
    projection: "EPSG:4326",
    //坐标信息显示样式类名,默认是‘ol-mouse-position‘
    className: "custom-mouse-position",
    //显示鼠标位置信息的目标容器
    target: document.getElementById("mouse-position"),
    //未定义坐标的标记
    undefinedHTML: " ",
});
this.map.addControl(mousePositionControl);

OpenLayers地图控件controls

import MousePosition from "ol/control/MousePosition";
import { format } from "ol/coordinate";

var mousePositionControl = new MousePosition({
    //坐标格式
    coordinateFormat: function (coordinate) {
        return format(coordinate, "经度:{x}   纬度:{y}", 2);
    },
    //地图投影坐标系(若未设置则输出为默认投影坐标系下的坐标)
    projection: "EPSG:4326",
    //坐标信息显示样式类名,默认是‘ol-mouse-position‘
    className: "custom-mouse-position",
    //显示鼠标位置信息的目标容器
    target: document.getElementById("mouse-position"),
    //未定义坐标的标记
    undefinedHTML: " ",
});
this.map.addControl(mousePositionControl);              

3) overviewmap 地图全局视图(鹰眼图)控件

 OpenLayers地图控件controls

import { defaults as defaultControls, OverviewMap } from "ol/control";

var overviewMapControl = new OverviewMap({
    layers: [
        new TileLayer({
            source: new OSM(),
        })
    ]
});

controls: defaultControls({ zoom: true }).extend([
    overviewMapControl
])        

4) scaleline 比例尺控件

OpenLayers地图控件controls

import { ScaleLine } from "ol/control";

this.map.addControl(new ScaleLine());

5) zoom缩放控件

OpenLayers地图控件controls

controls: defaultControls({
    zoom: true,
}).extend([]),

6) zoomslider缩放滑块刻度控件

 OpenLayers地图控件controls

import { ZoomSlider } from "ol/control";

this.map.addControl(new ZoomSlider());

7) Rotate地图旋转控件

(shift+alt+鼠标旋转地图)

OpenLayers地图控件controls

import { Rotate } from "ol/control";

this.map.addControl(new Rotate());

8) ZoomToExtent缩放到全局控件

OpenLayers地图控件controls

import { ZoomToExtent } from "ol/control";

this.map.addControl(new ZoomToExtent());

 

OpenLayers地图控件controls

上一篇:Swing开发之JComboBox篇


下一篇:Git拉取代码报:ssh_dispatch_run_fatal: Connection to *** port 22: message authentication code incorrect