记录openlayers加载后端返回的json,不显示的问题
说明:一开始从postgresql返回的geojson,显出不出来,一共有三个问题。
- geojson中中feature中改成features,
- geojson中设置crs,坐标系,4326
- features加上[]
- 设置坐标系转化,因为openlayers使用的是3857
查询语句
cursor.execute(f’’’
SELECT json_build_object(
‘type’, ‘FeatureCollection’,
‘crs’, json_build_object(
‘type’, ‘name’,
‘properties’, json_build_object(
‘name’, ‘EPSG:4326’
)
),
‘features’, jsonb_agg (json_build_object(
‘type’, ‘Feature’,
‘id’, id,
‘geometry’, ST_AsGeoJSON(geom)::json,
‘properties’, json_build_object(
‘feat_type’, type,
‘feat_area’, ST_Area(geom)
)
)
)
)
FROM {tableName} where
ST_Contains(geom,st_geometryfromtext(‘POINT({lat} {lon})’, 4326))’’’
)