index.html
<!DOCTYPE html>
<html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>图形样式 - 颜色插值</title>
  <style type="text/css">
    html,body{margin:0px;height:100%;width:100%}
    .container{width:100%;height:100%}
  </style>
  <link rel="stylesheet" href="https://unpkg.com/maptalks/dist/maptalks.css">
  <script type="text/javascript" src="https://unpkg.com/maptalks/dist/maptalks.min.js"></script>
  <body>

    <div id="map" class="container"></div>
    <script>
      var map = new maptalks.Map('map', {
        center: [0, 0],
        zoom: 2,
        baseLayer: new maptalks.TileLayer('tile', {
          urlTemplate: 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png',
          subdomains: ['a','b','c','d'],
          attribution: '&copy; <a href="http://osm.org">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/">CARTO</a>'
        })
      });

      var layer = new maptalks.VectorLayer('v').addTo(map);
      fetch('./population.json').then(function (res) { return res.json(); }).then(function (json) {
        var points = [];
        var max = -Infinity;
        json.forEach(function (d) {
          var x = d[0], y = d[1], value = d[2];
          max = Math.max(value, max);
          var point = new maptalks.Marker([x, y], {
            properties: {
              value: value
            },
            symbol: {
              markerWidth: 2,
              markerHeight: 2,
              markerType: 'ellipse',
              markerFill: {
                type: 'color-interpolate',
                property: 'value',
                stops: [
                  [0, 'green'],
                  [50, 'yellow'],
                  [360, 'red']
                ]
              },
              markerLineWidth: 0
            }
          });
          points.push(point);
        });
        layer.addGeometry(points);
        console.log(max);
      });


    </script>
  </body>
</html>
已复制!