简体   繁体   English

如何更改 map object 中的属性目标的值

[英]How to change the value of the property target in the map object

i would like to know how to set value fot a the target property of the map.我想知道如何为 map 的目标属性设置值。 in the below posted code,i would like to change the target property to, for example to mapTest instead of map.在下面发布的代码中,我想将目标属性更改为例如 mapTest 而不是 map。 to achieve that, i did the following:为了实现这一点,我做了以下事情:

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

and changed the target as follows accordingly:并相应地更改目标如下:

    target: 'mapTest',

but then the code does not display anything please let me know how to change the target property of the map object correctly但随后代码不显示任何内容请让我知道如何正确更改 map object 的目标属性

app.component.html : 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 : 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
})
});
 }

Ok, so I'm not sure what the exact problem is but here are some pointers, Map class has a method setTarget where you can change the target property but you also need to trigger render method as well so it will render the map in a new element container, it should look something like this:好的,所以我不确定确切的问题是什么,但这里有一些指针, Map class 有一个方法setTarget ,您可以在其中更改目标属性,但您还需要触发render方法,因此它将在 a1D78DC8ED514214E9AEZ444B 中渲染新的元素容器,它应该看起来像这样:

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

On a sidenote, there is a whitespace in this. map在旁注中,这里有一个空格this. map this. map between a dot and map, hope that's not in your actual code. this. map在点和 map 之间,希望这不在您的实际代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM