kaito
kaito

Reputation: 291

How to get properties from feature without event listener? (event.feature)

how to get the "feature" data from a layer (loaded with geoJSON) without event listener?

thats the usual way, which works fine:

layer1.addListener('mouseover', function (event) {
    console.log( event.feature.getProperty('description') );
}

but now i want to get the value from data object "layer1".

i tried already this:

layer1.getProperty('description')
layer1.feature.getProperty('description')

The way how i load the geoJSON

var layer1 = new google.maps.Data();
layer1 = loadGeoJson('https://googledrive.com/host/MYFILE')

The content of json

Here a short question btw: if i have more features (e.g polygons) in my json, can i get this values to manipulate (e.g. toggle visibility) it?

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    12.3456789,
                    01.2345678,
                    0
                ]
            },
            "properties": {
                "name": "Test Polygon",
                "description": "My Test Description"
            }
        }
    ]
}

Upvotes: 0

Views: 1087

Answers (1)

geocodezip
geocodezip

Reputation: 161334

To get all the features of a google.maps.Data Layer, use:

forEach(callback:function(Data.Feature))

Return Value: None

Repeatedly invokes the given function, passing a feature in the collection to the function on each invocation. The order of iteration through the features is undefined.

or to get a single feature (if you know the Id):

getFeatureById(id:number|string)

Return Value: Data.Feature|undefined

Returns the feature with the given ID, if it exists in the collection. Otherwise returns undefined.

Note that the IDs 1234 and '1234' are equivalent. Either can be used to look up the same feature.

Upvotes: 1

Related Questions