babeljs - Openlayers proj 未定义问题
问题描述
与 browserify 和 babel 捆绑的 Openlayers (5.1.3) 应用程序:
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import {bbox} from 'ol/loadingstrategy';
import proj from 'ol/proj';
...
var source = new VectorSource({
loader: function( extent, resolution, projection ) {
var crs = config.crs || "EPSG:4326";
var url = '/rest/table/' + config.table;
var newExtent = proj.transformExtent( extent, proj.get( crs ), proj.get('EPSG:3857'));
...
错误:
Uncaught TypeError: Cannot read property 'transformExtent' of undefined
包.json:
"scripts": {
"watch": "watchify -g [ babelify --presets [ \"@babel/preset-env\" ] ] client/js/main.js -o public/bundle.js -v ",
为什么?
解决方案
感谢@Mike https://stackoverflow.com/users/10118270/mike - 这是更新的代码:
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import {bbox} from 'ol/loadingstrategy';
import {get as getProjection, transformExtent} from 'ol/proj';
...
var source = new VectorSource({
loader: function( extent, resolution, projection ) {
var crs = config.crs || "EPSG:4326";
var url = '/rest/table/' + config.table;
var newExtent = transformExtent( extent, getProjection('EPSG:3857'), getProjection( crs ));
...
我也有错误的源和目标预测。
推荐阅读
- google-sheets-formula - 我想比较股票价格和止损并通过电子邮件提醒我
- excel - 将 jpg excel 传输到 power point python
- scala - 如何解决此类型不匹配错误?
- email - 我正在尝试使用 smtp 协议通过 telnet 发送电子邮件,但在“MAIL FROM:”之后遇到错误响应
- r - 如何在 R 中将彩色丝带放到时间序列图上
- python - 如何在 Python 中实现以下双曲函数?
- excel - 按名称重命名多个文件 Excel VBA
- php - 制作 CRUD 应用程序时与 php 中的 mysqli 相关的错误
- c - 无法在循环双向链表中插入元素
- bash - Shell 脚本:从目录中获取最新文件(扩展名)