简体   繁体   中英

Mapbox setPaintProperty for circle-radius is not updating layer

I have a Mapbox circle layer and I need to change the radius of the circle but the setPaintProperty method doesn't seem to work. The layer displays initially:

map.addLayer({
        "id": "circleCurrentGpsCircle",
        "type": "circle",
        "source": "source_circleCurrentGpsCircle",
        "paint": {
          "circle-radius": {
            stops: [
              [0, 0],
              [22, metersToPixelsAtMaxZoom(gpsAccuracyWidth, currentLatitude)]
            ],
            base: 2
          },
          "circle-color": self.props.senData.gpsCircleShading ? "#FFFF00" : "transparent",
          "circle-opacity": 0.3,
          "circle-stroke-width": 3,
          "circle-stroke-color": "#FFFF00"
        }
      });

I then call the following to change the radius of the circle:

var radiusData = {
        stops: [
          [0, 0],
          [22, metersToPixelsAtMaxZoom(gpsAccuracyWidth, currentLatitude)]
        ],
        base: 2
      };
      this.map.getLayer('circleCurrentGpsCircle').setPaintProperty('circle-radius', radiusData);

The circle doesn't change though. I'm not getting any errors in the console.

Normally, one calls setPaintProperty on the map object itself, not on a layer:

this.map.setPaintProperty('circleCurrentGpsCircle', 'circle-radius', radiusData);

I've never noticed the setPaintProperty() method on the returned layer object, but in my brief testing, it doesn't seem to work for me either.

(Actually with a bit of further testing, it seems that values set through that function do get recorded somewhere, and when you later call map.setPaintProperty() , all those values now get displayed. But this doesn't help you - just change the line to what I provided above.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM