强制OpenLayers Markers图层在顶部绘制,并在下面标记图层

时间:2014-08-28 17:16:52

标签: javascript openlayers

正如标题中所示,我想知道如何强制OpenLayers Markers图层在顶部绘制,并在下方标记图层。我有一个OSM baseMap和一个包含标签的可选图层。

所以我跟着this link,我创建了一个新的js文件,但是徒劳无功。我花了两天的时间试图做到没有任何结果,有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

感谢您的回复。所以我使用的代码如下:

用于BaseMap和Labeled Layer(它也可以选择)

             map = new OpenLayers.Map('map',{controls: [new OpenLayers.Control.Navigation(),
                         new OpenLayers.Control.PanZoomBar(),
                         new OpenLayers.Control.LayerSwitcher({'ascending':false}),
                         new OpenLayers.Control.ScaleLine(),

                         new OpenLayers.Control.MousePosition(),
                         new OpenLayers.Control.OverviewMap(),
                         new OpenLayers.Control.KeyboardDefaults()], 
             numZoomLevels: 30, 
             projection: mercator,
             displayProjection: geographic,
             units: "m",
             extent: indoor
             });

    var style = new OpenLayers.StyleMap({

        "default": new OpenLayers.Style({
                    fillColor: "#ff9544",
                    fillOpacity: 0.9,
                    strokeColor: "#fc5411",
                    strokeWidth: 1,
                    //strokeDashstyle: "dash",
                     label: "${name}",
                   // labelAlign: "cc",
                    fontColor: "#0000",
                    fontOpacity: 1,
                    fontFamily: "sans-serif",


                   })})

               var layerLocalisation = new OpenLayers.Layer.Vector("Localisations",{isBaseLayer: false,visibility : true});                

var layer = new OpenLayers.Layer.Vector("Bati", {
                   strategies: [new OpenLayers.Strategy.Fixed()],
                   styleMap: style,
                   protocol: new OpenLayers.Protocol.HTTP({
                   url: "data/gml/bati.xml",
                   format: new OpenLayers.Format.GML(),
                   projection: mercator
               })
           });

  var gmap = new OpenLayers.Layer.Google(
               "Google Streets", // the default
           {numZoomLevels: 30, visibility: false}
        );                     

  map.addLayers([gmap,layer,layerLocalisation]);

在与我的HTML页面中的按钮相关的功能中(在输入逻辑和纬度后添加标记的功能):

   function locate()
        {
             var coox = document.getElementById("idlong").value;
             //alert(coox);
             var cooy = document.getElementById("idlat").value;


              var coo1 =  new OpenLayers.LonLat(coox, cooy).transform(geographic,mercator);

              var point1 =  new OpenLayers.Geometry.Point(coo1.lon,coo1.lat);

              var featurePoint1 = new OpenLayers.Feature.Vector(
               point1,
              { description: 'info' },
               { externalGraphic: 'OpenLayers/img/marker-gold.png', graphicHeight: 25, graphicWidth: 21, graphicXOffset: -12, graphicYOffset: -25 }
              );

              layerLocalisation.addFeatures([featurePoint1]);             
              // map.addLayers([vectorLayer1]);
              map.setCenter(coo1,18);           
      }

所以标记显示但是,它位于选择标记的图层下,我希望我这么清楚,