OpenLayers+React+GeoServer 地图开发记录
引入Openlayers
npm install ol -S
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import {
Circle as CircleStyle, Fill, Stroke, Style, Icon } from 'ol/style';
import {
Draw, Snap} from 'ol/interaction';
import {
Vector as VectorSource } from 'ol/source';
import {
Tile as TileLayer, Vector as VectorLayer, Image } from 'ol/layer';
import ImageWMS from 'ol/source/ImageWMS';
import XYZ from 'ol/source/XYZ';
import {
get} from 'ol/proj';
import Feature from 'ol/Feature';
import Polygon from 'ol/geom/Polygon';
import Overlay from 'ol/Overlay';
import {
getArea } from 'ol/sphere';
初始化
var projection = get('EPSG:4326');
const myImageLoader = new Image({
source: new ImageWMS({
url: '',
params: {
LAYERS: '',
VERSION: '1.1.1',
SERVICE: 'WMS',
REQUEST: 'GetMap',
FORMAT: 'image/jpeg',
exceptions: 'application/vnd.ogc.se_inimage',
},
serverType: 'geoserver',
}),
extent: [minx, miny, maxx, maxy],
zIndex: 3,
title: '卫星',
});
var tian_di_tu_satellite_layer = new TileLayer({
title: '天地图卫星影像',
visible: true,
source: new XYZ({
url:
'http://t4.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=你的key',
}),
zIndex: 2,