You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用jVectormap仅展示美荷新三国并添加可点击跳转标记的技术问询

Absolutely! jVectormap has all the tools you need to pull this off—here's a step-by-step breakdown to make it happen:

1. Only Show Your Target Countries

First, you'll need to configure the map to render only the US, Netherlands, and Singapore. You can do this by hiding all regions on load, then explicitly showing your target countries using their ISO 3166-1 alpha-2 codes (US, NL, SG):

$('#world-map').vectorMap({
  map: 'world_mill',
  backgroundColor: '#ffffff',
  onLoad: function(event, map) {
    // Hide all countries initially
    map.hideRegions();
    // Show only your target countries
    map.showRegions(['US', 'NL', 'SG']);
  }
});
2. Add Clickable Markers for Offices

Next, use the markers option to place pins at your office locations, and hook up click events to handle page navigation. You can store the target URL directly in each marker's configuration:

$('#world-map').vectorMap({
  map: 'world_mill',
  backgroundColor: '#ffffff',
  // Define markers with coordinates, labels, and target URLs
  markers: [
    { latLng: [37.0902, -95.7129], name: 'US Office', url: '/us-office' },
    { latLng: [52.1326, 5.2913], name: 'Netherlands Office', url: '/nl-office' },
    { latLng: [1.3521, 103.8198], name: 'Singapore Office', url: '/sg-office' }
  ],
  // Customize marker styling (optional but recommended)
  markerStyle: {
    initial: {
      fill: '#e74c3c',
      stroke: '#ffffff',
      strokeWidth: 2,
      r: 8
    },
    hover: {
      r: 10,
      fill: '#c0392b'
    }
  },
  // Handle marker clicks to trigger page navigation
  onMarkerClick: function(event, index) {
    const targetMarker = this.markers[index];
    if (targetMarker.url) {
      window.location.href = targetMarker.url;
    }
  },
  // Keep the region visibility logic from step 1
  onLoad: function(event, map) {
    map.hideRegions();
    map.showRegions(['US', 'NL', 'SG']);
  }
});
3. Optional: Auto-Focus on Target Countries

To make sure all three countries are clearly visible without manual zooming, add the focusOn option to auto-adjust the map's view:

focusOn: {
  regions: ['US', 'NL', 'SG'],
  scale: 1.2 // Tweak this to adjust zoom level
}
Quick Notes
  • Double-check your office coordinates (use tools like Google Maps to get precise lat/long values).
  • Make sure you're using a compatible map file (like world_mill.js—most jVectormap distributions include this).
  • Adjust the markerStyle values to match your brand's design system.

内容的提问来源于stack exchange,提问作者yuri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:19:45