绘制船舶图标

传入标准 GeoJSON 格式数据生成船舶图标实例对象

示例

// 推荐使用 turf.js 对数据进行格式化 遍历等操作
const points = {
  type: "FeatureCollection",
  features: [
    {
      type: "Feature",
      properties: {
        iconStyle: {
          type: "base",
          deg: 45,
          fill: "red",
          fillOpacity: 0.5,
          opacity: 1,
        },
        test: "test",
      },
      geometry: {
        type: "Point",
        coordinates: [-84.23420673067342, -72.55849561953549],
      },
    },
  ],
};

const options = {
  onEachFeature(feature, layer) {
    layer.on("click", () => {
      console.log(feature);
      console.log(layer);
    });
  },
};
const layer = hnsdk.drawVessel(points, options);

layer.addTo(map);

参数

入参类型描述
geojsonfeatureCollectionGeoJSON FeatureCollection 标准格式数据
optionsoptions创建图层的可配置项

options

选项类型描述
onEachFeatureFunction一个 Function ,在每个创建的 Feature 被创建和样式化后,将被调用一次。对于将事件和弹出窗口附加到要素上很有用。默认情况下,对新创建的图层不做任何处理:
function (feature, layer) {}
filterFunction一个 Function ,用于决定是否包括一个要素。默认是包括所有要素:
function (geoJsonFeature) { return true; }

featureCollection

选项类型描述
typeString类型 必须为 FeatureCollection
featuresfeature[]特征组 每一项是每个船舶图标经纬度、及携带数据对象

feature

选项类型描述
typeString类型 必须为 Feature
propertiesproperties特征携带数据,iconStyle 必填
geometrygeometry经纬度数据

geometry

选项类型描述
typeString类型 必须为 Point
coordinates[Number , Number]经纬度数组,前经后纬

properties

选项类型描述
iconStyleiconStyle船舶图标样式
任何任何船舶图标携带数据

iconStyle

选项类型描述
degnumber船头朝向 0 - 360
fillstring填充色
fillOpacitynumber填充色透明度 0-1
typestring基础:base
航行中:run
转向:turn
停泊:mooring
浮桶:floating
opacitynumber图标透明度 0-1

方法

方法返回值描述
removethis从当前处于活动状态的地图中删除图层。
addTothis将图层添加到指定的地图或图层组

返回

GeoJSON 实例对象

Last Updated:
Contributors: zhiwen