vue-mapbox icon indicating copy to clipboard operation
vue-mapbox copied to clipboard

FeatureCollection in GeoJSON file possible?

Open snsxn opened this issue 5 years ago • 2 comments

I can’t figure out how to load a geojson file with an array of multiple features as featurecollection. Maybe it can’t do it?

snsxn avatar Mar 07 '20 10:03 snsxn

It would really help if the documentation had working examples. FeatureCollections do work. Have you tried validating the geojson? http://geojson.io/ http://geojsonlint.com/

Your geojson source should look something like this:

{
	data: {
		features: [
			{
				geometry: {
					coordinates: [
						[longitude, latitude]
					],
					type: "Point" // or some other valid geojson type
				},
				properties: {},
				type: "Feature"
			}
		],
		id: "some-id"
		type: "FeatureCollection"
	},
	type: "geojson"
}

rognstad avatar Apr 02 '20 16:04 rognstad

Documentation definitely needs working examples please! The main site is out of date (or just not working).

I got it working with the following:

import { parse } from 'wellknown'

export default {
    computed: {
        layerConfig() {
            return { type: 'fill', paint: { 'fill-color': '#ff0000', 'fill-opacity': 0.1 } };
        },
        source() {
            const geoJson = parse('POLYGON((7.109374999999982 51.55050197847774,12.382812499999982 53.16067087751812,13.085937499999982 42.213139626323134,-2.9101562500000178 52.093749599982466,4.208984374999982 52.470132527618325,7.109374999999982 51.55050197847774))'),
            return { type: 'geojson', data: geoJson }
        }
    }
}

then...

<MglGeojsonLayer
      type="fill"
      :sourceId="`source_1`"
      :layerId="`layer_1`"
      :source="source"
      :layer="layerConfig"
      @click="(e) => $emit('click', e)"
    />

tommed avatar Apr 17 '20 12:04 tommed