叶子让文档说:
import * as L from 'leaflet';
GeoJSON 层 GeoJSON 对象通过 GeoJSON 图层添加到 map 中。要创建它并将其添加到 map 中,我们可以使用以下代码:
ngOnInit{
L.GeoJSON(geojsonFeature).addTo(myfrugalmap);
}
The geojson is drawn but i receive an error :
ERROR in src/app/geo/geo.component.ts(335,11): error TS2345: Argument
of type '{ "type": string; "features": ({ "type": string; "geometry":
{ "type": string; "coordinates": num...' is not assignable to
parameter of type 'GeoJsonObject'. Property 'type' is missing in
type '{ "type": string; "features": ({ "type": string; "geometry": {
"type": string; "coordinates": num...'.
我可以忽略这个错误吗?
最佳答案
类型声明中不存在 amenity 和 popupContent
应该是:
import * as L from 'leaflet';
var geojsonFeature = {
"type": "Feature",
"properties": {
"name": "Location B",
"category": "House"
},
"geometry": {
"type": "Point",
"coordinates": [-104.99404, 39.75621]
}
};
ngOnInit{
L.geoJSON(geojsonFeature).addTo(map); // or L.geoJSON([geojsonFeature]).addTo(map);
}
关于javascript - 类型为 'GeoJsonObject' 的 STRING 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52220305/