|React+Openlayuers 模板(学习中,持续更新)

基础模板基础
import React { createRef useEffect useReffrom 'react';
import { Map View Feature Overlayfrom 'ol';
import reactDom from 'react-dom';
import TileLayer from 'ol/layer/Tile';
import { OSMfrom 'ol/source';
import { Point LineStringfrom 'ol/geom'; //点
import { Icon Stroke Stylefrom 'ol/style';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import 'ol/ol.css';
import styles from './index.less';
import poiImg from '@/assets/images/house.png';
import ycdl from '../json/ycdl.json'
const Index: React.FC = () => {
// 地图
const map = useRef<any>();
// 地图容器
const mapDom = createRef<HTMLDivElement>();
useEffect(() => {
// 初始化地图
initMap()
// 加载标注
createFeature(ycdl.features[0
.geometry.coordinates poiImg 'iconFeature');
//加载线
createLine(ycdl.features[0
.geometry.coordinates poiImg 'lineFeature');
//加载信息框
createInfo()
);
/**
* 初始化地图
*/
const initMap = () => {
map.current = new Map({
target: 'map'
layers: [
new TileLayer({
source: new OSM()
)
view: new View({
center: [111.286962 30.69217
projection: 'EPSG:4326'
zoom: 14
)
);
//创建标注
const createFeature = (featureData: Array<any> featureImg: string layerId: string) => {
// 创建标注
if (featureData.length > 0) {
let iconFeatures: any;
iconFeatures = new Array();
featureData.forEach((v index) => {
iconFeatures.push(new Feature({
geometry: new Point([...v
)
))
iconFeatures[index
- 网友热议|母亲回应3个孩子2个上清华:只能教孩子做人诚实守信 学习都靠自己努力
- 格力电器|不要再说Python难了,按照这个学习路线,四周速成Python
- OPPO|准大学生看过来!满足大学四年学习、生活需求平板,三件套不到2K
- 京东|Java:有哪些快速学习Java语言的技巧?
- meta|学习通被曝泄露1.7亿条信息!网友:快下架吧
- 零售业|陈根:学习通被曝大规模信息泄露,争议之下还有三点重要思考
- 新东方|新东方的成功转型,这几点不正是跨境电商卖家们需要学习的地方吗!
- 明码标价|3000元可购买整个学习通数据库?我们的信息被公开售卖,明码标价
- saas|学习通被曝信息泄露:超 1.7 亿条隐私数据仅售卖 1.2 万元!
- 伊隆·马斯克|网传学习通1.7亿密码泄露!有什么补救措施?
