首页 新闻 会员 周边 捐助

openlayers标注问题 动态设置iconFeature的name值?

0
[已解决问题] 解决于 2019-09-30 11:29
    for (let i = 1; i <= 10; i++) {
          let t1 = Math.random() * (maxX - minX + 1) + minX;
          let t2 = Math.random() * (maxY - minY + 1) + minY;
          //创建图标特性
          iconFeature = new ol.Feature({
            geometry: new ol.geom.Point([t1, t2], "XY"),
            name: "ico"+i
          });

iconFeature.get("name")得到都是ico10怎么设置iconFeature的name值呢

wwj007的主页 wwj007 | 菜鸟二级 | 园豆:245
提问于:2019-09-28 10:27
< >
分享
最佳答案
0
   for (let i = 1; i <= arr.length; i++) {
        let t1 = Math.random() * (maxX - minX + 1) + minX;
        let t2 = Math.random() * (maxY - minY + 1) + minY;
        //创建图标特性
        var iconFeature = new ol.Feature({
          geometry: new ol.geom.Point([t1, t2], "XY"),
          name: arr[i - 1]
        });
        //设置点要素样式
        iconFeature.setStyle(
          createLabelStyle(iconFeature, icon, scale, opacity)
        );
        //将图标特性添加进矢量中
        vectorSource.addFeature(iconFeature);
      }
wwj007 | 菜鸟二级 |园豆:245 | 2019-09-30 11:29
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册