0

I'm drawing circles on a map based on lon/lat. These circles are drawn from "subarrays" in an array, e.g:

myArray = [[array(18)]],[array(111)], [array(65)]....]

I map each of these arrays using GeoJSON like this:

var geojsonlatObject = {
        'type': 'FeatureCollection',
            'crs': {
                'type': 'name',
                'properties': {
                'name': 'EPSG:4326'
            }
        },
        'features':
            [{
                'type': 'Feature',
                'geometry': {
                    'type': 'MultiPoint',
                    'coordinates': circlecoordinates().map(function (x) {
                        //console.log(x[0][0]);
                        //console.log(x[0][1]);
                        return ol.proj.transform([x[0][0], x[0][1]], 'EPSG:4326', 'EPSG:3857')
                    })
                }
            }]
    };

Further, I have a style like this:

    var locationandtransitstyle = new ol.style.Style({

        text: new ol.style.Text({
            text: String(resultArray.length),//this.length,//'15',
            scale: 1.7,
            fill: new ol.style.Fill({
                color: '#ffffff'
            })
        }),
        image: new ol.style.Circle({
        radius: 15,
        fill: new ol.style.Fill({
            color: 'rgba(30,144,255,0.7)'
        })             
      })
    })

The result of this is that I have the length of myArray in each circle. But I want the length of the subarrays as text inside the circles. Any ideas on how to do this?

My thoughts at the moment is that I can add use the "properties" option in GeoJSON, https://tools.ietf.org/html/rfc7946, but I don't know how to implement it for each feature...

    ......."coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "***for-circle add array lenght***"
  }

UPDATE

After some more experimenting i came to the following: I can log length of the subarrays by:

console.log(x.length);

inside my map function. Can i use that to set this value to a properti??:

'type': 'Feature',
                'geometry': {
                    'type': 'MultiPoint',
                    'coordinates': circlecoordinates().map(function (x) {
                        console.log(x[0][0]);
                        console.log(x[0][1]);
                        console.log(x.length);
                        return ol.proj.transform([x[0][0], x[0][1]], 'EPSG:4326', 'EPSG:3857')
                    })
                },
                "properties": {
                    "name": "...value of x.length..."
                }
            }]

Is it possible to do this, or will it not work? Do i need a .map()-function in for the property as well?

Alternatively:

properties": {
                    "name": circlecoordinates().map(function (x) {
                         return    x.length
                            }
                }
0

As for now i think the answer to my question is here: Encoding properties for each point in a GeoJSON multipoint

So, i will abandon current path, and try to restructure my data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.