diff --git a/dev-demos/bugs/heatmap/demos/map.tsx b/dev-demos/bugs/heatmap/demos/map.tsx index 0bbe4d4b10..59a7c4dcb0 100644 --- a/dev-demos/bugs/heatmap/demos/map.tsx +++ b/dev-demos/bugs/heatmap/demos/map.tsx @@ -9,7 +9,7 @@ export default () => { const scene = new Scene({ id: 'map', - map: new GaodeMap({ + map: new Map({ style: 'light', pitch: 0, center: [ 114.07737552216226, 22.542656745583486 ], diff --git a/dev-demos/bugs/polygon/demos/scale.tsx b/dev-demos/bugs/polygon/demos/scale.tsx index 7a065c99cb..ab2e49f1f2 100644 --- a/dev-demos/bugs/polygon/demos/scale.tsx +++ b/dev-demos/bugs/polygon/demos/scale.tsx @@ -3,74 +3,1261 @@ // @ts-ignore import { PolygonLayer, Scene } from '@antv/l7'; // @ts-ignore -import {GaodeMap } from '@antv/l7-maps'; +import { GaodeMap, Map, GaodeMapV1 } from '@antv/l7-maps'; import React, { useEffect } from 'react'; - +const data = { + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [ + [ + [ + [ + 67.789833, + 37.184776 + ], + [ + 67.633331, + 37.248444 + ], + [ + 67.440308, + 37.233139 + ], + [ + 67.26397, + 37.188499 + ], + [ + 67.098335, + 37.330387 + ], + [ + 66.971359, + 37.386749 + ], + [ + 66.683365, + 37.337223 + ], + [ + 66.52597, + 37.347584 + ], + [ + 66.530746, + 37.402973 + ], + [ + 66.63958, + 37.439529 + ], + [ + 66.637054, + 37.483944 + ], + [ + 66.538277, + 37.579472 + ], + [ + 66.548226, + 37.791779 + ], + [ + 66.676636, + 37.961971 + ], + [ + 66.620193, + 38.014027 + ], + [ + 66.496559, + 38.041862 + ], + [ + 66.400002, + 38.032471 + ], + [ + 66.245529, + 38.154026 + ], + [ + 65.851501, + 38.274082 + ], + [ + 65.797447, + 38.235863 + ], + [ + 65.481362, + 38.319 + ], + [ + 65.300552, + 38.408501 + ], + [ + 65.025024, + 38.612473 + ], + [ + 64.826195, + 38.679749 + ], + [ + 64.522835, + 38.838223 + ], + [ + 64.331024, + 38.985863 + ], + [ + 64.177109, + 38.959194 + ], + [ + 63.745388, + 39.206722 + ], + [ + 63.539139, + 39.383583 + ], + [ + 63.170418, + 39.574112 + ], + [ + 62.797974, + 39.775749 + ], + [ + 62.487946, + 39.951389 + ], + [ + 62.3965, + 40.099278 + ], + [ + 62.413776, + 40.1735 + ], + [ + 62.393166, + 40.31078 + ], + [ + 62.333248, + 40.383446 + ], + [ + 62.349472, + 40.438305 + ], + [ + 62.207722, + 40.50853 + ], + [ + 62.113083, + 40.596111 + ], + [ + 62.000111, + 40.820332 + ], + [ + 61.97089, + 41.019138 + ], + [ + 61.882668, + 41.118805 + ], + [ + 61.626888, + 41.264999 + ], + [ + 61.421554, + 41.285889 + ], + [ + 61.379917, + 41.16489 + ], + [ + 61.299805, + 41.145222 + ], + [ + 61.171333, + 41.173248 + ], + [ + 61.046055, + 41.234695 + ], + [ + 60.505585, + 41.216473 + ], + [ + 60.131249, + 41.394833 + ], + [ + 60.093723, + 41.43211 + ], + [ + 60.111889, + 41.548138 + ], + [ + 60.16375, + 41.609528 + ], + [ + 60.068584, + 41.7285 + ], + [ + 60.083637, + 41.809334 + ], + [ + 60.231472, + 41.765751 + ], + [ + 60.258389, + 41.815418 + ], + [ + 60.045056, + 41.916416 + ], + [ + 60.029999, + 42.009724 + ], + [ + 59.970196, + 42.128223 + ], + [ + 60.039139, + 42.195915 + ], + [ + 59.827972, + 42.306305 + ], + [ + 59.717609, + 42.285973 + ], + [ + 59.419251, + 42.276554 + ], + [ + 59.270638, + 42.39286 + ], + [ + 59.277443, + 42.438835 + ], + [ + 59.169472, + 42.528027 + ], + [ + 59.047833, + 42.510723 + ], + [ + 58.934696, + 42.54364 + ], + [ + 58.702499, + 42.726528 + ], + [ + 58.59536, + 42.665943 + ], + [ + 58.472668, + 42.650307 + ], + [ + 58.297165, + 42.689445 + ], + [ + 58.154778, + 42.609722 + ], + [ + 58.306473, + 42.548248 + ], + [ + 58.323444, + 42.448082 + ], + [ + 58.201195, + 42.467388 + ], + [ + 58.134724, + 42.442528 + ], + [ + 58.053276, + 42.504471 + ], + [ + 57.915138, + 42.457222 + ], + [ + 57.947304, + 42.371639 + ], + [ + 57.928528, + 42.24514 + ], + [ + 57.847195, + 42.246307 + ], + [ + 57.835472, + 42.172943 + ], + [ + 57.67561, + 42.151974 + ], + [ + 57.521694, + 42.174084 + ], + [ + 57.312805, + 42.137806 + ], + [ + 57.214111, + 42.068417 + ], + [ + 57.129971, + 41.943584 + ], + [ + 57.001526, + 41.896 + ], + [ + 56.967583, + 41.804554 + ], + [ + 56.972195, + 41.672359 + ], + [ + 57.01989, + 41.586418 + ], + [ + 57.031639, + 41.445862 + ], + [ + 57.086555, + 41.374889 + ], + [ + 57.042415, + 41.263222 + ], + [ + 56.432529, + 41.299915 + ], + [ + 56.00061, + 41.318054 + ], + [ + 56.000084, + 42.017166 + ], + [ + 55.999416, + 42.944363 + ], + [ + 55.998833, + 43.743832 + ], + [ + 55.998501, + 44.221279 + ], + [ + 55.998112, + 45 + ], + [ + 57.356388, + 45.310917 + ], + [ + 57.990749, + 45.449139 + ], + [ + 58.578686, + 45.599289 + ], + [ + 59.099235, + 45.341999 + ], + [ + 60.001514, + 44.999783 + ], + [ + 61.111194, + 44.35775 + ], + [ + 61.121418, + 44.268665 + ], + [ + 61.413582, + 44.016445 + ], + [ + 61.975639, + 43.512279 + ], + [ + 62.028694, + 43.486527 + ], + [ + 63.208057, + 43.6525 + ], + [ + 63.388889, + 43.672863 + ], + [ + 63.911888, + 43.628082 + ], + [ + 64.53653, + 43.603306 + ], + [ + 65.010246, + 43.766861 + ], + [ + 65.17025, + 43.743557 + ], + [ + 65.294136, + 43.545277 + ], + [ + 65.651085, + 43.303528 + ], + [ + 65.827194, + 42.868137 + ], + [ + 66.099198, + 42.962196 + ], + [ + 66.105667, + 42.347332 + ], + [ + 66.016441, + 42.378418 + ], + [ + 66.008552, + 41.943501 + ], + [ + 66.530746, + 41.896305 + ], + [ + 66.60611, + 41.251415 + ], + [ + 67.311165, + 41.211807 + ], + [ + 67.743469, + 41.201946 + ], + [ + 67.918611, + 41.156945 + ], + [ + 68.030555, + 41.0775 + ], + [ + 67.975278, + 40.909722 + ], + [ + 67.985556, + 40.846667 + ], + [ + 68.061945, + 40.771111 + ], + [ + 68.443611, + 40.596111 + ], + [ + 68.617222, + 40.613333 + ], + [ + 68.423055, + 40.705556 + ], + [ + 68.451944, + 40.769167 + ], + [ + 68.445555, + 40.916111 + ], + [ + 68.371389, + 41.045 + ], + [ + 68.435278, + 41.094722 + ], + [ + 68.652679, + 40.940998 + ], + [ + 68.744804, + 40.987446 + ], + [ + 68.829529, + 41.116222 + ], + [ + 68.988197, + 41.253193 + ], + [ + 69.033249, + 41.342167 + ], + [ + 69.231476, + 41.461723 + ], + [ + 69.307442, + 41.450863 + ], + [ + 69.406387, + 41.504444 + ], + [ + 69.621086, + 41.658028 + ], + [ + 69.832802, + 41.719082 + ], + [ + 69.95211, + 41.718807 + ], + [ + 69.984558, + 41.780804 + ], + [ + 70.159752, + 41.844307 + ], + [ + 70.240303, + 41.941166 + ], + [ + 70.330887, + 41.975613 + ], + [ + 70.322609, + 42.034363 + ], + [ + 70.433304, + 42.130085 + ], + [ + 70.626976, + 42.000832 + ], + [ + 70.693581, + 42.126835 + ], + [ + 70.800942, + 42.209862 + ], + [ + 70.940224, + 42.259193 + ], + [ + 71.070274, + 42.287834 + ], + [ + 71.261139, + 42.195946 + ], + [ + 70.966225, + 42.026333 + ], + [ + 70.861641, + 42.041805 + ], + [ + 70.85025, + 41.945168 + ], + [ + 70.656586, + 41.891445 + ], + [ + 70.508888, + 41.776333 + ], + [ + 70.492386, + 41.718861 + ], + [ + 70.348251, + 41.637749 + ], + [ + 70.195557, + 41.598305 + ], + [ + 70.186165, + 41.518555 + ], + [ + 70.320274, + 41.514416 + ], + [ + 70.483391, + 41.399612 + ], + [ + 70.594803, + 41.448029 + ], + [ + 70.715942, + 41.460972 + ], + [ + 70.780083, + 41.375389 + ], + [ + 70.783165, + 41.188194 + ], + [ + 70.875359, + 41.231445 + ], + [ + 70.96167, + 41.163082 + ], + [ + 71.019279, + 41.192665 + ], + [ + 71.124252, + 41.147221 + ], + [ + 71.257469, + 41.186359 + ], + [ + 71.392502, + 41.11211 + ], + [ + 71.435082, + 41.123611 + ], + [ + 71.487694, + 41.316029 + ], + [ + 71.591003, + 41.30339 + ], + [ + 71.731308, + 41.456833 + ], + [ + 71.799309, + 41.431446 + ], + [ + 71.935165, + 41.308277 + ], + [ + 71.861999, + 41.200863 + ], + [ + 71.890358, + 41.172165 + ], + [ + 72.083557, + 41.140888 + ], + [ + 72.192718, + 41.154861 + ], + [ + 72.228363, + 41.052418 + ], + [ + 72.351692, + 41.064777 + ], + [ + 72.497582, + 41.03064 + ], + [ + 72.5755, + 40.890472 + ], + [ + 72.680809, + 40.85561 + ], + [ + 72.834808, + 40.869472 + ], + [ + 73.005722, + 40.767082 + ], + [ + 72.848587, + 40.688915 + ], + [ + 72.767113, + 40.675499 + ], + [ + 72.762085, + 40.57 + ], + [ + 72.683525, + 40.593166 + ], + [ + 72.636665, + 40.51939 + ], + [ + 72.476303, + 40.564056 + ], + [ + 72.4105, + 40.401249 + ], + [ + 72.183502, + 40.498249 + ], + [ + 71.997055, + 40.332416 + ], + [ + 71.939476, + 40.22464 + ], + [ + 71.716194, + 40.150806 + ], + [ + 71.680191, + 40.231972 + ], + [ + 71.551056, + 40.199638 + ], + [ + 71.486916, + 40.262417 + ], + [ + 71.277336, + 40.326721 + ], + [ + 71.118225, + 40.319332 + ], + [ + 70.963165, + 40.259918 + ], + [ + 70.967613, + 40.2285 + ], + [ + 70.645614, + 40.165028 + ], + [ + 70.570999, + 40.244694 + ], + [ + 70.550529, + 40.34589 + ], + [ + 70.385223, + 40.376499 + ], + [ + 70.332664, + 40.449249 + ], + [ + 70.494835, + 40.511391 + ], + [ + 70.630333, + 40.620918 + ], + [ + 70.735496, + 40.657585 + ], + [ + 70.789665, + 40.72514 + ], + [ + 70.654724, + 40.761528 + ], + [ + 70.673836, + 40.848389 + ], + [ + 70.534553, + 40.992085 + ], + [ + 70.440529, + 41.041222 + ], + [ + 70.370476, + 40.928944 + ], + [ + 70.21492, + 40.826305 + ], + [ + 70.155197, + 40.834332 + ], + [ + 70.080277, + 40.765167 + ], + [ + 69.922752, + 40.703888 + ], + [ + 69.767555, + 40.688778 + ], + [ + 69.667664, + 40.629944 + ], + [ + 69.547859, + 40.753502 + ], + [ + 69.40097, + 40.782028 + ], + [ + 69.348358, + 40.712082 + ], + [ + 69.363388, + 40.615528 + ], + [ + 69.273941, + 40.495361 + ], + [ + 69.338997, + 40.347889 + ], + [ + 69.259247, + 40.248196 + ], + [ + 69.316139, + 40.201584 + ], + [ + 68.999473, + 40.220528 + ], + [ + 68.77533, + 40.197723 + ], + [ + 68.53833, + 40.14061 + ], + [ + 68.608414, + 40.091778 + ], + [ + 68.872864, + 40.146362 + ], + [ + 68.977386, + 40.151669 + ], + [ + 69.014221, + 40.080223 + ], + [ + 68.889389, + 40.068028 + ], + [ + 68.812385, + 40 + ], + [ + 68.912941, + 39.904335 + ], + [ + 68.716247, + 39.869335 + ], + [ + 68.591888, + 39.724304 + ], + [ + 68.62664, + 39.650749 + ], + [ + 68.514893, + 39.534084 + ], + [ + 68.034142, + 39.576111 + ], + [ + 67.796776, + 39.654362 + ], + [ + 67.713692, + 39.656445 + ], + [ + 67.628166, + 39.600029 + ], + [ + 67.498726, + 39.571861 + ], + [ + 67.425468, + 39.496971 + ], + [ + 67.518974, + 39.338696 + ], + [ + 67.39228, + 39.299835 + ], + [ + 67.462082, + 39.203194 + ], + [ + 67.677864, + 39.144001 + ], + [ + 67.715362, + 38.999668 + ], + [ + 67.975693, + 39.033333 + ], + [ + 68.115364, + 39.010029 + ], + [ + 68.199081, + 38.926109 + ], + [ + 68.196976, + 38.851307 + ], + [ + 68.072975, + 38.803501 + ], + [ + 68.127693, + 38.741196 + ], + [ + 68.068474, + 38.540668 + ], + [ + 68.196747, + 38.406055 + ], + [ + 68.233582, + 38.32864 + ], + [ + 68.320335, + 38.292526 + ], + [ + 68.402641, + 38.195 + ], + [ + 68.369919, + 38.078472 + ], + [ + 68.284553, + 37.984028 + ], + [ + 68.270279, + 37.90939 + ], + [ + 68.128754, + 37.877277 + ], + [ + 68.042724, + 37.736584 + ], + [ + 67.938751, + 37.640278 + ], + [ + 67.828361, + 37.463276 + ], + [ + 67.820778, + 37.234806 + ], + [ + 67.789833, + 37.184776 + ] + ] + ] + ] + }, + "properties": { + "name": "乌兹别克斯坦", + "name_en": "UZBEKISTAN", + "code": "UZB", + "centroid": [ + 66.37492049999999, + 40.84882956333334 + ] + } + } + ] +} +console.log(data); export default () => { - useEffect( () => { - const scene = new Scene({ - id: 'map', - map: new GaodeMap({ - center: [ 110, 36 ], - style: 'light', - zoom: 3 - }) - }); - const data = fetch('https://gw.alipayobjects.com/os/raptor/1669276113315/33.json').then(res=>res.json()).then((data)=>{ - const features = data.features.map((fe)=>{ - const name = fe.properties.name; - fe.properties.value = name ==='杭州市'? 46:0; - return fe; - }) + useEffect(() => { + const scene = new Scene({ + id: 'map', + map: new Map({ + center: [64.50191700000005, 41.52862851827109], + style: 'light', + zoom: 5 + }) + }); + // @ts-ignore + window.scene = scene; - const fill = new PolygonLayer({ - autoFit:true - }) - .source({ - type: 'FeatureCollection', - features, - }) - .shape('fill') - .scale('value',{ - type:'quantile' - }) - .color('value',[ - "rgb(247, 251, 255)", - "rgb(222, 235, 247)", - "rgb(198, 219, 239)", - "rgb(158, 202, 225)", - "rgb(107, 174, 214)", - "rgb(66, 146, 198)", - "rgb(33, 113, 181)", - "rgb(8, 81, 156)", - "rgb(8, 48, 107)" - ]) - .style({ - opacity:1, - - }); + const fill = new PolygonLayer({ + autoFit: true + }) + .source(data) + .shape('fill') + .color('red') + .style({ + opacity: 0.6, - scene.addLayer(fill); - fill.on('inited',()=>{ - console.log(fill.getLegend('color')) - }) - - console.log(fill); - - }) - + }); + const line = new PolygonLayer({ + autoFit: false + }) + .source(data) + .shape('line') + .size(2) + .color('rgb(255, 48, 107)') + .style({ + opacity: 1, - - - }, []); - return ( -
- ); - }; - \ No newline at end of file + }); + + scene.addLayer(fill); + // scene.addLayer(line); + // scene.on('zoom', () => { + // console.log(scene.getZoom(), scene.getCenter()) + // }) + + + }, []); + return ( + + ); +}; diff --git a/packages/site/docs/api/scene.zh.md b/packages/site/docs/api/scene.zh.md index ab18326005..040b2dd1d3 100644 --- a/packages/site/docs/api/scene.zh.md +++ b/packages/site/docs/api/scene.zh.md @@ -355,7 +355,9 @@ export interface ICameraOptions { type ICenter = [number, number]; scene.setZoomAndCenter(zoom, center); ``` + ### setZoom(zoom: number): void 设置地图旋转 + 设置地图缩放等级 ```javascript diff --git a/packages/utils/src/workers/triangulation.ts b/packages/utils/src/workers/triangulation.ts index 613e8758b7..be03a2af4a 100644 --- a/packages/utils/src/workers/triangulation.ts +++ b/packages/utils/src/workers/triangulation.ts @@ -64,11 +64,29 @@ export function PointFillTriangulation(feature: IEncodeFeature) { export function polygonFillTriangulation(feature: IEncodeFeature) { const { coordinates } = feature; - const flattengeo = earcut.flatten(coordinates as number[][][]); + // @ts-ignore + const flatCoord = coordinates.map((coord: number[][]) => coord.map((lnglat: [number, number]) => [lnglat[0], project_y(lnglat[1])])) + const flattengeo = earcut.flatten(flatCoord as number[][][]); const { vertices, dimensions, holes } = flattengeo; + // https://github.com/mapbox/earcut/issues/159 + const triangles = earcut(vertices, holes, dimensions); + for (let i = 0; i < vertices.length; i += 2) { + vertices[i + 1] = un_project_y(vertices[i + 1]); + } + return { - indices: earcut(vertices, holes, dimensions), + indices: triangles, vertices, size: dimensions, }; } + +function project_y( y: number) { + return Math.log(Math.tan(Math.PI * y / 360)) +} + +function un_project_y( y: number) { + + return Math.atan(Math.exp(y)) * 360 / Math.PI + +}