在“ mapbox gl”中,动态数据未添加到addsource中

时间:2019-08-13 12:32:37

标签: angular

ngAfterViewInit(){
     mapboxgl.accessToken = 'pk.eyJ1IjoidWp3YWxhYjMwIiwiYSI6ImNqeWZmazBkNjBhcmgzY2xoeDM0eWRkdmgifQ.CJn7X47xraRyHFj4uLH7Eg';
      var gmap = new mapboxgl.Map({
         container: 'map',
         zoom: 0.3,
         center: [0, 20],
         style: 'mapbox://styles/mapbox/light-v10'
         });
         this.map = gmap;
         gmap.addControl(new mapboxgl.NavigationControl()); 


         // filters for classifying earthquakes into five categories based on magnitude
         var mag1 = ["<", ["get", "mag"], 2];
         var mag2 = ["all", [">=", ["get", "mag"], 2], ["<", ["get", "mag"], 3]];
         var mag3 = ["all", [">=", ["get", "mag"], 3], ["<", ["get", "mag"], 4]];
         var mag4 = ["all", [">=", ["get", "mag"], 4], ["<", ["get", "mag"], 5]];
         var mag5 = [">=", ["get", "mag"], 5];

         // colors to use for the categories
         var colors = ['#fed976', '#feb24c', '#fd8d3c', '#fc4e2a', '#e31a1c'];

         gmap.on('load', function () {
            console.log("aaaaaaaaaaaa",this.json_string);

         // add a clustered GeoJSON source for a sample set of earthquakes

         gmap.addSource('earthquakes', {
         "type": "geojson",
         "data":{
            "type": "FeatureCollection",
            "crs": { "type": "name",
                     "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" }
                  },
            "features": this.json_string,
         },
        /* "data": "https://docs.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson",*/
         "cluster": true,
         "clusterRadius": 80,
         "clusterProperties": { // keep separate counts for each magnitude category in a cluster
         "mag1": ["+", ["case", mag1, 1, 0]],
         "mag2": ["+", ["case", mag2, 1, 0]],
         "mag3": ["+", ["case", mag3, 1, 0]],
         "mag4": ["+", ["case", mag4, 1, 0]],
         "mag5": ["+", ["case", mag5, 1, 0]]
         }
         });

谢谢

0 个答案:

没有答案