Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 是否可以在openlayers中显示点和图标以及一些偏移?_Javascript_Openlayers - Fatal编程技术网

Javascript 是否可以在openlayers中显示点和图标以及一些偏移?

Javascript 是否可以在openlayers中显示点和图标以及一些偏移?,javascript,openlayers,Javascript,Openlayers,我想使用openlayers在地图的同一位置显示点和外部图形图像。这可能吗??我尝试将功能添加到两个图层,一个带有点,另一个带有外部图形图像。但这一形象并没有改变。有什么帮助吗?? 我的代码是: var defaultStyle1 = new OpenLayers.Style({ fillOpacity: 0.7, labelAlign: "cm", graphicWidth: 10, graphicHeight: 10, externalGrap

我想使用openlayers在地图的同一位置显示点和外部图形图像。这可能吗??我尝试将功能添加到两个图层,一个带有点,另一个带有外部图形图像。但这一形象并没有改变。有什么帮助吗?? 我的代码是:

  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);
var defaultStyle1=新的OpenLayers.Style({
不透明度:0.7,
labelAlign:“cm”,
宽度:10,
身高:10,
外部图形:“${icon}”,
图形偏移:10,
旋转:“${getRotationAngle}”
}, {
背景:{
图标:功能(特性){
var zoom=map.getZoom();
如果(缩放<7){返回null;}
else{console.log(“returning img”);return'images/arrow.png';}
},
getRotationAngle:函数(特性){
if(typeof(feature.cluster)!=“未定义”){
返回null;
}
if(typeof(feature.pois)!=“未定义”){
if(typeof(feature.pois[0].imageangle)!=“未定义”){
返回特征.pois[0].imageangle;
}否则{
返回null;
}
}
},
}
});
var styleMap=new OpenLayers.styleMap({
“默认”:defaultStyle1
});
var arrowLayer=new OpenLayers.Layer.Vector(“arrowLayer”{
styleMap:styleMap
});
map.addLayer(箭头图层);
var defaultStyle2=新的OpenLayers.Style({
fillColor:'红色',
不透明度:0.7,
strokeColor:“黑色”,
冲程宽度:2,
点半径:4,
fontColor:“蓝色”,
字体大小:“8px”,
丰特家族:“塔荷马”,
fontWeight:“粗体”,
labelAlign:“cm”
});
var selectStyle=new OpenLayers.Style(
{fillColor:“蓝色”,
不透明度:0.7,
strokeColor:“黑色”,
冲程宽度:2,
点半径:5
}
);
var styleMap=new OpenLayers.styleMap({
“默认”:defaultStyle2,“选择”:selectStyle
});
var pointLayer=new OpenLayers.Layer.Vector(“pointLayer”{
styleMap:styleMap
});
map.addLayer(pointLayer);
//来自服务器的数据
var poi=新OpenLayers.Geometry.Point(data.longitude,data.latitude);
var poiFeature=新的OpenLayers.Feature.Vector(poi);
pointLayer.addFeatures(POIFatures);
arrowLayer.addFeatures(POIFatures);
arrowLayer.redraw(真);
pointLayer.redraw(true);

但仅显示点图层,缩放级别超过7也不显示箭头图层。我的代码中有错误吗???

你解决了吗?你真的只是想为每个点显示2个图形(标记和你自己的带有偏移的图形)吗?