GithubHelp home page GithubHelp logo

antvis / larkmap Goto Github PK

View Code? Open in Web Editor NEW
72.0 14.0 28.0 1.11 MB

A React toolkit for geospatial visualization based on L7.

Home Page: https://larkmap.antv.antgroup.com

License: MIT License

JavaScript 0.70% TypeScript 90.38% Shell 0.07% Less 8.85%
react antvis data-visualization l7 map webgl ant-l7

larkmap's Introduction

English | 简体中文

LarkMap

🌍 基于 L7 的空间数据可视分析 React 组件库.

npm Version npm License Status Release Status

Percentage of issues still open Average time to resolve an issue

网站快速开始组件

📦 安装

$ npm install @antv/l7 @antv/larkmap

🔨 使用

import React from 'react';
import { LarkMap } from '@antv/larkmap';

const config = {
  mapType: 'Gaode',
  mapOptions: {
    style: 'light',
    center: [120.210792, 30.246026],
    pitch: 0,
    zoom: 8,
    rotation: 0,
  },
};

export default () => {
  return <LarkMap {...config} style={{ height: '300px' }}></LarkMap>;
};

本地开发

# Install project dependencies
$ npm install

# Run website
$ npm run start

# Run lint & unit tests
$ npm run ci

# Compile package
$ npm run build

🤝 如何贡献

如果您在使用的过程中碰到问题,可以先通过 issues 看看有没有类似的 bug 或者建议。

如需提交代码,请遵从我们的贡献指南

许可证

MIT@AntV.

larkmap's People

Contributors

andybuibui avatar andyfang94 avatar dreammy23 avatar heiyexing avatar hsp-sz avatar lvisei avatar lzxue avatar marklei7 avatar simplexiao avatar websybin avatar wing-scud avatar yiiiiiiqianyao avatar yzg1025 avatar zhaoqc-max avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

larkmap's Issues

🐛 [BUG]LegendCategories的labels数据一致时控制台key报错

🐛 Bug description [Please make everyone to understand it]

image

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

key应该拿label+color,参考l7plot,支持重复label,不会报错
image

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🤔 [QUESTION]

🐛 Question description [Please make everyone to understand it]

LarkMap 似乎无法使用 简单Map 模式

💻 Link to minimal reproduction

import { CustomControl, LarkMap, useScene, ImageLayerProps, ImageLayer } from '@antv/larkmap';
import { Button } from '@/components/ui/button';
import React, { useEffect, useState } from 'react';
import { DrawCircle, DrawRect } from '@antv/l7-draw';

function CustomDraw() {
    const [circleDrawer, setCircleDrawer] = useState<DrawCircle | null>(null);
    const [rectDrawer, setRectDrawer] = useState<DrawRect | null>(null);

    const scene = useScene();
    useEffect(() => {
        const drawerRect = new DrawRect(scene, {
            distanceOptions: {},
            areaOptions: {},
        });
        setRectDrawer(drawerRect);
        const drawerCircle = new DrawCircle(scene, {});
        setCircleDrawer(drawerCircle);

    }, []);
    return (
        <CustomControl className="float-right">
            <div style={{ padding: 8 }}>
                circleDrawer
                <Button onClick={() => circleDrawer?.enable()}>启用</Button>
                <Button onClick={() => circleDrawer?.disable()}>禁用</Button>
                <Button onClick={() => circleDrawer?.clear()}>清空</Button>
            </div>
            <div style={{ padding: 8 }}>
                rectDrawer
                <Button onClick={() => rectDrawer?.enable()}>启用</Button>
                <Button onClick={() => rectDrawer?.disable()}>禁用</Button>
                <Button onClick={() => rectDrawer?.clear()}>清空</Button>
            </div>

        </CustomControl>
    );
}
const layerOptions: Omit<ImageLayerProps, 'source'> = {
    autoFit: true,
    style: {
        opacity: 0.8,
    },
};
export default function Map() {
    const [options, setOptions] = useState(layerOptions);
    const [source, setSource] = useState({
        data: 'https://gw.alipayobjects.com/mdn/rms_816329/afts/img/A*I0X5R4jAUQ4AAAAAAAAAAAAAARQnAQ',
        parser: {
            type: 'image',
            extent: [36, 40, 64, 60],
        },
    });

    return (
        <LarkMap
            id="map_show"
            mapType="Map"
            mapOptions={{
                center: [0, 0],
                pitch: 0,
                zoom: 3,
                style: "dark",
                version: 'SIMPLE',
                mapSize: 100,
                maxZoom: 5,
                minZoom: 2,
                pitchEnabled: false,
                rotateEnabled: false,
            }}
            className="h-9/10"
        >
            <ImageLayer {...options} source={source} />
            <CustomDraw />
        </LarkMap>
    );
}

🏞 Expected result

预期
1.正常显示,现在经纬度具有约束
2. 可以正常绘制圆等

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG] LayerPopup控制台提示报错

🐛 Bug description [Please make everyone to understand it]

image

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG]ChoroplethLayer中文本的位置不太正常

🐛 Bug description [Please make everyone to understand it]

缩略之后,名字文本都跑到了边界线了。再看看山东省的,直接跑到海里面了
image

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🥰 [FEATURE]LayerSwitchControl组件的poper没有按主题色渲染

💻 Features description [Please make everyone to understand it]

图层显隐组件在任何主题色下弹出框的颜色都是白色,希望可以按主题色渲染

🏞 What problem does this feature solve

现状
image

预期
当前图标图层是暗色,popper的内容区域也应该为黑色

🧐 What does the proposed API look like

🚑 Any additional [like screenshots]

🥰 [FEATURE] Support rotation for IconImageLayer

💻 Features description

Different roation for each icon image in IconImageLayer.

🏞 What problem does this feature solve

Could add direction info on icons.

🧐 What does the proposed API look like

"source": {
  "data": [
    {"x": 1, "y": 1, "angle": 30},
    {"x": 2, "y": 2, "angle": 90}
  ]
}

🚑 Any additional [like screenshots]

🐛 [BUG] LayerPopup展示异常

🐛 Bug description [Please make everyone to understand it]

  1. LayerPopup 绑定ChoroplethLayer
  2. ChoroplethLayer数据变化(参考l7plot的下钻和上卷操作)
  3. 下钻到市,鼠标放到地图外面,没有触发hover
  4. 再双击上卷(ChoroplethLayer的数据变化),此时LayerPopup会莫名其妙的出现一个异常的图层
image

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG] Legend labelUnit 拼写错误, lableUnit ->labelUnit

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG]使用Larkmap的全屏组件-FullscreenControl,开启全屏之后,antd的所有下拉框内容会被隐藏掉,显示不出来。包括message,Select,Cascader,Modal等

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

https://locationinsight.antv.antgroup.com/#/demo/0001?nav=layers
打开这个网址,开启全屏后,地址搜索的下拉框就显示不出来了

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🤔 [QUESTION] 示例代码无法运行

🐛 Question description [Please make everyone to understand it]

使用npx创建ts项目,然后跑示例代码,提示config类型不兼容

💻 Link to minimal reproduction

Please provide a link by forking these links LarkMap or GitHub repo. What is a minimal reproduction, and why is it required?

安装:

$ npx create-react-app antd-l7-test/ --template typescript
$ cd antd-l7-test
$ yarn add @antv/l7 @antv/larkmap
$ yarn

运行:

$ npm run start

src/App.tsx修改为示例代码:

import React from 'react';
import { LarkMap } from '@antv/larkmap';

const config = {
  mapType: 'Gaode',
  mapOptions: {
    style: 'light',
    center: [120.210792, 30.246026],
    zoom: 10,
  },
};

export default () => {
  return <LarkMap {...config} style={{ height: '300px' }}></LarkMap>;
};

报错:

ERROR in src/App.tsx:14:11
TS2322: Type '{ style: { height: string; }; mapType: string; mapOptions: { style: string; center: number[]; zoom: number; }; }' is not assignable to type 'Omit<LarkMapProps & RefAttributes<LarkMapRefAttributes>, "ref">'.
  Types of property 'mapType' are incompatible.
    Type 'string' is not assignable to type '"Gaode" | "GaodeV1" | "GaodeV2" | "Mapbox" | "Map" | "Tencent" | "Baidu" | undefined'.
    12 |
    13 | export default () => {
  > 14 |   return <LarkMap {...config} style={{ height: '300px' }}></LarkMap>;
       |           ^^^^^^^
    15 | };
    16 |

软件版本:

    "@antv/l7": "^2.21.1",
    "@antv/larkmap": "^1.4.13",

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🤔 [QUESTION] 为什么 heatlayer 热力图层的feature始终为null

"@antv/l7": "^2.15.3",
"@antv/larkmap": "^1.3.5",
"react": "^18.2.0",
包信息如上,
同一个点,同一份数据,textLayer点击事件可以获取到feature,heatlayer 获取的feature为null
image
const layerOptions: Omit<HeatmapLayerProps, 'source'> = {
autoFit: true,
shape: 'heatmap' as const,

  size: {
      field: 'radius',
  },

  style: {
      intensity: 3,
      radius: 10,
      opacity: 1,
      rampColors: {
          colors: ['#95de64', '#52c41a', '#ffc069', '#fa8c16', '#ff7875', '#f5222d'],
          positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
      },
  },
  state: {
      active: true,
  },

}
<HeatmapLayer
onClick={(e) => {
console.log(e, 'heatmap clicked')
}}
ref={ref}
id="minganpointHeatlayer"
name="敏感点"
{...layerOptions}
source={source}

const textlayerOptions: Omit<TextLayerProps, 'source'> = {
autoFit: true,
field: 'val',
style: {
fill: {
field: 'val',
value: ['#95de64', '#52c41a', '#ffc069', '#fa8c16', '#ff7875', '#f5222d'],
},
opacity: 1,
fontSize: 14,
textAllowOverlap: false,
padding: [10, 10] as [number, number],
},
}

<TextLayer
{...textlayerOptions}
source={source}
onClick={(e) => {
console.log(e, 'textlayer click')
}}
/>

heatlayer 尝试过用layer.getSource();
source.getFeatureById(featureId); 结果也是null

useDraw cannot enable 🐛 [BUG]

I wrote a custom drawer name LineDrawer:

import { CustomControl, useDraw } from "@antv/larkmap";
import { Feature, LineString, Point } from "geojson";
import React, { useEffect } from "react";

export const LineDrawer: React.FC<{
  start: Point;
  initialData?: Feature<LineString>[];
}> = ({ initialData }) => {
  const {
    draw,
    drawData,
    setDrawData,
    getDrawData,
    isEnable,
    enable,
    disable,
  } = useDraw({
    type: "line",
    options: {
      initialData: initialData,
      showMidPoint: false,
      editable: false,
      distanceOptions: {
        showTotalDistance: true,
        showDashDistance: true,
        format: (meters: number, points: Feature<Point>[]) => {
          if (meters >= 1000) {
            return +(meters / 1000).toFixed(2) + "km";
          } else {
            return +meters.toFixed(2) + "m";
          }
        },
      },
      adsorbOptions: {
        data: "allDrawData",
        pointAdsorbPixel: 20,
        lineAdsorbPixel: 20,
      },
    },
  });

  useEffect(() => {
    enable();
  }, [enable]);

  return (
    <CustomControl>
      <div>
        {<button onClick={enable}>Enable</button>}
        {<button onClick={disable}>Disable</button>}
        <button
          onClick={() => {
            setDrawData([]);
          }}
        >
          Clear
        </button>
        <button
          onClick={() => {
            console.log(getDrawData());
          }}
        >
          Get Data
        </button>
      </div>
    </CustomControl>
  );
};

Use it in a LarkMap:

import { GeoLocate } from "@antv/l7";
import React, { CSSProperties } from "react";
import { Point } from "geojson";
import {
  FullscreenControl,
  LarkMap,
  ZoomControl,
  useScene,
} from "@antv/larkmap";
import gcoord from "gcoord";
import { LineDrawer } from "./line_drawer";

export type LineFragment = {
  __typename?: "Line";
  name?: string | null;
  diameter: number;
  layingHeight: number;
  lineString?: any | null;
};

interface LinesInputProps {
  value?: LineFragment[];
  start: Point;
  onChange?: (value: LineFragment[]) => void;
  style?: CSSProperties;
  theme?: string;
  amapApi: string;
  amapkey: string;
  fullScreenControl?: boolean;
  zoomControl?: boolean;
  //  searchControl?: boolean;
}

export const LinesInput: React.FC<LinesInputProps> = ({
  value,
  start,
  onChange,
  theme,
  amapApi,
  amapkey,
  style = {
    height: 300,
    width: "100%",
  },
  fullScreenControl = true,
  zoomControl = true,
  //   searchControl = false,
}) => {
  return (
    <LarkMap
      style={style}
      mapType="Gaode"
      mapOptions={{
        center: start.coordinates as [number, number],
        style: theme,
        zoom: 12,
        token: amapkey,
        // center: center && (center as [number, number]),
      }}
      onSceneLoaded={(newScene) => {
        const geoLocate = new GeoLocate({
          transform: (position) => {
            // 将获取到基于 WGS84 地理坐标系 的坐标转成 GCJ02 坐标系
            return gcoord.transform(position, gcoord.WGS84, gcoord.GCJ02);
          },
        });
        newScene.addControl(geoLocate);
      }}
      logoVisible={false}
    >
      {fullScreenControl && <FullscreenControl />}
      {zoomControl && <ZoomControl />}
      <LineDrawer start={start} />
    </LarkMap>
  );
};

image

But in LineDrawer, enable is not working, and I got such error:
image
here line_drawer.tsx:43 refers to:

  useEffect(() => {
    enable();
  }, [enable]);

🤔 [QUESTION] how to remove the click listener on the layer when removing the layer

🐛 Question description [Please make everyone to understand it]

I build a new layer - PointLayer and subscribe to a click event.

    layer.on('click', e => {
                console.log('click',e);
                const { lng, lat } = e.lngLat;
     });

when remove this layer with scene.remove(layer), wondering is there any method to unregister the click listener or the scene.remove(layer) can automatically do the job.

    "@antv/l7": "^2.17.8",
    "@antv/l7-core": "^2.21.8",
    "@antv/l7-draw": "^3.1.3",
    "@antv/l7-maps": "^2.17.8",
    "@antv/larkmap": "^1.4.17",

🐛 ChoroplethLayer组件的onCreated方法中监听不到legend的变化

/### 使用ChoroplethLayer行政区下钻组件时,想监听 legend 改变的方法,发现没有生效

<ChoroplethLayer
      id="boundsLayer"
       autoFit: true,
       fillColor: {
         field: 'predictsValue',
         value: [
          '#fadfce',
          '#ffbb96', 
          '#ff8f5b',
          '#fc6e35',
          '#f03c21',
        ]
      },
      zIndex: 0,
      opacity: 0.8,
      lineWidth: 1,
      label: {
        field: 'areaName',
        visible: true,
        style: { fill: 'black', fontSize: 12, stroke: '#fff', strokeWidth: 1 },
      },
      source={{ data: boundData }}
      onCreated={(layer) => {
        layer?.on('legend:color', () => console.log('监听legend:color')); // 无效,没有打印语句
        layer?.on('legend', () => console.log('监听legend')); // 无效,没有打印语句
        layer?.on('dataUpdate', () => console.log('监听legend')); // 生效,有打印语句
      }}
    />

🐛 [BUG] layer 缺少 filter 配置

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG] 图层切换显示组件有问题

我增加了两个图层 控制台报错信息
图片

Warning: Cannot update a component (`LayerSwitchControl2`) while rendering a different component (`ForwardRef(BubbleLayer3)`). To locate the bad setState() call inside `ForwardRef(BubbleLayer3)`, follow the stack trace as described in https://reactjs.org/link/setstate-in-render
BubbleLayer3@http://127.0.0.1:5173/node_modules/.vite/deps/@antv_larkmap.js?v=505fd349:28947:32
AreaMarkLayer@http://127.0.0.1:5173/src/map-features/AreaMarkLayer.tsx:23:39
div
LarkMap2@http://127.0.0.1:5173/node_modules/.vite/deps/@antv_larkmap.js?v=505fd349:23306:12
GaoDeMapInstance@http://127.0.0.1:5173/src/GaoDeMapInstance.tsx?t=1695886767663:48:39
App@http://127.0.0.1:5173/src/App.tsx?t=1695886189350:23:37 react-dom.development.js:86:29
    React 5
    onUpdateLayerList2 index.js:18
    doEmit index.ts:69
    emit index.ts:73
    addLayer layer-manager.js:66
    useCreateLayer2 index.js:45
    BubbleLayer3 index.js:10
    React 8
    workLoop scheduler.development.js:266
    flushWork scheduler.development.js:239
    performWorkUntilDeadline scheduler.development.js:533
    (异步:EventHandlerNonNull)
    js scheduler.development.js:571
    js scheduler.development.js:633
    __require chunk-ROME4SDB.js:11
    js index.js:6
    __require chunk-ROME4SDB.js:11
    React 2
    __require chunk-ROME4SDB.js:11
    js React
    __require chunk-ROME4SDB.js:11
    js React
    __require chunk-ROME4SDB.js:11
    <anonymous> react-dom_client.js:38

右上角只能显示一个图层,不能切换双图层

图片

  • LarkMap Version: 最新版
  • Platform: react 18

🤔 [QUESTION] any code API to add context menu in the scene ?

🐛 Question description [Please make everyone to understand it]

I want to add contextmenu to the scene, I only see the example from https://github.com/antvis/LarkMap/blob/ac6b4de7dc72617f6e9bd0afc077c4bde7c5970a/src/components/ContextMenu/demos/default.tsx#L4 ,which is

      <ContextMenu>
        <ContextMenu.Item  text="放大一级"  onClick={() => {  handleMenu('zoomIn'); }}/>
        <ContextMenu.Item text="缩小一级" onClick={() => handleMenu('zoomOut')} />
        <ContextMenu.Item text="缩放至全国范围" onClick={() => handleMenu('center')} />
      </ContextMenu>

however just wondering is there any code API to have the scene add the context menu ?

        this.scene = new Scene({
            id: 'map',
            map: new GaodeMap(this.map)
        });

best rgds

🐛 [BUG] style 的选项

最新的版本
mapOptions: {
style: 'light',
}

这个style选项设置了高德的自定义地图 怎么没效果??

eslint中报type警告🐛 [BUG]

🐛 Bug description [Please make everyone to understand it]

node_modules/@antv/larkmap/es/components/Legend/LegendProportion/index.less的第10行和第11行:
原来是:
justify-content: end;
align-items: end;
应该改为
justify-content: flex-end;
align-items: flex-end;

🤔 [QUESTION] gaode 主题无法渲染?

🐛 Question description [Please make everyone to understand it]

示例的高德主题 style 和 mapStyle配置均无法生效

💻 Link to minimal reproduction

Please provide a link by forking these links LarkMap or GitHub repo. What is a minimal reproduction, and why is it required?

https://codesandbox.io/p/sandbox/busy-christian-cgykfy?file=%2FApp.jsx%3A8%2C39

🏞 Expected result

黑色主题

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG] marker的onClick的参数类型错误

🐛 Bug description [Please make everyone to understand it]

现在的类型:
image
实际打印出来的结果:
image

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🤔 [QUESTION] 似乎没有完全支持L7Plot的raster部分

🐛 Question description [Please make everyone to understand it]

感谢LarkMap,但是看起来似乎没有完全支持L7的raster部分。
请告诉我怎么做才能实现呢,这个很重要,可以使用L7内部的转换代码将各种数据转换为栅格后传给LarkMap吗

💻 Link to minimal reproduction

source code:

import AMapLoader from '@amap/amap-jsapi-loader';
import { LarkMap, RasterLayer, RasterLayerProps } from '@antv/larkmap';
import React, { useState } from 'react';
import { GaodeMap } from '@antv/l7';

const rasterLayerOptions: Omit<RasterLayerProps, 'source'> = {
    autoFit: true,
    style: {
        opacity: 0.8,
        domain: [0, 2000],
        rampColors: {
            colors: ['#FF4818', '#F7B74A', '#FFF598', '#91EABC', '#2EA9A1', '#206C7C'].reverse(),
            positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
        },
    },
};
const getMapInstance = () => {
    return AMapLoader.load({
        key: '089b120ae9421928984329b9ecec8eba', // 申请好的 Web 端开发者Key,首次调用 load 时必填
        version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
        plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
    }).then((AMap) => {
        return new GaodeMap({
            mapInstance: new AMap.Map('container', {
                zoom: 12, //初始化地图层级
                center: [116.397428, 39.90923], //初始化地图中心点
            }),
        });
    });
};
export default function Map() {
    const [rasterOptions, setRasterOptions] = useState(rasterLayerOptions);
    const [rasterSource, setRasterSource] = useState({
        data: {
            type: "FeatureCollection",
            features: [
                {
                    type: "Feature",
                    geometry: { type: "Point", coordinates: [104.101, 30.649] },
                    properties: { name: "chengdu" },
                },
            ],
        },
        parser: { type: 'geojson' },
        raster: {
            cellSize: 0.002, // 20cm对应的经纬度大小,这个值会因地区和投影方式而略有差异
        },
        transforms: [
            {
                type: 'grid',
                size: 15000,
                field: 't',
                method: 'sum',
            }
        ]
    });
    return (
        <LarkMap
            id="container"
            map={getMapInstance}
            className="h-9/10"
        >
            <RasterLayer {...rasterOptions} source={rasterSource} />
        </LarkMap>
    );
}

image
image

Please provide a link by forking these links LarkMap or GitHub repo. What is a minimal reproduction, and why is it required?

🏞 Expected result

预期:正常运行

🚑 Any additional [like screenshots]

  • LarkMap Version:
    "@antv/l7": "^2.15.2",
    "@antv/l7-draw": "^3.0.20",
    "@antv/larkmap": "^1.3.5",
  • Platform:
    windows

🐛 [BUG]

🐛 React 18 + StrictMode 下, LayerPopup不显示

📷 Step to reproduce

  1. 创建默认的React 18 应用
  2. 拷贝范例代码并替代 App.tsx

🏞 Expected result

鼠标移到区域上后,不显示图层信息框

🚑 Any additional [like screenshots]

将main.tsx中 <React.StrictMode> 注释后,就能显示图层信息框了
ReactDOM.createRoot(document.getElementById('root')!).render(
// <React.StrictMode>
<App />
// </React.StrictMode>,
)

  • LarkMap Version:
    "@antv/l7": "^2.17.7",
    "@antv/larkmap": "^1.4.1",
  • Platform:
    "react": "^18.2.0",
    "react-dom": "^18.2.0"

🤔 [QUESTION]渲染好像有点问题

🐛 Question description [Please make everyone to understand it]

💻 Link to minimal reproduction

import AMapLoader from '@amap/amap-jsapi-loader';
import { CustomControl, LarkMap, useScene, ImageLayerProps, ImageLayer, RasterLayer, RasterLayerProps, HeatmapLayer, HeatmapLayerProps, ZoomControl } from '@antv/larkmap';
import { Button } from '@/components/ui/button';
import React, { useEffect, useState } from 'react';
import { DrawCircle, DrawRect } from '@antv/l7-draw';
import { GaodeMap } from '@antv/l7';

import * as turf from '@turf/turf';
const geoJson = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "properties": {},
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [116.40233, 39.785038],
                        [116.40293, 39.785109],
                        [116.402952, 39.785005],
                        [116.402346, 39.78494]
                    ]
                ]
            }
        }
    ]
}


async function getTiffData() {

    const cellSide = 20; // 20cm对应的经纬度大小,这个值会因地区和投影方式而略有差异
    const options = { units: "centimeters" };
    // const options = { units: "meters" };

    // 根据GeoJSON对象的边界创建栅格
    const bbox = turf.bbox(geoJson);

    // var grid = turf.squareGrid(bbox, cellSide, options);
    var grid = turf.pointGrid(bbox, cellSide, options);
    const result: {
        lng: number,
        lat: number,
        t: number
    }[] = [];
    grid.features.forEach((feature) => {
        result.push({ lng: feature.geometry.coordinates[0], lat: feature.geometry.coordinates[1], t: 1 })
    })

    console.log("async")

    return result;
}
function CustomDraw() {
    const [circleDrawer, setCircleDrawer] = useState<DrawCircle | null>(null);
    const [rectDrawer, setRectDrawer] = useState<DrawRect | null>(null);
    const scene = useScene();
    scene.on('zoomend', (e: any) => { console.log(e) });
    useEffect(() => {
        const drawerRect = new DrawRect(scene, {
            distanceOptions: {},
            areaOptions: {},
        });
        setRectDrawer(drawerRect);
        const drawerCircle = new DrawCircle(scene, {});
        setCircleDrawer(drawerCircle);

    }, []);
    return (
        <CustomControl className="float-right">
            <div style={{ padding: 8 }}>
                circleDrawer
                <Button onClick={() => circleDrawer?.enable()}>启用</Button>
                <Button onClick={() => circleDrawer?.disable()}>禁用</Button>
                <Button onClick={() => circleDrawer?.clear()}>清空</Button>
            </div>
            <div style={{ padding: 8 }}>
                rectDrawer
                <Button onClick={() => rectDrawer?.enable()}>启用</Button>
                <Button onClick={() => rectDrawer?.disable()}>禁用</Button>
                <Button onClick={() => rectDrawer?.clear()}>清空</Button>
            </div>
        </CustomControl>
    );
}
const heatLayerOptions: Omit<HeatmapLayerProps, 'source'> = {
    autoFit: true,
    shape: 'square',
    minZoom: 20,
    maxZoom: 30,
    size: {
        field: 't',
        value: [0, 1.0],
    },
    style: {
        intensity: 3,
        radius: 20,
        opacity: 1,
        rampColors: {
            colors: ['#FF4818', '#F7B74A', '#FFF598', '#F27DEB', '#8C1EB2', '#421EB2'],
            positions: [0, 0.2, 0.4, 0.6, 0.8, 1.0],
        },
    },
};
const getMapInstance = () => {
    return AMapLoader.load({
        key: '089b120ae9421928984329b9ecec8eba', // 申请好的 Web 端开发者Key,首次调用 load 时必填
        version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
        plugins: [], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
    }).then((AMap) => {
        return new GaodeMap({
            mapInstance: new AMap.Map('container', {
                zoom: 29.8, //初始化地图层级
                zooms: [2, 30],
                center: [116.397428, 39.90923], //初始化地图中心点
            }),
        });
    });
};



export default function Map() {
    const [heatOptions, setHeatOptions] = useState(heatLayerOptions);
    const [heatSource, setHeatSource] = useState({
        data: [],
        parser: { type: 'json', x: 'lng', y: 'lat' }
    });
    useEffect(() => {
        getTiffData()
            .then((data: any) => {
                setHeatSource((prevState) => ({ ...prevState, data }));
            });
    }, []);

    return (
        <LarkMap
            id="container"
            map={getMapInstance}
            className="h-9/10"
        >
            <HeatmapLayer {...heatLayerOptions} source={heatSource} />
            <ZoomControl/>
            <CustomDraw />
        </LarkMap>
    );
}

image
image

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • Platform:

🐛 [BUG]在获取sence示例的时候,ref无法正常获取

🐛 Bug description [Please make everyone to understand it]

在获取sence示例的时候,ref无法正常获取
TS2322: Type 'MutableRefObject<LarkMapRefAttributes | undefined>' is not assignable to type 'Ref | undefined'.
Type 'MutableRefObject<LarkMapRefAttributes | undefined>' is not assignable to type 'RefObject'.
Types of property 'current' are incompatible.
Type 'LarkMapRefAttributes | undefined' is not assignable to type 'LarkMapRefAttributes | null'.
Type 'undefined' is not assignable to type 'LarkMapRefAttributes | null'.

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

  • Required Link to minimal reproduction:

📷 Step to reproduce

image
image

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version:
  • 当前版本
  • Platform:
  • windows

🐛 [BUG] Error when used with Next.js

🐛 Bug description [Please make everyone to understand it]

Please provide a link by forking these links LarkMap or GitHub repo, a minimal reproduction.

"use client"
import type { LarkMapProps } from '@antv/larkmap';
import { LarkMap } from '@antv/larkmap';
import React from 'react';

const config: LarkMapProps = {
    mapType: 'Gaode',
    mapOptions: {
        style: 'light',
        center: [120.210792, 30.246026],
        zoom: 9,
        // token: '你申请的 Key',
    },
};

export default function L7Map() {
    return (
        <LarkMap {...config} style={{ height: '300px' }}>
            <h2 style={{ position: 'absolute', left: '10px' }}>LarkMap</h2>
        </LarkMap>
    )
}

📷 Step to reproduce

next.config.js

const webpack = require('webpack');
const withLess = require('next-with-less');

const nextConfig = {
    reactStrictMode: true,
    webpack: config => {
      config.plugins.push(
        new webpack.DefinePlugin({
          CESIUM_BASE_URL: JSON.stringify('cesium'),
        }),
      );
      return config;
    },
    // experimental: true
    experimental : {
      esmExternals: 'loose',
    }
}

module.exports = withLess(nextConfig)

Error message reported by Next.js

- error ./node_modules/@antv/larkmap/es/components/ContextMenu/index.less
Global CSS cannot be imported from within node_modules.
Read more: https://nextjs.org/docs/messages/css-npm
Location: node_modules\@antv\larkmap\es\components\ContextMenu\index.js

🏞 Expected result

🚑 Any additional [like screenshots]

  • LarkMap Version: latest
  • Platform: windows and linux

🥰 图片/字体资源注册异步方式

💻 图片/字体资源统一注册使用方式

🏞 cene.addImage 是异步的,图层可能先渲染导致没有出来,当下解决的方案 await scene.addImage 完成再渲染图层

import { LarkMap } from '@antv/larkmap';

export default () => {
const [loadedImages, setLoadedImages] = useState(false);
  const onSceneLoaded = (scene: Scene) => {
	scene.addImage('name', url).then(() => {
		setLoadedImages(true);
	})
    console.log(scene);
  };

  return (
    <LarkMap mapType="Gaode" style={{ height: '300px' }} onSceneLoaded={onSceneLoaded}>
      { loadedImages && <PointLayer {...options} source={source} /> }
    </LarkMap>
  );
};

🧐 What does the proposed API look like

import { LarkMap } from '@antv/larkmap';

const images = [
  { id: '01', image: 'https://gw.alipayobjects.com/zos/basement_prod/604b5e7f-309e-40db-b95b-4fac746c5153.svg' },
  { id: '02', image: 'https://gw.alipayobjects.com/zos/basement_prod/30580bc9-506f-4438-8c1a-744e082054ec.svg' },
  { id: '03', image: 'https://gw.alipayobjects.com/zos/basement_prod/7aa1f460-9f9f-499f-afdf-13424aa26bbf.svg' },
];

export default () => {
  const onSceneLoaded = (scene: Scene) => {
    console.log(scene);
  };

  return (
    <LarkMap mapType="Gaode" style={{ height: '300px' }} onSceneLoaded={onSceneLoaded} registerImages={images} >
      <PointLayer {...options} source={source} />
    </LarkMap>
  );
};

🚑 Any additional

统一管理缺点就是加载资源失败,还是需要 try catch 不能让所有图层出不来

🐛 [BUG]MapLibre 不显示地图

代码如下

import { LarkMap, LayerPopup, PointLayer, ScaleControl, ZoomControl } from '@antv/larkmap';
import type { LarkMapProps, LayerPopupProps, PointLayerProps } from '@antv/larkmap';
import {MapLibre} from "@antv/l7";

const config: LarkMapProps = {
  map: new MapLibre({
    zoom: 10,
    style: 'https://api.maptiler.com/maps/streets/style.json?key=YbCPLULzWdf1NplssEIc',
    minZoom: 0,
    maxZoom: 18,
  }),
}

我这么设置MapLibre,结果地图显示不了,然后控制台报错
Uncaught ReferenceError: _wrapNativeSuper is not defined
只显示了背景,没地图
企业微信截图_20240607174443

🐛 LayerPopup 复合图层情况

🐛 LayerPopup 复合图层报错

https://github.com/antvis/LarkMap/blob/main/src/components/LayerPopup/index.tsx#L47

  1. 直接复合图层报错
  2. 复合多主图层情况未考虑
  3. typeof item.layer === 'string' 情况。未找到是否跳出当前循环,不 console.error,console.warn ?
map((layer) => {
    if (layer.isComposite) {
      const layers = (layer as ICompositeLayer).getInteractionSubLayers();
      return layers.map((_layer) => _layer as unknown as ILayer);
    }
    return _layer as unknown as ILayer
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.