Projects the geometry
EPSG:4326 投影到 EPSG:3857
webMercatorUtils.geographicToWebMercator()
import * as webMercatorUtils from '@arcgis/core/geometry/support/webMercatorUtils.js'
const geometry3857 = webMercatorUtils.geographicToWebMercator(geometry4326)
EPSG:4490 投影到 EPSG:3857
无法使用 webMercatorUtils.project()
方法。
该方法在客户端执行投影计算。
const res = webMercatorUtils.canProject(
new SpatialReference({ wkid: 4490 }),
new SpatialReference({ wkid: 3857 }) // SpatialReference.WebMercator
)
console.log('res:', res); // res: false
使用 geometryService.project()
进行投影。
https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-geometryService.html#project
https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-support-ProjectParameters.html
https://developers.arcgis.com/javascript/latest/sample-code/widgets-coordinateconversion-custom/
该方法在服务端执行投影计算。
import ProjectParameters from '@arcgis/core/rest/support/ProjectParameters.js'
import * as geometryService from '@arcgis/core/rest/geometryService.js'
const projectParams = new ProjectParameters({
geometries: [geometry4490],
outSpatialReference: new SpatialReference({ wkid: 3857 })
})
const URL4GeometryService = 'https://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer'
geometryService.project(URL4GeometryService, projectParams).then(res => {
// res is an array of projected geometries.
})