0

I have a valid TopoJSON file (validated by Mapshaper) that is not properly loading into openlayers. The topoJSON was created from a valid GeoJSON files that DOES load properly into OpenLayers.

TopoJSON file: https://github.com/mmosier6/dataquery/blob/main/work/watches_fips_2020.topojson
GeoJSON file: https://github.com/mmosier6/dataquery/blob/main/work/watches_fips_2020.geojson

function watchMap(){
...
  jQuery.ajax({ 
    url:"data/watches_fips_2020.topojson",
    dataType: "json"
  }).done(function(data){
    
    vectorSource = new ol.source.Vector({
      features: (new ol.format.TopoJSON({layers:'watches_fips_2020'})).readFeatures(data, {featureProjection: 'EPSG:3857', dataProjection:'EPSG:4326'})
    });

    var mapData = new ol.layer.Vector({
      source: vectorSource,
      style: function (feature) {
        return getStyle(feature);
      }
    });     
    map = new ol.Map({
      target: 'map',
      layers: [new ol.layer.Tile({source: new ol.source.OSM()}), mapData],
        view: new ol.View({
        center: ol.proj.fromLonLat([-95, 38]),
        zoom: 4
      })
    });
}

The console returns these errors:

TopoJSON.js:327 Uncaught TypeError: l is not a function
 at Oy (TopoJSON.js:327)
 at My (TopoJSON.js:300)
 at t.readFeaturesFromObject (TopoJSON.js:105)
 at t.e.readFeatures (JSONFeature.js:51)
 at Object.<anonymous> (watchMap.js:24)

I tried to find the error by checking the functions in TopoJSON.js but could not figure it out.

mosier
  • 21
  • 3
  • 1
    In the latest version your code is failing at https://github.com/openlayers/openlayers/blob/main/src/ol/format/TopoJSON.js#L377 which suggests your data contains a geometry type not supported by OpenLayers, or a parsing error. – Mike Jan 12 '21 at 14:32
  • 1
    The topojson contains 5 occurrences of `"type":null` – Mike Jan 12 '21 at 21:11
  • 1
    That appears to be valid in the TopoJSON specification https://github.com/topojson/topojson-specification/blob/master/README.md but should be ignored https://github.com/topojson/topojson/issues/18 – Mike Jan 12 '21 at 21:24
  • That was exactly the problem. When I converted the 5m shapefile from [link](https://www.census.gov/geographies/mapping-files/time-series/geo/carto-boundary-file.html) to GeoJSON, the independent cities in VA all had null geometries, which then carried over into the TopoJSON. Using the TIGER/Line shapefiles [link](https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.2019.html) fixed the issue...although it created larger TopoJSON files. – mosier Jan 13 '21 at 10:06

0 Answers0