小编new*_*bie的帖子

使用 React-mapbox-gl 使用 Mapbox 渲染矢量切片

我有一个 geoJSON 文件,我vector.tiles使用这个 npm 包转换成。我用const tileIndex = geojsonvt(geoJSON). geoJSON 文件具有以下格式,并且在转换时没有任何错误。

const geoJSON = {
  type: 'FeatureCollection',
  crs: {
    type: 'name',
    properties: { name: 'urn:ogc:def:crs:OGC:1.3:CRS84' }
  },
  features: [
    {
      properties: [Object],
      geometry: [Object],
      type: 'Feature',
      _id: '5ed7b221a61a4b2970433932'
    },
    ... 1840 more items
 ]
}
Run Code Online (Sandbox Code Playgroud)

转换后得到的结果(geoJSON vector-tiles)如下 -

const tiles = {
    options: {},
    tiles: {
      '0': {
        features: [Array],
        numPoints: 540529,
        numSimplified: 3,
        numFeatures: 1940,
        source: null,
        x: 0,
        y: 0,
        z: …
Run Code Online (Sandbox Code Playgroud)

mapbox reactjs mapbox-gl mapbox-gl-js vector-tiles

7
推荐指数
1
解决办法
913
查看次数

使用 mongoose/MongoDB 中间件删除引用的文档(2021 年)

我尝试了所有与使用 node.js 在 MongoDB 中删除引用文档相关的堆栈溢出解决方案。但是他们中的大多数要么有不推荐使用的方法的解决方案,其中一些根本不起作用。

我有两个模型,Parent并且Childone-to-many关系。父文档包含一组引用的子文档 ID,如下面的架构所示。

//file => parent.js 

const parentSchema = new mongoose.Schema({
  parentName: {
    type: String,
  },
  childrens : [
    {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Children'
    }
  ]
});

const Parent = mongoose.model("Parent", parentSchema);
module.exports = Parent ; 

Run Code Online (Sandbox Code Playgroud)

下一个文件具有成功触发的children带有childrenSchema.pre()中间件或钩子的模型-

//file => children.js 

const mongoose = require("mongoose");
const Parent  = require("./parent"); 


const childrenSchema = new mongoose.Schema({
  childrenId: Number,
  info: String,
  type: String, 
});


childrenSchema.pre('findOneAndDelete', async function(next) {
  console.log('trigger when …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb node.js express

6
推荐指数
1
解决办法
37
查看次数

R :根据按列更改分组中的前后值来查找最小值

添加可复制性:

  data.frame(
product=c(rep("x",2),rep("y",3)),
price_category_from=c(10,20,10,20,30),
price=c(30,31,31,30,27)
Run Code Online (Sandbox Code Playgroud)

)

如下所示,我有一个表格,我想对其进行分组product并更改price_category_from列的值以找到最小值price

product     price_category_from     price
  x                10                30
  x                20                31
  y                10                31
  y                20                30
  y                30                27
Run Code Online (Sandbox Code Playgroud)

如下所示,结果表应包含price.new用于更改列中值的最小price_category_from列。例如,price.new在产品的两行中x都是30因为类别的后续priceprice_category_from更大。而对于产品y,每个后续price_category_from类别的最小值都会发生变化,因为下一个price值较小。

中的值price_category_from是按递增顺序排列的间隔。

product     price_category_from     price    price.new
  x                10                30        30
  x                20                31        30  **
  y                10                31        31
  y                20                30        30
  y                30                27        27 …
Run Code Online (Sandbox Code Playgroud)

r reshape2 dplyr data.table

1
推荐指数
1
解决办法
66
查看次数

从 axios 访问进度条的 ProgressEvent 值以在 React 中设置状态

我有两个文件 - 其中之一是公共文件,其中包含使用 axios 进行请求的逻辑PUTprogress bar另一个文件包含根据progressEventfrom方法的值进行更新的组件onUploadProgress。我想setUploadPercentage用发出的当前值设置状态。但我很难重构我的代码以访问我的类组件中的这个值FileUpload。任何帮助,将不胜感激。

  1. 包含 axios 请求逻辑的文件:-
export function putData(formData) {
  return axios.put('/update', formData, {
    headers: {
      "Content-Type": "multipart/form-data",
    },
    onUploadProgress : (progressEvent) => {
        return parseInt(Math.round((progressEvent.loaded * 100) / progressEvent.total))
    },
  });
}
Run Code Online (Sandbox Code Playgroud)
  1. 包含组件的文件:-
import React, { useState } from "react";
import { putData } from "../../services/clientService";
import Progress from "../common/progress";

const FileUpload = () => {
  const [uploadPercentage, setUploadPercentage] = useState(0);

  const onChange = …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs axios react-state

1
推荐指数
1
解决办法
1万
查看次数