vue-mapbox
vue-mapbox copied to clipboard
FeatureCollection in GeoJSON file possible?
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?
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"
}
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)"
/>