【问题标题】:Multiple images per layer in OpenLayersOpenLayers 中每层有多个图像
【发布时间】:2012-05-01 16:23:06
【问题描述】:

是否可以在 OpenLayers 中将多个图像放在一个图层中?

理想情况下,我想将我的图片分组(每一层都是一个类别),这样我就可以整体显示和隐藏每个类别,而不是显示/隐藏每张图片。

这可能吗?我发现了几个使用 OpenLayers 的 Image 层(似乎只支持一个图像)或带有 StyleMap 的 Vector 层(似乎也只允许一个外部图像)的例子。

我是否忽略了某些东西,还是需要更多的努力(即创建自定义图层类型)?

提前致谢!

【问题讨论】:

    标签: image openlayers layer


    【解决方案1】:

    要将多张图片放在同一层,可以像这样创建styleMap

    var style = new OpenLayers.StyleMap({
        default :new OpenLayers.Style({
              'pointRadius': 10,
              'externalGraphic': '/images/${icon}.png'
        })
    })
    

    其中“${icon}”是特征的一个属性。

    在下一个示例中,我使用 2 张图片“star”和“home”

    var path = new OpenLayers.Layer.Vector( "images" );
    //set the styleMap
    path.styleMap = style;
    map.addLayers([path]);
    
    //create a new feature
    var pointHome = new OpenLayers.Geometry.Point(-57.533832,-25.33963);
    var featureHome = new OpenLayers.Feature.Vector(pointHome);
    //set the icon of the feature
    featureHome.attributes["icon"] ="home";
    
    var pointStar = new OpenLayers.Geometry.Point(-57.533371,-25.338946);
    var featureStar = new OpenLayers.Feature.Vector(pointStar);
    //set the icon of the feature
    featureStar.attributes["icon"] ="star";
    
    path.addFeatures([featureHome, featureStar]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多