惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
MyScale Blog
MyScale Blog
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
有赞技术团队
有赞技术团队
雷峰网
雷峰网
罗磊的独立博客
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
博客园 - 司徒正美
Last Week in AI
Last Week in AI
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
量子位
宝玉的分享
宝玉的分享

博客园 - Coca-code

202609142132_《Unix(唯一) sample code》 202608051132_《theta & freguency measure distance _algorithmn》 202603171903_《实时OS Kernel》 202603162259_《CSS格子(1-9 js版)》 202603162216_《CSS格子(1-9)》 202503241513_《Root entrance function of 'Hello Mars' 》 202403172356_《Initial sys. of C》 202401221657_《React相关(一) 写法》 202401102331 -《Flex9格布局——从1到9》 202312142321_《遍历 for customised data structure 》 202311141210——《一些修改表字段的sql语句》 202310061823_《运行这个页面,背后是一大堆配置》 202310061227-《心得:低版本mysql配置一,些轮子插件》 202310032035_《近期撸码心得》 202310031029——《个人在Lombok使用中遇到的错误及解决》 202309301820_《Spring boot项目,继承mybatis-generator遇到的问题及解决》 202309272035-《maven依赖已下载,但还是报红,解决办法》 202309272022-《idea编辑器,maven解析依赖慢,解决办法》 202306112142-《最近开发心得...》 202306062001-《远程Linux服务器——安装tomcat8、jdk1.8、mysql5——mysql 用sql建表时提示utf8错误....》 202305281631-《远程Linux服务器——安装tomcat8、jdk1.8、mysql5——mysql workerbench连接出错》
202503271546_《Idiot js code of map app》
Coca-code · 2025-03-27 · via 博客园 - Coca-code
let mapBounds = {};
const imageWidth = 800, imageHeight = 600;
let targets = []; // Array of moving targets

function init(coordinate_lt, coordinate_rb) {
  mapBounds = {
    x1: coordinate_lt[0], y1: coordinate_lt[1],
    x2: coordinate_rb[0], y2: coordinate_rb[1]
  };

  // Initial mock targets (e.g., drones or rovers)
  targets = [
    { id: 1, x: 39.5, y: -74.5, vx: 0.0001, vy: 0.00005 }, // Velocity in coord units/frame
    { id: 2, x: 38.8, y: -73.8, vx: -0.00005, vy: 0.0001 }
  ];

  startBreathing();
}

function coordToPixels(x, y, bounds = mapBounds) {
  const dx = bounds.x2 - bounds.x1 || 1;
  const dy = bounds.y2 - bounds.y1 || 1;
  const px = imageWidth * (x - bounds.x1) / dx;
  const py = imageHeight * (bounds.y1 - y) / dy;
  return { x: Math.min(Math.max(px, 0), imageWidth), y: Math.min(Math.max(py, 0), imageHeight) };
}

function adjust(targetTriangle) {
  // Update bounds based on triangle (e.g., from fixed sensors)
  const targetBounds = {
    x1: Math.min(...targetTriangle.map(c => c[0])),
    y1: Math.min(...targetTriangle.map(c => c[1])),
    x2: Math.max(...targetTriangle.map(c => c[0])),
    y2: Math.max(...targetTriangle.map(c => c[1])),
  };
  const attractionStrength = 0.05;
  mapBounds.x1 += (targetBounds.x1 - mapBounds.x1) * attractionStrength;
  mapBounds.y1 += (targetBounds.y1 - mapBounds.y1) * attractionStrength;
  mapBounds.x2 += (targetBounds.x2 - mapBounds.x2) * attractionStrength;
  mapBounds.y2 += (targetBounds.y2 - mapBounds.y2) * attractionStrength;

  // Update moving targets
  targets.forEach(t => {
    t.x += t.vx; // Move based on velocity
    t.y += t.vy;
    // Bounce off bounds (optional, for demo)
    if (t.x < mapBounds.x1 || t.x > mapBounds.x2) t.vx *= -1;
    if (t.y < mapBounds.y1 || t.y > mapBounds.y2) t.vy *= -1;
  });

  updateUI();
}

function updateUI() {
  const container = document.querySelector('.map-container');
  container.innerHTML = '<img src="muddy-earth.png" class="map-image" alt="Map">';

  // Plot moving targets
  targets.forEach(t => {
    const pos = coordToPixels(t.x, t.y);
    const marker = document.createElement('div');
    marker.className = 'marker';
    marker.style.left = `${pos.x}px`;
    marker.style.top = `${pos.y}px`;
    marker.style.background = t.id === 1 ? 'purple' : 'orange';
    container.appendChild(marker);
  });
}

function startBreathing() {
  function breathe() {
    // Fixed triangle (e.g., RTK reference points)
    const referenceTriangle = [
      [39.0 + Math.sin(Date.now() / 1000) * 0.01, -74.0],
      [39.5, -74.5 + Math.cos(Date.now() / 1000) * 0.01],
      [38.5, -73.5]
    ];
    adjust(referenceTriangle);
    requestAnimationFrame(breathe);
  }
  breathe();
}

// Earth test
init([40.0, -75.0], [38.0, -73.0]);

//CSS code ... ...