首页 / 浏览问题 / WebGIS / 问题详情
webjs中如何动态添加颜色
1EXP 2022年08月05日
function (serviceResult) {

          serviceResult.result.features.features.map((item, index) => {

            var feature = new GeoJSON();

            style = new Style({

              fill: new Fill({

                color: that.color[index],

              }),

            });

            var ls = feature.readFeatures({

              type: serviceResult.result.features.type,

              features: [serviceResult.result.features.features[index]],

            });

            vectorSource.addFeatures(feature);

          });

          that.PCIprojectLayer = new Vector({

            source: vectorSource,

          });

          that.map.addLayer(that.PCIprojectLayer);

        }

1个回答

您好,您用的服务具体是什么呢。您具体描述一下您是想动态修改什么的颜色呢?

如果您是使用OpenLayer,想要对geojson导入的每一类要素对象修改风格,可以在创建好需要的style,在geojson写入成source,实例化建立vector的时候进行style的匹配修改。

您可以参考:https://blog.csdn.net/chen413203144/article/details/123897370

当然也阔以在实例化Vector后,以整个Vector的style修改,或者在source中取出具体的要素对象进行style的修改。

希望可以帮助到您。

9,603EXP 2022年08月05日
...