
前端进阶(十三)-GIS
import { LoadScript, GoogleMap, Marker, InfoWindow } from '@react-google-maps/api'
const map = () => {
return (
<GoogleMap
center={center}
zoom={zoom}
mapContainerStyle={{
width: '100%',
height: '100%',
...mapContainerStyle,
}}
{...otherProps}
>
{children}
<Marker
key={`${coord.lat}-${coord.lng}`}
position={coord}
icon={{
url,
size,
}}
onClick={() => {
setInfoCoord(coord)
}}
/>
</GoogleMap>
)
}Marker: 点
useGoogleMap: 对map进行操作
import { useGoogleMap, useJsApiLoader } from '@react-google-maps/api'
const react = () => {
const map = useGoogleMap()
const { isLoaded } = useJsApiLoader({
googleMapsApiKey: GOOGLE_MAP_API_KEY,
libraries: ['drawing', 'places', 'visualization', 'marker'],
})
map.setCenter()
}https://github.com/mapbox/mapbox-gl-js
https://github.com/visgl/deck.gl
https://juejin.cn/post/7379909196340527113
https://l7.antv.antgroup.com/api/scene
https://zhuanlan.zhihu.com/p/499249093
地理分析库
https://turfjs.fenxianglu.cn/docs/api/center
在react中基于google map自动补全地址
import React from 'react';
import { GoogleMaps } from 'google-maps';
import PlacesAutocomplete from 'react-places-autocomplete';
class App extends React.Component {
handleSelect = address => {
console.log('Selected:', address);
};
render() {
return (
<PlacesAutocomplete
wrapperElement={<div style={{ width: '200px' }} />}
onSelect={this.handleSelect}
>
{({ getInputProps, suggestions, getSuggestionItemProps, loading }) => (
<input {...getInputProps({ placeholder: 'Search Places' })} />
{suggestions.map(suggestion => (
<div {...getSuggestionItemProps({ suggestion })}>
{suggestion.description}
</div>
))}
</PlacesAutocomplete>
);
}
}聚合地图点展示