Commit 2533a109 by dliangx

使用高德地图作为数据源

parent 70796814
...@@ -6,22 +6,27 @@ import TileLayer from 'ol/layer/Tile'; ...@@ -6,22 +6,27 @@ import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM'; import OSM from 'ol/source/OSM';
import 'ol/ol.css'; import 'ol/ol.css';
import './Land.css' import './Land.css'
import XYZ from "ol/source/XYZ";
const Land = ()=>{ const Land = ()=>{
const mapRef = useRef(null); const mapRef = useRef(null);
const gaodeSource = new XYZ({
url: 'https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
});
const gaodeLayer = new TileLayer({
source: gaodeSource,
});
useEffect(() => { useEffect(() => {
if (mapRef.current) { if (mapRef.current) {
const map = new Map({ const map = new Map({
target: mapRef.current, target: mapRef.current,
layers: [ layers: [
new TileLayer({ gaodeLayer
source: new OSM(),
}),
], ],
view: new View({ view: new View({
center: [0, 0], center: [0, 0],
zoom: 2, zoom: 3,
}), }),
}); });
......
import Footer from "../common/Footer" import Footer from "../common/Footer";
import { useEffect, useRef } from "react";
import Map from "ol/Map";
import View from "ol/View";
import TileLayer from "ol/layer/Tile";
import "ol/ol.css";
import XYZ from "ol/source/XYZ";
const Layers = () => {
const mapRef = useRef(null);
const gaodeSource = new XYZ({
url: "https://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}",
});
const Layers = ()=>{ const gaodeLayer = new TileLayer({
return(<> source: gaodeSource,
});
useEffect(() => {
if (mapRef.current) {
const map = new Map({
target: mapRef.current,
layers: [gaodeLayer],
view: new View({
center: [0, 0],
zoom: 3,
minZoom: 3, // 设置最小缩放等级为 5
maxZoom: 18, // 设置最大缩放等级为 15
}),
});
return () => {
map.setTarget();
};
}
}, []);
return (
<>
<div ref={mapRef} className=" bottom-14 top-0 w-full absolute"></div>
<Footer></Footer> <Footer></Footer>
</>) </>
} );
};
export default Layers; export default Layers;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment