|React+Openlayuers 模板(学习中,持续更新)( 二 )


.setId(`icon ${index`)
          )
          // 将标注属性添加到矢量数据源中
          let iconSource = new VectorSource({
            features: iconFeatures
          )
          //将标注矢量数据源添加到矢量层
          let iconLayer = new VectorLayer({
            source: iconSource
            zIndex: 3
            style: () => {
              return new Style({
                image: new Icon({
                  anchor: [0.5 1

                  scale: 0.12
                  src: featureImg
                )
              )
           
          )
          // 将矢量层添加到地图
          map.current.addLayer(iconLayer);
       
     
      /**
      * 创建线
      */
      const createLine = (lineData: Array<any> lineColor: string layerId: string) => {
        let lineFeature: any;
        if (lineData.length > 0) {
          lineFeature = new Feature({
            geometry: new LineString([...lineData
)
          )
       
        // 将划线属性添加到矢量数据源中
        let lineSource = new VectorSource({)
        lineSource.addFeature(lineFeature);
        let lineLayer = new VectorLayer({
          source: lineSource
          zIndex: 2
          style: () => {
            return new Style({
              stroke: new Stroke({
                width: 4
                color: 'rgb(02550)'
              )
            )
         
        )
        // 将矢量层添加到地图
        map.current.addLayer(lineLayer);