代码之家  ›  专栏  ›  技术社区  ›  minisaurus

Openlayers项目未定义问题

  •  0
  • minisaurus  · 技术社区  · 6 年前

    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
    

      "scripts": {
        "watch": "watchify -g [ babelify --presets [ \"@babel/preset-env\" ] ] client/js/main.js -o public/bundle.js -v ",
    

    为什么?

    1 回复  |  直到 6 年前
        1
  •  0
  •   minisaurus    6 年前

    感谢@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 ));
    ...
    

    推荐文章