首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单个标记未使用ngx leaflet markercluster可视化

单个标记未使用ngx leaflet markercluster可视化
EN

Stack Overflow用户
提问于 2019-07-09 00:15:36
回答 1查看 512关注 0票数 1

当我在地图上放大一个集群,使用ngx angular版本的leaflet-markercluster时,我不能可视化单个标记。

使用以上模块的纯javascript和js版本可以得到不同的结果。

map.component的代码如下:

代码语言:javascript
复制
import { Component, OnInit, Input } from '@angular/core';

import * as L from 'leaflet';
import 'leaflet.markercluster';

@Component({
    selector: 'map',
    templateUrl: './map.component.html'
})
export class MapComponent implements OnInit {

  @Input() coords:number[][];
    options = {
        zoom: 5,
    maxZoom : 18,
        center: L.latLng([ 41.5, 12.5 ]),

   layers: [L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {})],


    };

    // Marker cluster stuff
  markerClusterGroup: L.MarkerClusterGroup;
    markerClusterData: L.Marker[] = [];
    markerClusterOptions: L.MarkerClusterGroupOptions;


    ngOnInit() {

        this.markerClusterData = this.generateMarker(this.coords);
    }

    markerClusterReady(group: L.MarkerClusterGroup) {
        this.markerClusterGroup = group;
    }
   [...]

Leaflet选项在中定义

代码语言:javascript
复制
    <div leaflet style="height: 400px;"
        [leafletOptions]="options"
        [leafletMarkerCluster]="markerClusterData"
        [leafletMarkerClusterOptions]="markerClusterOptions"
        (leafletMarkerClusterReady)="markerClusterReady($event)">
    </div>

您可以可视化整个代码并在stackblitz上运行

如何解决单标记可视化问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-09 03:44:03

这与众所周知的与webpack的捆绑问题有关。在icon变量中定义iconUrl,它应该可以解决这个问题。

代码语言:javascript
复制
const icon = L.icon({
    iconSize: [25, 41],
    iconAnchor: [10, 41],
    popupAnchor: [2, -40],
    // specify the path here
    iconUrl: "https://unpkg.com/leaflet@1.5.1/dist/images/marker-icon.png",
    shadowUrl:
      "https://unpkg.com/leaflet@1.5.1/dist/images/marker-shadow.png"
});

我只想提个建议,把iconUrl放在for循环之外。因为您只需要声明变量一次。

Demo

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56938885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档