as shown in the below posted code, i create a VectorTileLayer
and the VectorTileSource
is MVT
geometry that is retrieved from a webservice as stated in the url
attribute.
the database table contains the columns as shown below. For each zoom-in and -out or dragging event the webservice will be called and retrieve the matching/correspnding tiles according to x
,y
and zoom z
.
what the webservice provides to the VectorTileSource
is a row of the table grid_cell_data
.
now, for each rendered feature the function style
will be called.
what i want to achieve is, to have access to the rendered-feature properties/attributes which are, for example, isTreatment
, fourCornersRepresentativeToBufferAsGeoJSON
and so on.
i added logs in the style-function as shown below, but none of the columns in the table mentioned below are accessible. in other words, the name of the columns of the table are not set as a properties to the rendered feature.
the rendered feature should be a row contains all information.
please let me know how to access the feature properties
i also added an image shows the output of the logs mentioned in style-function.
code:
public visualisePolygonsAsMVTTilesOnMapWithColors(map,keyGridsAsGeoJSON,fillColor,strokeColor,text){
var vectorTile = new VectorTileLayer({
source: new VectorTileSource({
format: new MVT(),
url: environment.LocalHostForTileLayerSourceAsMVTTileForZXYWS + "/{z}/{x}/{y}",
}),
style: function (feature,resolution){
console.log("feature:",feature)
console.log("feature.getProperties():",feature.getProperties())
}
});
return vectorTile;
}
postgresql database table
CREATE TABLE IF NOT EXISTS grid_cell_data (
id SERIAL PRIMARY KEY,
isTreatment boolean,
isBuffer boolean,
fourCornersRepresentativeToTreatmentAsGeoJSON text,
fourCornersRepresentativeToBufferAsGeoJSON text,
distanceFromCenterPointOfTreatmentToNearestEdge float8,
distanceFromCenterPointOfBufferToNearestEdge float8,
areasOfCoveragePerWindowForCellsRepresentativeToTreatment float8,
areasOfCoveragePerWindowForCellsRepresentativeToBuffer float8,
averageHeightsPerWindowRepresentativeToTreatment float8,
averageHeightsPerWindowRepresentativeToBuffer float8,
geometryOfCellRepresentativeToTreatment geometry,
geometryOfCellRepresentativeToBuffer geometry
)
contents of rendered feature
i solved it. the problem was in the select
statement. the select
statement must contain the columns name as follows:
query_1
query="""
SELECT
ST_AsMVT(mvtGeometryRow, 'MVTGeometryRow', 4096, 'geom') as result
FROM (
SELECT
isTreatment,isbuffer,fourCornersRepresentativeToTreatmentAsGeoJSON,fourCornersRepresentativeToBufferAsGeoJSON,distanceFromCenterPointOfTreatmentToNearestEdge,
distanceFromCenterPointOfBufferToNearestEdge,areasOfCoveragePerWindowForCellsRepresentativeToTreatment,areasOfCoveragePerWindowForCellsRepresentativeToBuffer,averageHeightsPerWindowRepresentativeToTreatment,
averageHeightsPerWindowRepresentativeToBuffer,geometryOfCellRepresentativeToTreatment,geometryOfCellRepresentativeToBuffer,
ST_AsMVTGeom(
geometryOfCellRepresentativeToTreatment,ST_MakeEnvelope(%s,%s,%s,%s,4326),4096,0,false) As geom
FROM grid_cell_data where geometryOfCellRepresentativeToTreatment <> 'POLYGON EMPTY' and fourCornersRepresentativeToTreatmentAsGeoJSON <> '' and fourCornersRepresentativeToTreatmentAsGeoJSON IS NOT null
) mvtGeometryRow
"""
the following query is valid but the columns names will not appear as properties of the rendered-feature:
query = """
WITH j AS (
SELECT ST_AsMVTGeom(
geometryOfCellRepresentativeToBuffer,
ST_MakeEnvelope(%s,%s,%s,%s,4326),4096,0,false
) As MVTGeom
FROM grid_cell_data where geometryOfCellRepresentativeToBuffer <> 'POLYGON EMPTY' and fourCornersRepresentativeToBufferAsGeoJSON <> '' and fourCornersRepresentativeToBufferAsGeoJSON IS NOT NULL
)
SELECT ST_AsMVT(j.*) FROM j;
"""