我读到了不同的话题,但不起作用。我想用传单和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不是一个函数
提前谢谢
发布于 2018-03-27 20:57:30
您还需要导入@types/proj4leaflet包。这包含导出的Proj4Leaflet代码的Proj4Leaflet声明。
// 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(...);不过,编辑仍然不适合我
https://stackoverflow.com/questions/49513063
复制相似问题