Angular 7材料+OpenLayers:在显示中绘制的点位置错误。
创始人
2024-10-17 00:00:20
0

您可以尝试使用以下解决方法来解决在Angular 7材料和OpenLayers中显示绘制点位置错误的问题:

  1. 确保您已正确安装和配置了Angular材料和OpenLayers。确保您的package.json文件中已添加了相应的依赖项,并在您的项目中正确导入和使用它们。

  2. 检查您的代码中是否存在错误。请确保您已正确设置和使用OpenLayers的地图和视图,并将其与Angular材料集成。确保您正确地初始化和使用OpenLayers的绘制源和绘制图层。

下面是一个示例代码,展示了如何在Angular 7材料和OpenLayers中显示绘制点位置:

在HTML模板中:


  

在组件中:

import { Component, OnInit } from '@angular/core';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';
import Draw from 'ol/interaction/Draw';
import { Vector as VectorLayer } from 'ol/layer';
import { Vector as VectorSource } from 'ol/source';
import { Circle as CircleStyle, Fill, Stroke, Style } from 'ol/style';

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

  constructor() { }

  ngOnInit() {
    const map = new Map({
      target: 'map',
      layers: [
        new TileLayer({
          source: new OSM()
        })
      ],
      view: new View({
        center: [0, 0],
        zoom: 2
      })
    });

    const source = new VectorSource();
    const vector = new VectorLayer({
      source: source,
      style: new Style({
        fill: new Fill({
          color: 'rgba(255, 255, 255, 0.2)'
        }),
        stroke: new Stroke({
          color: '#ffcc33',
          width: 2
        }),
        image: new CircleStyle({
          radius: 7,
          fill: new Fill({
            color: '#ffcc33'
          })
        })
      })
    });

    map.addLayer(vector);

    const draw = new Draw({
      source: source,
      type: 'Point'
    });
    map.addInteraction(draw);
  }
}

在上面的示例中,我们创建了一个包含OpenLayers地图的Angular材料卡片。我们使用了OpenStreetMap作为底图,并使用一个绘制交互来绘制点。您可以根据您的需求自定义样式和交互。

请确保在您的项目中正确导入和使用所需的OpenLayers和Angular材料模块。如果仍然遇到问题,请检查控制台输出以查看是否有任何错误信息,并确保您的代码没有其他错误。

相关内容

热门资讯

透视烘培!aa poker辅助... 透视烘培!aa poker辅助,AApoker透视软件总是有工具,八分钟教程(有挂存在)aa pok...
透视总结!wpk辅助哪里买,w... 透视总结!wpk辅助哪里买,wpk控制牌是真的吗(透视)果然有技巧(哔哩哔哩)1、下载好透视辅助下载...
透视策略!德普之星辅助软件,德... 透视策略!德普之星辅助软件,德普之星工具切实存在有插件,第2分钟教程(有挂教学)德普之星辅助软件能透...
一直以来!aapoker透视插... 一直以来!aapoker透视插件,微信小程序微乐破解器2024,揭幕透视(新版有挂)-哔哩哔哩1、首...
透视好友!pokemmo手机脚... 透视好友!pokemmo手机脚本辅助器,微乐贵阳足鸡麻将开挂,科普透视(今日头条)-哔哩哔哩poke...
透视积累!德普之星透视辅助软件... 透视积累!德普之星透视辅助软件下载,德普之星私人局总是是有透视,第3分钟教程(确实有挂)1、玩家可以...
透视手段!wpk辅助哪里买,W... 透视手段!wpk辅助哪里买,WPK有透视一直真的是有工具,7分钟教程(有挂透视)1、玩家可以在wpk...
这一现象值得深思!xpoker... 这一现象值得深思!xpoker辅助器,微乐自建房辅助软件功能,总结脚本(有挂解惑)-哔哩哔哩xpok...
透视绝活!wepoker软件辅... 透视绝活!wepoker软件辅助程序,WePoKer透视果然真的是有工具,8分钟教程(有挂秘诀)1、...
今日!wepoker好友房开挂... 今日!wepoker好友房开挂,微乐春天扑克开挂辅助插件,开挂脚本(有挂存在)-哔哩哔哩1、上手简单...