1.0.1 • Published 1 year ago

openlayer-tool v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

ol-tool openlayers 地图加载工具类

npm i openlayer-tool
yarn add openlayer-tool

示例 加载天地图

<template>
  <div id="map"></div>
</template>

<script>
// 加载工具类
import WebGis from "openlayer-tool";
//加载css
import "openlayer-tool/dist/webGis.css";

export default {
  data() {
    return {
      view: null,
    };
  },
  methods: {
    init() {
      this.view = new WebGis({ id: "map" });
      // 初始化
      this.view.initTdt("你的天地图key", () => {
        // 设置中心点
        this.view.webgis.setCenter([121.39444245258065, 31.170587645068945]);
        // 设置缩放比例
        this.view.webgis.setZoom(16);
        let params = {
          id: 1,
          url: "geoJsonUrl",
        };
        // 加载geoJson
        this.view.webgis.loadGeoJSON(params, (source) => {
          let feature = source[0].getGeometry().getCoordinates();
          this.view.handlePolygon();
        });
      });
    },
  },
};
</script>

API

events

事件名事件说明类型参数描述或返回值
initTdt加载天地图Function(mapKey, callBack)mapKey:天地图 key, callBack:回调函数
getOlMapObject获取 olMapFunction()返回 Object
setZoom缩放Function(level)level:地图缩放级别 0 ~ 20 级
setCenter设置中心点Function(centerArray)centerArray:'longitude', 'latitude'
zoomIn地图放大Function()-
zoomOut地图缩小Function()-
loadGeoJSON加载 geoJsonFunction(params, callBack)params:{id, url}, callBack:回调函数
handlePolygon注册点击事件Function()-