Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

geojson - Error loading TopoJSON file in Openlayers 5

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...