【问题标题】:How to change the value of the property target in the map object如何更改地图对象中属性目标的值
【发布时间】:2021-03-28 22:38:06
【问题描述】:

我想知道如何为地图的目标属性设置值。 在下面发布的代码中,我想将目标属性更改为,例如 mapTest 而不是 map。为了实现这一点,我做了以下事情:

#mapTest {
    width: 800px;
    height: 550px;
  }
</style>
    <div id="mapTest"></div>
    <script src="./index.js"></script>

并相应地更改目标如下:

    target: 'mapTest',

但是代码没有显示任何内容 请告诉我如何正确更改地图对象的目标属性

app.component.html

    <div class="MousePosition">
  <div id="mouse-position"></div>
</div>
<form>
  <label for="projection">Projection </label>
  <select id="projection">
    <option value="EPSG:4326">EPSG:4326</option>
    <option value="EPSG:3857">EPSG:3857</option>
  </select>
  <label for="precision">Precision</label>
  <input id="precision" type="number" min="0" max="12" value="4"/>
</form>
<style>
  #map {//<---i want to change this
    width: 800px;
    height: 550px;
  }
</style>
    <div id="map"></div>
    <script src="./index.js"></script>

app.component.ts

ngOnInit() {
this. map = new Map({
controls: defaultControls().extend([mousePositionControl]),
target: 'map',//<---i want to change this
layers: [
  new TileLayer({
    source: new XYZSource({
      url: 'http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg'
    })
  })
],
view: new View({
  center: [0, 0],
  zoom: 0
})
});
 }

【问题讨论】:

    标签: javascript node.js angular typescript openlayers


    【解决方案1】:

    好的,所以我不确定确切的问题是什么,但这里有一些指针,Map 类有一个方法 setTarget,您可以在其中更改目标属性,但您还需要触发 render 方法为好吧,它会在一个新的元素容器中渲染地图,它应该看起来像这样:

    onSomeEvent() {
        this.map.setTarget('mapTest');
        this.map.render();
    }
    

    在旁注中,this. map 在点和映射之间有一个空格,希望这不在您的实际代码中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      • 2021-12-03
      • 2019-03-09
      • 1970-01-01
      • 2018-07-31
      • 1970-01-01
      • 2013-02-17
      相关资源
      最近更新 更多