{"record":{"id":"115763d971913b80","repo":"plotly/plotly.js","slug":"invalid-geojson-type-type-traces-with-location","errorCode":null,"errorMessage":"Invalid GeoJSON type ${type}. Traces with locationmode *geojson-id* only support *FeatureCollection* and *Feature* types.","messagePattern":"Invalid GeoJSON type (.+?)\\. Traces with locationmode \\*geojson-id\\* only support \\*FeatureCollection\\* and \\*Feature\\* types\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/lib/geo_location_utils.js","lineNumber":289,"sourceCode":"        }\n\n        // remove key from lookup, so that we can track (if any)\n        // the locations that did not have a corresponding GeoJSON feature\n        delete lookup[id];\n    }\n\n    switch (geojsonIn.type) {\n        case 'FeatureCollection':\n            var featuresIn = geojsonIn.features;\n            for (i = 0; i < featuresIn.length; i++) {\n                appendFeature(featuresIn[i]);\n            }\n            break;\n        case 'Feature':\n            appendFeature(geojsonIn);\n            break;\n        default:\n            loggers.warn(\n                [\n                    'Invalid GeoJSON type',\n                    (geojsonIn.type || 'none') + '.',\n                    'Traces with locationmode *geojson-id* only support',\n                    '*FeatureCollection* and *Feature* types.'\n                ].join(' ')\n            );\n            return false;\n    }\n\n    for (var loc in lookup) {\n        loggers.log(\n            [\n                'Location *' + loc + '*',\n                'does not have a matching feature with id-key',\n                '*' + trace.featureidkey + '*.'\n            ].join(' ')\n        );","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/lib/geo_location_utils.js#L271-L307","documentation":"For traces with locationmode 'geojson-id', plotly.js extracts GeoJSON features to match location ids. Only GeoJSON objects of type 'FeatureCollection' or 'Feature' are supported; anything else (Geometry, GeometryCollection, FeatureCollection-ish malformed input, or missing type) triggers this warning and the trace gets no geometry.","triggerScenarios":"Passing a raw Geometry ({type: 'Polygon', ...}) or an array of geometries as the geojson attribute; a fetched TopoJSON or non-GeoJSON file; a geojson object whose .type is misspelled or absent; passing a Feature collection wrapped in another object.","commonSituations":"Using data exported from shapefile converters that emit bare geometries; fetching 'GeoJSON' endpoints that actually return TopoJSON; building geojson by hand and forgetting the Feature wrapper; version confusion after switching locationmode from 'geojson' to 'geojson-id'.","solutions":["Wrap raw geometries: {type: 'Feature', geometry: <your geometry>, properties: {}} before assigning to geojson.","Convert TopoJSON to GeoJSON (e.g. with topojson-client feature()) before use.","Verify geojson.type === 'FeatureCollection' || geojson.type === 'Feature' right after fetching.","Ensure features contain an id (or use featureidkey pointing to a properties field) so 'geojson-id' lookups resolve.","Log JSON.parse of your file and inspect the top-level type when the warning appears."],"exampleFix":"// before\nPlotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson: {type: 'Polygon', coordinates: [...]}}]);\n// after\nconst feature = {type: 'Feature', properties: {id: 'ABC'}, geometry: {type: 'Polygon', coordinates: [...]}};\nPlotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson: feature, locations: ['ABC'], featureidkey: 'properties.id'}]);","handlingStrategy":"validation","validationCode":"function isUsableGeoJSON(g) {\n  return !!g && (g.type === 'FeatureCollection' || g.type === 'Feature') &&\n    (g.type === 'FeatureCollection' ? Array.isArray(g.features) && g.features.length > 0 : !!g.geometry);\n}\nif (!isUsableGeoJSON(geojson)) throw new Error('geojson must be Feature or FeatureCollection');","typeGuard":"function isGeoJSONFeatureOrCollection(v) {\n  return typeof v === 'object' && v !== null &&\n    (v.type === 'Feature' || (v.type === 'FeatureCollection' && Array.isArray(v.features)));\n}","tryCatchPattern":"const res = await fetch(url);\nconst geojson = await res.json();\nif (!isGeoJSONFeatureOrCollection(geojson)) {\n  throw new Error(`expected Feature/FeatureCollection, got ${geojson && geojson.type}`);\n}\nPlotly.newPlot(gd, [{type: 'choropleth', locationmode: 'geojson-id', geojson, ...}]);","preventionTips":["Convert TopoJSON with topojson-client before use.","Wrap bare geometries in {type:'Feature', geometry, properties}.","Give features ids or set featureidkey to a properties field.","Verify the fetched endpoint actually returns GeoJSON, not TopoJSON or shapefile output."],"tags":["geojson","maps","validation"],"backgroundTag":"invalid-geojson-type","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}