Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将外部swisstopo地图添加到angular 8中_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 将外部swisstopo地图添加到angular 8中

Javascript 将外部swisstopo地图添加到angular 8中,javascript,angular,typescript,Javascript,Angular,Typescript,我正在尝试在angular 8应用程序中添加swisstopo地图。我是angular的新手,我真的不知道如何在我的组件中包含这个简单的示例: 我曾尝试将脚本链接添加到index.html中,并将其加载,但之后我不知道如何以及在何处添加要使用的小型普通javascript代码 在angular-cli.json中输入脚本javascript名称。我不知道在加载组件时要执行这个脚本需要做什么 MapViewComponent.ts `import { Component, OnInit } fr

我正在尝试在angular 8应用程序中添加swisstopo地图。我是angular的新手,我真的不知道如何在我的组件中包含这个简单的示例:

我曾尝试将脚本链接添加到index.html中,并将其加载,但之后我不知道如何以及在何处添加要使用的小型普通javascript代码

在angular-cli.json中输入脚本javascript名称。我不知道在加载组件时要执行这个脚本需要做什么

MapViewComponent.ts

`import { Component, OnInit } from '@angular/core';`

 @Component({
    selector: 'app-map-view',
    templateUrl: './map-view.component.html',
    styleUrls: ['./map-view.component.scss']
 })
 export class MapViewComponent implements OnInit {

  constructor() { }

  ngOnInit() {

  }

 }
MapViewComponent.html

<div id="map" class="map"></div>

geo.admin中的快速入门示例

<!doctype html>
<html lang="en">
 <head>
 <style>
  .map {
    height: 400px;
    width: 100%;
  }
 </style>
<title>GeoAdmin API example</title>
</head>
<body>
   <h2>My first GeoAdmin map</h2>
   <script src="http://api3.geo.admin.ch/loader.js?lang=en&version=4.4.2" type="text/javascript"></script>
   <div id="map" class="map"></div>
   <script type="text/javascript">
      var layer = ga.layer.create('ch.swisstopo.pixelkarte-farbe');
      var map = new ga.Map({
        target: 'map',
        layers: [layer],
        view: new ol.View({
          resolution: 500,
          center: [2670000, 1160000]
        })
      });
  </script>
  </body>
</html>

.地图{
高度:400px;
宽度:100%;
}
geoadminapi示例
我的第一张地理管理地图
var layer=ga.layer.create('ch.swisstopo.pixelkart-farbe');
变量映射=新的遗传算法映射({
目标:“地图”,
图层:[图层],
视图:新ol.view({
决议:500,
中心:[26700001160000]
})
});

我希望在创建一个新的MapComponent时加载地图好吧,我最初的答案是垃圾

链接不起作用。我在瑞士,可能是因为这个国家,你不能访问这个?如果你能写下你想要添加的javascript代码,也许我可以帮你。谢谢你的回复,我已经从网站上添加了代码