与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
package.json:
"scripts": {
"watch": "watchify -g [ babelify --presets [ \"@babel/preset-env\" ] ] client/js/main.js -o public/bundle.js -v ",
为什么?
答案 0 :(得分:0)
感谢@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 ));
...
我也有错误的来源和目标预测。