Fed*_*lla 4 geojson leaflet angular ngx-leaflet
我正在开发一个 angular 应用程序,它使用传单地图来显示一些图层,我正在尝试使用 GeoJSON,但我无法创建 L.geoJSON 图层。我试图添加一个观点,我发现的每一个资源都告诉我要创建这个结构:
import { geoJSON } from 'leaflet';
geoJSON({
type: "Point",
coordinates: [lat,long]
});
Run Code Online (Sandbox Code Playgroud)
但是当我提供应用程序时,我收到此错误:
Argument of type '{ type: "Point"; coordinates: number[]; }' is not assignable to parameter of type 'GeoJsonObject'.
Object literal may only specify known properties, and 'coordinates' does not exist in type 'GeoJsonObject'.
Run Code Online (Sandbox Code Playgroud)
唯一的其他属性type是bbox?.
我确定我做错了什么,但我真的不明白是什么。
使用
"leaflet": "^1.3.1"
"@types/leaflet": "^1.2.5"
"@asymmetrik/ngx-leaflet": "^3.0.2"
Run Code Online (Sandbox Code Playgroud)
Leaflet 的类型化定义指定geoJSON工厂接受GeoJSON 对象( spec ) 作为第一个参数。
您作为第一个参数传递的对象是一个Point类型Geometry Object ( spec ),它扩展了 GeoJSON 对象。因此,您应该通过简单地将对象显式声明为geojson.Point:
import { geoJSON } from 'leaflet';
import * as geojson from 'geojson';
geoJSON(<geojson.Point>{
type: "Point",
coordinates: [lng, lat] // Note that in GeoJSON, order is [LONG, LAT]
});
Run Code Online (Sandbox Code Playgroud)
JavaScript 中的 Leaflet 实际上接受更多类型作为L.geoJSON工厂的第一个参数:
FeatureCollection,Feature或几何对象)| 归档时间: |
|
| 查看次数: |
3086 次 |
| 最近记录: |