首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-传单。映射CircleMarker数组会进入无限循环

react-传单。映射CircleMarker数组会进入无限循环
EN

Stack Overflow用户
提问于 2020-10-26 03:22:26
回答 1查看 286关注 0票数 0

我正在使用react-leaflet在我的react应用程序中创建地图。在Map组件中,我尝试映射一个国家数组,并返回每个国家的CirclrMarker。当我使用标记组件执行此操作时,它可以正常运行,但使用CirclrMarker组件时,代码会进入无限循环。

代码:

代码语言:javascript
复制
import React, { useState } from 'react'
import { Map, TileLayer, Marker, Popup, Circle, CircleMarker } from 'react-leaflet'
import L from 'leaflet'

import './Map.css'

function LeafletMap({ position, zoom, data }) {
    const markerIcon = 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"
    });
    return (
        <Map className="map" center={position} zoom={zoom}>
            <TileLayer
                attribution='&amp;copy <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
                url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
            />
             {data.map((country) => {
                return (
                <CircleMarker
                position={{ lat: country.countryInfo.lat, lng: country.countryInfo.long }}>
                    <Popup>{country.country}</Popup>
                </CircleMarker>)
            })} 
            <Marker position={position} zoom={zoom} icon={markerIcon}>
                <Popup> {zoom} </Popup>
            </Marker>
        </Map>
    )
}

export default LeafletMap

你知道为什么会发生这样的事情吗?

EN

回答 1

Stack Overflow用户

发布于 2020-10-26 18:11:23

向圆形标记添加半径:

代码语言:javascript
复制
<CircleMarker position={{ lat: country.countryInfo.lat, lng: country.countryInfo.long }} radius={100}>
      <Popup>{country.country}</Popup>
</CircleMarker>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64527846

复制
相关文章

相似问题

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