How to use the @mapbox/geojson-rewind function in @mapbox/geojson-rewind

To help you get started, we’ve selected a few @mapbox/geojson-rewind examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antvis / L7 / src / source / parser / geojson.js View on Github external
export default function geoJSON(data, cfg) {
  // 矢量瓦片图层不做 rewind

  rewind(data, true);
  const resultData = [];
  const featureKeys = {};
  data.features = data.features.filter(item => {
    return item != null && item.geometry && item.geometry.type && item.geometry.coordinates && item.geometry.coordinates.length > 0;
  });
  // 数据为空时处理
  let i = 0;
  turfMeta.flattenEach(data, (currentFeature, featureIndex) => { // 多个polygon 拆成一个
    const coord = getCoords(currentFeature);
    let id = featureIndex + 1;
    if (cfg.idField && currentFeature.properties[cfg.idField]) {
      const value = currentFeature.properties[cfg.idField];
      id = djb2hash(value) % 1000019;
      featureKeys[id] = {
        index: i++,
        idField: value
github antvis / L7 / packages / source / src / parser / geojson.ts View on Github external
export default function geoJSON(
  data: FeatureCollection,
  cfg?: IParserCFG,
): IParserData {
  rewind(data, true); // 设置地理多边形方向 If clockwise is true, the outer ring is clockwise, otherwise it is counterclockwise.
  const resultData: IParseDataItem[] = [];
  const featureKeys: IFeatureKey = {};
  data.features = data.features.filter((item: Feature) => {
    const geometry: Geometry | null = item.geometry as Geometry;
    return (
      item != null &&
      geometry &&
      geometry.type &&
      geometry.coordinates &&
      geometry.coordinates.length > 0
    );
  });
  // 数据为空时处理
  const i = 0;
  // multi polygon 拆分
  turfMeta.flattenEach(
github antvis / L7 / src / source / parser / json.js View on Github external
if (x1 && y1) { // 弧线 或者线段
      coords = [[ col[x], col[y] ], [ col[x1], col[y1] ]];
    }
    if (coordinates) {
      let type = 'Polygon';
      if (!Array.isArray(coordinates[0])) {
        type = 'Point';
      }
      if (Array.isArray(coordinates[0]) && !Array.isArray(coordinates[0][0])) {
        type = 'LineString';
      }
      const geometry = {
        type,
        coordinates: [ ...col[coordinates] ]
      };
      rewind(geometry, true);
      coords = geometry.coordinates;
    }

    col._id = featureIndex + 1;
    const dataItem = {
      ...col,
      coordinates: coords

    };
    resultdata.push(dataItem);
  });
  return {
github mapbox / mapbox-gl-js / src / source / geojson_worker_source.js View on Github external
this.loadGeoJSON(params, (err: ?Error, data: ?Object) => {
            if (err || !data) {
                return callback(err);
            } else if (typeof data !== 'object') {
                return callback(new Error(`Input data given to '${params.source}' is not a valid GeoJSON object.`));
            } else {
                rewind(data, true);

                try {
                    this._geoJSONIndex = params.cluster ?
                        new Supercluster(getSuperclusterOptions(params)).load(data.features) :
                        geojsonvt(data, params.geojsonVtOptions);
                } catch (err) {
                    return callback(err);
                }

                this.loaded = {};

                const result = {};
                if (perf) {
                    const resourceTimingData = perf.finish();
                    // it's necessary to eval the result of getEntriesByName() here via parse/stringify
                    // late evaluation in the main thread causes TypeError: illegal invocation
github antvis / L7 / packages / source / src / parser / json.ts View on Github external
[parseFloat(col[x1]), parseFloat(col[y1])],
      ];
    }
    if (coordinates) {
      let type = 'Polygon';
      if (!Array.isArray(coordinates[0])) {
        type = 'Point';
      }
      if (Array.isArray(coordinates[0]) && !Array.isArray(coordinates[0][0])) {
        type = 'LineString';
      }
      const geometry = {
        type,
        coordinates: [...col[coordinates]],
      };
      rewind(geometry, true);
      coords = geometry.coordinates;
    }
    const dataItem = {
      ...col,
      _id: featureIndex,
      coordinates: coords,
    };
    resultData.push(dataItem);
  });
  return {

@mapbox/geojson-rewind

enforce winding order for geojson

ISC
Latest version published 3 years ago

Package Health Score

74 / 100
Full package analysis

Popular @mapbox/geojson-rewind functions