Proj4Leaflet棱角分明5

时间:2018-03-27 12:37:58

标签: angular leaflet angular5

我读了不同的主题,但它不起作用。 我想使用leaftlet和Proj4Leaflet在角项目中投影espg

import * as L from 'Proj4Leaflet';
const crs = new L.Proj.CRS('EPSG:3006',
'+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs',
{
  resolutions: [
    8192, 4096, 2048, 1024, 512, 256, 128
  ],
  origin: [0, 0]
});

const myMap = L.map('map').setView([46.2, 2], 6);
myMap.options.crs = crs;
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
   attribution: 'My Map'
}).addTo(myMap);

this.http.get('../assets/data.json')
.subscribe(data => {
  console.log(data);
  const lMyGeoJson = L.geoJSON(<any>data, <any>{
    style: function(feature, layer) {
      return {
        weight: 1,
        opacity: 1,
        color: '#66CC66'
      };
    }
  }).addTo(myMap);

  console.log(lMyGeoJson);
} );

地图无法显示,执行时出错

  

TypeError:L.map不是函数

先谢谢

1 个答案:

答案 0 :(得分:0)

您还需要导入@types/proj4leaflet包。它包含导出的Proj4Leaflet代码的TypeScript声明。

// In package.json
...
"@types/proj4leaflet": "^1.0.5",
...
"proj4leaflet": "^1.0.2",
...

// In .angular-cli.json
"../node_modules/proj4leaflet/lib/proj4.js",
"../node_modules/proj4leaflet/src/proj4leaflet.js",

// In your app.module.ts
declare var require: any;
require('proj4leaflet');

// Importing in your .ts code
import {Map, Proj} from "leaflet";

// Creating the CRS:
let crs = new Proj.CRS(...);

编辑虽然

仍然不适合我