美文网首页
2020-08-04 es6+ol

2020-08-04 es6+ol

作者: 飞天宵夜 | 来源:发表于2020-08-04 19:30 被阅读0次

新建文件夹并安装依赖

mkdir new-project && cd new-project
npm init
npm install ol
npm install --save-dev parcel-bundler

新建index.js

import 'ol/ol.css';
import {Map, View} from 'ol';
import TileLayer from 'ol/layer/Tile';
import OSM from 'ol/source/OSM';

const map = new Map({
  target: 'map',
  layers: [
    new TileLayer({
      source: new OSM()
    })
  ],
  view: new View({
    center: [0, 0],
    zoom: 0
  })
});

新建index.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Using Parcel with OpenLayers</title>
    <style>
      #map {
        width: 400px;
        height: 250px;
      }
    </style>
  </head>
  <body>
    <div id="map"></div>
    <script src="./index.js"></script>
  </body>
</html>

运行脚本

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "parcel index.html",
    "build": "parcel build --public-url . index.html"
  },
  "author": "",
  "license": "ISC"
}

脚本命令

运行

npm start

打包

npm run build

相关文章

网友评论

      本文标题:2020-08-04 es6+ol

      本文链接:https://www.haomeiwen.com/subject/vetgrktx.html