是否可以在开放层中显示点和图标以及一些偏移量?

时间:2014-01-31 04:46:22

标签: javascript openlayers

我想使用openlayers在地图中的相同位置显示点和外部grapphic图像。那可能吗??我尝试将功能添加到2个图层,一个带点,一个带外部图形图像。但是图像不是在透露。任何帮助?  我的代码是:

  var defaultStyle1 = new OpenLayers.Style({ 
    fillOpacity: 0.7, 
    labelAlign: "cm",
    graphicWidth: 10,
    graphicHeight: 10,
    externalGraphic: "${icon}",
    graphicYOffset : 10, 
    rotation : "${getRotationAngle}"
  }, {
    context : {
      icon : function(feature) {
        var zoom = map.getZoom();
        if(zoom < 7) { return null;}
        else {console.log("returning img"); return 'images/arrow.png';}
      },
      getRotationAngle : function (feature) {
        if (typeof(feature.cluster) != 'undefined') {
          return null;
        }
        if (typeof(feature.pois) != 'undefined') {
          if(typeof(feature.pois[0].imageangle) != 'undefined') {
            return feature.pois[0].imageangle;
          } else {
            return null;
          }
        }
      },
    }
  });
  var styleMap = new OpenLayers.StyleMap({
    'default': defaultStyle1
  });
  var arrowLayer = new OpenLayers.Layer.Vector("arrowLayer", {
    styleMap : styleMap
  });
  map.addLayer(arrowLayer);

var defaultStyle2 = new OpenLayers.Style({ 
      fillColor: 'red', 
      fillOpacity: 0.7,
      strokeColor: "black", 
      strokeWidth: 2,
      pointRadius: 4, 
      fontColor: "blue", 
      fontSize: "8px", 
      fontFamily: "tahoma", 
      fontWeight: "bold", 
      labelAlign: "cm" 
    });
  var selectStyle = new OpenLayers.Style(
    { fillColor: "blue", 
      fillOpacity: 0.7, 
      strokeColor: "black", 
      strokeWidth: 2, 
      pointRadius: 5
    }
  );

  var styleMap = new OpenLayers.StyleMap({
    'default': defaultStyle2, 'select': selectStyle
  });
  var pointLayer = new OpenLayers.Layer.Vector("pointLayer", {
    styleMap : styleMap
  });
  map.addLayer(pointLayer);

 //data from server
  var poi = new OpenLayers.Geometry.Point(data.longitude, data.latitude);
  var poiFeature = new OpenLayers.Feature.Vector(poi);

  pointLayer.addFeatures(poiFeatures);
  arrowLayer.addFeatures(poiFeatures);
  arrowLayer.redraw(true);
  pointLayer.redraw(true);

但只显示点图层,缩放级别大于7,也不显示箭头图层。我的代码中有任何错误吗?

0 个答案:

没有答案