Openlayers:来自属性的x-y位置的GML标签折线

时间:2014-10-21 11:29:06

标签: openlayers qgis

我有一个在QGIS中生成的折线的GML文件,我在OpenLayers地图中显示。在QGIS中,通过为每条折线分配属性x,y和r(纬向长和旋转角度),可以巧妙地控制折线上标签的位置和旋转。我的问题 - 是否可以在OpenLayers中复制它?目前,下面的代码将显示折线,指定线条颜色(来自属性)并标记线条的末尾,但我无法找到使用x,y,r属性来定位和旋转标签的方法,或者使用当前图层中的可用标签样式类,或通过创建隐藏点上带有标签的新地图图层。或者,是否有任何其他标记折线的方法,例如动态标签(在您平移的地方始终可见)?

我的GML文件记录的格式为:

    <gml:featureMember>
  <ogr:kkt fid="kkt.1">
    <ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>44.812559373349139,35.123067298944513 44.877309206574807,35.090369282888879 44.950560220859877,35.055758183443189 45.018309159587957,35.032504238642005 45.096824639867442,35.010683901054648 45.21229522673363,34.979672029569649 45.279922241108068,34.961918618632232 45.328207131827412,34.944608836480917 45.379400253358313,34.921389158285983 45.438599638041431,34.88848896036766 45.505644158404003,34.837566477843978 45.554152957603797,34.794071273427527 45.595241006031721,34.763023849471629 45.631673146434373,34.739161723332415 45.67708,34.71297</gml:coordinates></gml:LineString></ogr:geometryProperty>
    <ogr:id>2</ogr:id>
    <ogr:thickness>200</ogr:thickness>
    <ogr:col>#00248F</ogr:col>
    <ogr:x>43.4678</ogr:x>
    <ogr:y>35.8826</ogr:y>
    <ogr:r>324</ogr:r>
  </ogr:kkt>
</gml:featureMember>

(其中属性:&#34; thickness&#34;是折线的文本标签;&#34; col&#34;是指定给折线的颜色,x,y,r是co-ords和标签的旋转属性)

我用来显示图层的Openlayers代码是:

        var contour = new OpenLayers.Layer.Vector("Contour Lines", {
      strategies: [new OpenLayers.Strategy.Fixed()],
      protocol: new OpenLayers.Protocol.HTTP({
        url: "kml/temp.gml",
        format: new OpenLayers.Format.GML({
          extractStyles: true,
          extractAttributes: true,
          maxDepth: 2
        })
      }),
      styleMap: new OpenLayers.StyleMap({
        "default": new OpenLayers.Style({
          fillColor: "${col}",
          fillOpacity: 0,
          strokeColor: "${col}",
          strokeWidth: 2,
          strokeOpacity: 0.5,
          fontColor: "black",
          fontFamily: "arial, sans-serif",
          fontSize: ".9em",
          fontWeight: "bold",
          label: "${thickness}",
          labelAlign: "cm",
          labelXOffset: -10
        })
      })
    });

0 个答案:

没有答案