Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
548 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...