openlayer中默认投影为3857.
引入:
import { fromLonLat, transform } from "ol/proj";
fromLonLat()
4326转为3857
view: new View({
projection: "EPSG:3857",//默认为 3857,可以不写
center: fromLonLat([104.29806, 30.5263]),// 数据格式4326转为3857
zoom: 18,
}),
transform()
4326转为3857:
center: transform([104.29806, 30.5263], "EPSG:4326", "EPSG:3857"), // 4326转为3857
3857转为4326:
center: transform(
[11610166.571302196, 3571423.5855320557],
"EPSG:3857",
"EPSG:4326"
), // 3857转为4326