【发布时间】: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