-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
5,492 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { useEffect, useRef } from 'react' | ||
import L from 'leaflet' | ||
import { TiledMapLayer } from '@supermapgis/iclient-leaflet' | ||
import 'leaflet/dist/leaflet.css' | ||
import 'leaflet.markercluster/dist/leaflet.markercluster-src.js' | ||
import 'leaflet.markercluster/dist/MarkerCluster.css' | ||
import 'leaflet.markercluster/dist/MarkerCluster.Default.css' | ||
import markerIcon from './icon.png' | ||
|
||
import styles from './index.module.less' | ||
|
||
const SuperMap = () => { | ||
const superMapRef = useRef(null) | ||
const tiledLayerRef = useRef(null) | ||
const markerClusterRef = useRef(null) | ||
|
||
const iconList = [ | ||
{ | ||
locationX: 121.44, | ||
locationY: 31.25, | ||
}, | ||
{ | ||
locationX: 121.54, | ||
locationY: 31.14, | ||
}, | ||
{ | ||
locationX: 121.473919, | ||
locationY: 30.955082, | ||
}, | ||
{ | ||
locationX: 121.447153, | ||
locationY: 30.800443, | ||
}, | ||
] | ||
|
||
useEffect(() => { | ||
initSuperMap() | ||
}, []) | ||
|
||
useEffect(() => { | ||
getResultLayer(iconList) | ||
}, []) | ||
const initSuperMap = () => { | ||
const url = 'https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4326' | ||
|
||
const map = L.map('superMap', { | ||
preferCanvas: true, | ||
crs: L.CRS.EPSG4326, | ||
center: [30.92, 121.56], | ||
maxZoom: 18, | ||
minZoom: 3, | ||
zoom: 3, | ||
attributionControl: false, | ||
zoomControl: true, | ||
}) | ||
const layer = new TiledMapLayer(url) | ||
layer.addTo(map) | ||
superMapRef.current = map | ||
tiledLayerRef.current = layer | ||
|
||
// map.on('click', function (e) { | ||
// console.log('e', e); | ||
// }); | ||
} | ||
|
||
const getResultLayer = (projectList) => { | ||
if (markerClusterRef.current) { | ||
superMapRef?.current?.removeLayer(markerClusterRef.current) | ||
} | ||
|
||
const markerCluster = L.markerClusterGroup({ | ||
spiderfyOnMaxZoom: true, | ||
showCoverageOnHover: false, | ||
zoomToBoundsOnClick: true, | ||
}) | ||
|
||
markerClusterRef.current = markerCluster | ||
|
||
projectList.forEach((element) => { | ||
const lat = element.locationY | ||
const lon = element.locationX | ||
|
||
const iconUrl = markerIcon | ||
|
||
const myIcon = L.icon({ | ||
iconUrl, | ||
iconSize: [20, 24], | ||
}) | ||
|
||
const marker = L.marker([lat, lon], { | ||
icon: myIcon, | ||
}) | ||
|
||
markerCluster.addLayer(marker) | ||
}) | ||
|
||
superMapRef?.current?.addLayer(markerCluster) | ||
} | ||
|
||
return ( | ||
<section className={styles.homeBox}> | ||
<div id="superMap" className={styles.superMap} ref={superMapRef}></div> | ||
</section> | ||
) | ||
} | ||
|
||
export default SuperMap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.superMap{ | ||
width: 1200px; | ||
height: 600px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters