0

in the below posted code, i want to pass the parameter keyGridsAsGeoJSON as input to the function in style attribute.every time i print the value of k which is var k = keyGridsAsGeoJSON i receive the values posted below. i expect that k contains values which contained in keyGridsAsGeoJSON. the values in keyGridsAsGeoJSON are as shown in the image below.

please let me know why the contents of k is not as the contents of keyGridsAsGeoJSON

values in keyGridsAsGeoJSON enter image description here

value of k:

k: RenderFeature {id_: undefined, type_: 'Polygon', flatCoordinates_: Array(10), flatInteriorPoints_: null, flatMidpoints_: null, …}
    ends_: [10]
    flatCoordinates_: (10) [738401.380994772, 6643445.99157804, 738417.2804938197, 663446.495435405, 38417.7843511839, 643430.558613589, 738401.035135203, 6643430.054756225, 73841.3809947722, 643445.99157804]
    flatInteriorPoints_: null
    flatMidpoints_: null
    id_: undefined
    properties_: {layer: 'default'}
    type_: "Polygon"
    [[Prototype]]: Object
    

code:

public visualisePolygonsAsMVTTilesOnMapWithColors(map,keyGridsAsGeoJSON,fillColor,strokeColor,text){
    var features = [];
    var iter = 0
    var k = keyGridsAsGeoJSON
    console.log("keyGridsAsGeoJSON:",keyGridsAsGeoJSON)
    keyGridsAsGeoJSON.forEach(function(keyGridAsGeoJSON) {
        let polygonGeometry = [keyGridAsGeoJSON['features'][0]['geometry']]
        polygonGeometry.forEach(function(geojson) {
            var geometry = new GeoJSON().readGeometry(geojson, {
                dataProjection: 'EPSG:4326',
                featureProjection: map.getView().getProjection()
                });
                features.push(new Feature(geometry));
            });
        });
    var vectorTile = new VectorTileLayer({
        source: new VectorTileSource({
            format: new MVT(),
            url: environment.LocalHostForTileLayerSourceAsMVTTileForZXYWS + "/{z}/{x}/{y}"
        }),
        style: function (k){
            console.log("features:",features)
            console.log("k:",k)
        }
      });
    return vectorTile;
}
Amrmsmb
  • 1
  • 27
  • 104
  • 226
  • The renderer calls the style function as it renders each feature. k is the feature being rendered. – Mike Nov 17 '21 at 10:51
  • thanks. do you mean that even if i did not pass an parameter to the style function, still i can access each feature in it? – Amrmsmb Nov 17 '21 at 10:56
  • The style function is called by the renderer, not by your code. Every call is passed one feature. If you `console.log("k:",k.getProrties()) ` you will see the properties which can be used to distinguish between features and return a style specific to that feature. – Mike Nov 17 '21 at 11:54

0 Answers0