Uncaught InvalidValueError: not a function or FeatureCollection

After watching a recent Google Devs video, I decided to make a UK regional map. Several opportunities were mentioned on this site that I have since had to dismiss *

So, I ended up using this site (example data download page): http://mapit.mysociety.org/area/11804.html

Pay attention to loading GeoJSON , how on the third connection down? Its file size is 1 MB. When I first tried using it with my card:

function initMap(){ var ukc = new google.maps.LatLng(54.8, -4.6); var mapOptions = { zoom: 5, center: ukc }; map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); map.data.loadGeoJson('http://local.mapsite.com:8080/app/jsondata/eastern.json'); } $(document).ready(function(){ initMap(); }); 

I got the above error: Uncaught InvalidValueError: not Feature or FeatureCollection

Fix Attempt 1 - Google it

Error starting error returned with nothing useful.

Fix Try 2 - Squeeze It

I thought it was the sheer size of the beast, so I reduced it with mapshaper.org to a more manageable 10K. Not lucky yet!

Fix Attempt 3 - Lint it

Maybe my GeoJSON was poorly formatted? But as you might think this worked correctly on mapit.org, but I found this wonderful GeoJSON data overlay site: http://geojsonlint.com/ - Worked! Obviously, GeoJSON worked so well that it drew my East Angle polygon to the UK in all its glory (note geojsonlint uses OpenStreetMap). But still inaction

Bug Fix 4 - TopoJson

Hoping that I could unite the regions and squeeze at the same time, I desperately thought that topyson would work. I tried - I still have the same error. Here's a link to my topojson file that was opened on Google Drive: someregions.json No luck .

Fix Attempt 5 - Add Function Code to Run JSON

The current GeoJSON file {"BBOX" is launched: [- 0.745702,51.448473,1.767999,52.98991], "Type": "GeometryCollection", "geometry": ...

I added:

 {"type": "Feature", "bbox":[-0.745702,51.448473,1.767999,52.98991],"type":"GeometryCollection","geometries": 

Fix Attempt 6

Repeat several areas because they do not contain the bbox parameter next to the launch, but simply start {"type": "Polygon", "coordinates": [[[-3.155785, 53.427385], [-3.151533, 53.427328], [...

Still no luck .

The (Failed) Conclusion

Even though I proved that my file was small enough, groped, and worked elsewhere, I still received these error messages from the console when I tried to place them on my card.

 Uncaught InvalidValueError: not a Feature or FeatureCollection 

Here is my compressed GeoJSON file, shared through GDrive: https://drive.google.com/file/d/0B42Aec8RKcHtNVNZZUxqV0Y5Rkk/edit?usp=sharing

My subsequent attempts will include topojson to squeeze all regions into one with inner borders, but I wanted to check here first to see if anyone knows what my problem might be? Because it could be a few more hours of wasted energy wasted.

* An attempt to use the data from the crawl surveys failed because they provided SHD and not SHP data as indicated in the previous question on this issue. Therefore, I could not convert it to GeoJSON using ogr2ogr.

+7
maps google-maps google-maps-api-3 geojson
source share
2 answers

The specification for GeoJSON can be found at http://geojson.org/geojson-spec.html The corresponding (albeit experimental) Google Maps API documentation can be found at https://developers.google.com/maps/documentation/javascript/3. exp / reference # Data

So, it seems that it is acceptable for GeoJSON to use Google Maps, you need to wrap the Polygon (or similar) returned by MapIt in Feature or FeatureCollection, here is an example for a Bermuda triangle:

  { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [-80.190262,25.774252], [-66.118292,18.466465], [-64.75737,32.321384], [-80.190262,25.774252] ] ] } } ] } 

for the data provided by http://mapit.mysociety.org/area/11804.html , this should be:

  { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": /** paste here the complete output of http://mapit.mysociety.org/area/11804.geojson **/ } ] } 
+15
source share

I had the same problem (or at least the same one), and it was solved by introducing one additional step.

Origin of data: My semantic network delivers in the first round a request for data on caves in the south of France in GeoJSON format. This is directly imported via:

map.data.loadGeoJson (theUrl);

Since we can work independently of the semantic network with this data (the application is a thick client), caves are stored locally through jStorage . Iterating map functions and saving these objects directly in jStorage failed due to circular references. I did a manual procedure (not general enough, but appropriate for the purpose) to convert map.data.Feature into a javascript object that could be saved.

When receiving data from the store:

 var cave = $.jStorage.get(key); map.data.addGeoJson(cave); 

raises an Uncaught InvalidValueError: not a Feature or FeatureCollection error.

But:

 var geojson = JSON.parse(cave); map.data.addGeoJson(geojson); 

It works great.

My interpretation is that addGeoJson functions need a javascript object, not a string.

Example geoJson (meaning "cave" orignal):

 { "type": "Feature", "geometry": {"type": "Point", "coordinates": [5.368743302306143, 44.0421921072459]},"id": "84.MON.014", "properties": {"nom": "Aven du Grand GuΓ©rin", "nid": "7b4703-f387f6f544-0750e59f441be7bb30a7e097c5d725f7", "nature": "Aven", "nodeTime": 1400743203325, "dataId": "5b66137c-1461fdfe5ca-f528764d624db129b32c21fbca0cb8d6", "status": 1}} 
+9
source share

All Articles