【问题标题】:amCharts center mapamCharts 中心地图
【发布时间】:2023-04-03 03:01:01
【问题描述】:

我正在使用 amCharts 的世界地图,当我降低高度时,地图会自动缩放到北美。有没有办法将地图的中心设置为欧洲而不是北美?我想在鼠标悬停时删除国家名称。

<html>
	<head>
		<title>map created with amCharts | amCharts</title>
		<meta name="description" content="map created using amCharts pixel map generator" />

		<!--
			This map was created using Pixel Map Generator by amCharts and is licensed under the Creative Commons Attribution 4.0 International License.
			You may use this map the way you see fit as long as proper attribution to the name of amCharts is given in the form of link to https://pixelmap.amcharts.com/
			To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/

			If you would like to use this map without any attribution, you can acquire a commercial license for the JavaScript Maps - a tool that was used to produce this map.
			To do so, visit amCharts Online Store: https://www.amcharts.com/online-store/
		-->

		<!-- amCharts javascript sources -->
		<script type="text/javascript" src="https://www.amcharts.com/lib/3/ammap.js"></script>
		<script type="text/javascript" src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>

		<!-- amCharts javascript code -->
		<script type="text/javascript">
		var targetSVG = "M9,0C4.029,0,0,4.029,0,9s4.029,9,9,9s9-4.029,9-9S13.971,0,9,0z M9,15.93 c-3.83,0-6.93-3.1-6.93-6.93S5.17,2.07,9,2.07s6.93,3.1,6.93,6.93S12.83,15.93,9,15.93 M12.5,9c0,1.933-1.567,3.5-3.5,3.5S5.5,10.933,5.5,9S7.067,5.5,9,5.5 S12.5,7.067,12.5,9z";
			AmCharts.makeChart("map",{
					"type": "map",
					"pathToImages": "http://www.amcharts.com/lib/3/images/",
					"addClassNames": true,
					"fontSize": 15,
					"color": "#FFFFFF",
					"projection": "mercator",
					"backgroundAlpha": 1,
					"backgroundColor": "rgba(80,80,80,1)",
					"dataProvider": {
						"map": "worldLow",
						"getAreasFromMap": true,
						"images": [
							{
								"top": 40,
								"left": 60,
								"width": 80,
								"height": 40,
								"pixelMapperLogo": true,
								"imageURL": "http://pixelmap.amcharts.com/static/img/logo.svg",
								"url": "http://www.amcharts.com"
							},
							{
								"selectable": true,
								"title": "Brussels",
								"longitude": 4.2100,
								"latitude": 50.5100,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1,
								"url": "https://blockchainhub.net/brussels/"
							},
							{
								"selectable": true,
								"title": "Berlin",
								"longitude": 13.2300,
								"latitude": 52.3100,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1,
								"url": "https://blockchainhub.net/berlin/"
							},
							{
								"selectable": true,
								"title": "Graz",
								"longitude": 15.2600,
								"latitude": 47.4000,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1,
								"url": "https://blockchainhub.net/graz/"
							},
							{
								"selectable": true,
								"title": "Sofia (coming soon)",
								"longitude": 23.33,
								"latitude": 42.7000,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1
							},
							{
								"selectable": true,
								"title": "Shanghai (coming soon)",
								"longitude": 121.47472,
								"latitude": 31.2286,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1
							},
							{
								"selectable": true,
								"title": "Salt Lake City (coming soon)",
								"longitude": -111.5300,
								"latitude": 40.4500,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1
							},
							{
								"selectable": true,
								"title": "Helsinki (coming soon)",
								"longitude": 24.5615,
								"latitude": 60.1015,
								"svgPath": targetSVG,
								"color": "#ff1d51",
								"scale": 1
							}
						]
					},
					"balloon": {
						"horizontalPadding": 15,
						"borderAlpha": 0,
						"borderThickness": 1,
						"verticalPadding": 15
					},
					"areasSettings": {
						"color": "rgba(129,129,129,1)",
						"outlineColor": "rgba(80,80,80,1)",
						"rollOverOutlineColor": "rgba(80,80,80,1)",
						"rollOverBrightness": 20,
						"selectedBrightness": 20,
						"selectable": true,
						"unlistedAreasAlpha": 0,
						"unlistedAreasOutlineAlpha": 0
					},
					"imagesSettings": {
						"alpha": 1,
						"color": "rgba(129,129,129,1)",
						"outlineAlpha": 0,
						"rollOverOutlineAlpha": 0,
						"outlineColor": "rgba(80,80,80,1)",
						"rollOverBrightness": 20,
						"selectedBrightness": 20,
						"selectable": true
					},
					"linesSettings": {
						"color": "rgba(129,129,129,1)",
						"selectable": true,
						"rollOverBrightness": 20,
						"selectedBrightness": 20
					},
					"zoomControl": {
						"zoomControlEnabled": true,
						"homeButtonEnabled": false,
						"panControlEnabled": false,
						"right": 38,
						"bottom": 30,
						"minZoomLevel": 2.25,
						"gridHeight": 100,
						"gridAlpha": 0.1,
						"gridBackgroundAlpha": 0,
						"gridColor": "#FFFFFF",
						"draggerAlpha": 1,
						"buttonCornerRadius": 2
					}
				});
		</script>
	</head>
	<body style="margin: 0;background-color: rgba(80,80,80,1);">
		<div id="map" style="width: 100%; height: 400px;"></div>
	</body>
</html>
amCharts API here

【问题讨论】:

标签: amcharts


【解决方案1】:

默认情况下,要将地图居中到地图的所需部分,您需要在 dataProvider 中设置 zoomLatitudezoomLongitudezoomLevel 属性的组合,以便在加载时缩放到所需的部分.世界地图经过墨卡托校准,因此您可以使用真实坐标来设置它们。对于您的情况,我选择了 2.5 的 zoomLevel,并将 zoomLatitudezoomLongitude 设置在波兰的一个区域上,使其在我的演示中居中,但可以根据您的使用情况进一步调整它。

至于禁用国家翻转气球,您可以将getAreasFromMap设置为false(或删除dataProvider中的行),它将禁用国家的翻转,因为它们不会自动定义。如果您希望在areas 数组中添加它们,您可以通过将它们添加到您的dataProvider 来选择性地启用它们。您必须将 unlistedAreasAlphaunlistedAreasOutlineAlpha 设置回 1,并将 unlistedAreasColorunlistedAreasOutlineColor 设置为您当前的灰色,因为这些国家/地区不再列出。

用代码总结一下:

AmCharts.makeChart("map", {
  // ... 
  "dataProvider": {
    "map": "worldLow",
    // modify the default zoom
    "zoomLevel": 2.5,
    "zoomLongitude": 18.764648,
    "zoomLatitude": 51.493241,
     // ... 
  },
  // ....
  "areasSettings": {
    // ...
    // add color to unlisted areas since getAreasFromMap was removed from the dataProvider
    "unlistedAreasColor": "rgba(129,129,129,1)",
    "unlistedAreasOutlineColor": "rgba(80,80,80,1)",
    // ...
  },
  // ...
});

下面的演示:

<html>

<head>
  <title>map created with amCharts | amCharts</title>
  <meta name="description" content="map created using amCharts pixel map generator" />

  <!--
			This map was created using Pixel Map Generator by amCharts and is licensed under the Creative Commons Attribution 4.0 International License.
			You may use this map the way you see fit as long as proper attribution to the name of amCharts is given in the form of link to https://pixelmap.amcharts.com/
			To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/

			If you would like to use this map without any attribution, you can acquire a commercial license for the JavaScript Maps - a tool that was used to produce this map.
			To do so, visit amCharts Online Store: https://www.amcharts.com/online-store/
		-->

  <!-- amCharts javascript sources -->
  <script type="text/javascript" src="https://www.amcharts.com/lib/3/ammap.js"></script>
  <script type="text/javascript" src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>

  <!-- amCharts javascript code -->
  <script type="text/javascript">
    var targetSVG = "M9,0C4.029,0,0,4.029,0,9s4.029,9,9,9s9-4.029,9-9S13.971,0,9,0z M9,15.93 c-3.83,0-6.93-3.1-6.93-6.93S5.17,2.07,9,2.07s6.93,3.1,6.93,6.93S12.83,15.93,9,15.93 M12.5,9c0,1.933-1.567,3.5-3.5,3.5S5.5,10.933,5.5,9S7.067,5.5,9,5.5 S12.5,7.067,12.5,9z";
    AmCharts.makeChart("map", {
      "type": "map",
      "pathToImages": "http://www.amcharts.com/lib/3/images/",
      "addClassNames": true,
      "fontSize": 15,
      "color": "#FFFFFF",
      "projection": "mercator",
      "backgroundAlpha": 1,
      "backgroundColor": "rgba(80,80,80,1)",
      "dataProvider": {
        "map": "worldLow",
        "zoomLevel": 2.5,
        "zoomLongitude": 18.764648,
        "zoomLatitude": 51.493241,
        "images": [{
          "top": 40,
          "left": 60,
          "width": 80,
          "height": 40,
          "pixelMapperLogo": true,
          "imageURL": "http://pixelmap.amcharts.com/static/img/logo.svg",
          "url": "http://www.amcharts.com"
        }, {
          "selectable": true,
          "title": "Brussels",
          "longitude": 4.2100,
          "latitude": 50.5100,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1,
          "url": "https://blockchainhub.net/brussels/"
        }, {
          "selectable": true,
          "title": "Berlin",
          "longitude": 13.2300,
          "latitude": 52.3100,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1,
          "url": "https://blockchainhub.net/berlin/"
        }, {
          "selectable": true,
          "title": "Graz",
          "longitude": 15.2600,
          "latitude": 47.4000,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1,
          "url": "https://blockchainhub.net/graz/"
        }, {
          "selectable": true,
          "title": "Sofia (coming soon)",
          "longitude": 23.33,
          "latitude": 42.7000,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1
        }, {
          "selectable": true,
          "title": "Shanghai (coming soon)",
          "longitude": 121.47472,
          "latitude": 31.2286,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1
        }, {
          "selectable": true,
          "title": "Salt Lake City (coming soon)",
          "longitude": -111.5300,
          "latitude": 40.4500,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1
        }, {
          "selectable": true,
          "title": "Helsinki (coming soon)",
          "longitude": 24.5615,
          "latitude": 60.1015,
          "svgPath": targetSVG,
          "color": "#ff1d51",
          "scale": 1
        }]
      },
      "balloon": {
        "horizontalPadding": 15,
        "borderAlpha": 0,
        "borderThickness": 1,
        "verticalPadding": 15
      },
      "areasSettings": {
        "color": "rgba(129,129,129,1)",
        "outlineColor": "rgba(80,80,80,1)",
        "unlistedAreasColor": "rgba(129,129,129,1)",
        "unlistedAreasOutlineColor": "rgba(80,80,80,1)",
        "rollOverOutlineColor": "rgba(80,80,80,1)",
        "rollOverBrightness": 20,
        "selectedBrightness": 20
      },
      "imagesSettings": {
        "alpha": 1,
        "color": "rgba(129,129,129,1)",
        "outlineAlpha": 0,
        "rollOverOutlineAlpha": 0,
        "outlineColor": "rgba(80,80,80,1)",
        "rollOverBrightness": 20,
        "selectedBrightness": 20,
        "selectable": true
      },
      "linesSettings": {
        "color": "rgba(129,129,129,1)",
        "selectable": true,
        "rollOverBrightness": 20,
        "selectedBrightness": 20
      },
      "zoomControl": {
        "zoomControlEnabled": true,
        "homeButtonEnabled": false,
        "panControlEnabled": false,
        "right": 38,
        "bottom": 30,
        "minZoomLevel": 2.25,
        "gridHeight": 100,
        "gridAlpha": 0.1,
        "gridBackgroundAlpha": 0,
        "gridColor": "#FFFFFF",
        "draggerAlpha": 1,
        "buttonCornerRadius": 2
      }
    });
  </script>
</head>

<body style="margin: 0;background-color: rgba(80,80,80,1);">
  <div id="map" style="width: 100%; height: 400px;"></div>
</body>

</html>

【讨论】:

    【解决方案2】:

    <html>
    	<head>
    		<title>map created with amCharts | amCharts</title>
    		<meta name="description" content="map created using amCharts pixel map generator" />
    
    		<!--
    			This map was created using Pixel Map Generator by amCharts and is licensed under the Creative Commons Attribution 4.0 International License.
    			You may use this map the way you see fit as long as proper attribution to the name of amCharts is given in the form of link to https://pixelmap.amcharts.com/
    			To view a copy of this license, visit http://creativecommons.org/licenses/by/4.0/
    
    			If you would like to use this map without any attribution, you can acquire a commercial license for the JavaScript Maps - a tool that was used to produce this map.
    			To do so, visit amCharts Online Store: https://www.amcharts.com/online-store/
    		-->
    
    		<!-- amCharts javascript sources -->
    		<script type="text/javascript" src="https://www.amcharts.com/lib/3/ammap.js"></script>
    		<script type="text/javascript" src="https://www.amcharts.com/lib/3/maps/js/worldLow.js"></script>
    
    		<!-- amCharts javascript code -->
    		<script type="text/javascript">
    		var targetSVG = "M9,0C4.029,0,0,4.029,0,9s4.029,9,9,9s9-4.029,9-9S13.971,0,9,0z M9,15.93 c-3.83,0-6.93-3.1-6.93-6.93S5.17,2.07,9,2.07s6.93,3.1,6.93,6.93S12.83,15.93,9,15.93 M12.5,9c0,1.933-1.567,3.5-3.5,3.5S5.5,10.933,5.5,9S7.067,5.5,9,5.5 S12.5,7.067,12.5,9z";
    	map=		AmCharts.makeChart("map",{
    					"type": "map",
    					"pathToImages": "http://www.amcharts.com/lib/3/images/",
    					"addClassNames": true,
    					"fontSize": 15,
    					"color": "#FFFFFF",
    					"projection": "mercator",
    					"backgroundAlpha": 1,
    					"backgroundColor": "rgba(80,80,80,1)",
    					"dataProvider": {
                          
    						"map": "worldLow",
    						"getAreasFromMap": true,
    						"images": [
    							{
    								"top": 40,
    								"left": 60,
    								"width": 80,
    								"height": 40,
    								"pixelMapperLogo": true,
    								"imageURL": "http://pixelmap.amcharts.com/static/img/logo.svg",
    								"url": "http://www.amcharts.com"
    							},
    							{
    								"selectable": true,
    								"title": "Brussels",
    								"longitude": 4.2100,
    								"latitude": 50.5100,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1,
    								"url": "https://blockchainhub.net/brussels/"
    							},
    							{
    								"selectable": true,
    								"title": "Berlin",
    								"longitude": 13.2300,
    								"latitude": 52.3100,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1,
    								"url": "https://blockchainhub.net/berlin/"
    							},
    							{
    								"selectable": true,
    								"title": "Graz",
    								"longitude": 15.2600,
    								"latitude": 47.4000,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1,
    								"url": "https://blockchainhub.net/graz/"
    							},
    							{
    								"selectable": true,
    								"title": "Sofia (coming soon)",
    								"longitude": 23.33,
    								"latitude": 42.7000,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1
    							},
    							{
    								"selectable": true,
    								"title": "Shanghai (coming soon)",
    								"longitude": 121.47472,
    								"latitude": 31.2286,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1
    							},
    							{
    								"selectable": true,
    								"title": "Salt Lake City (coming soon)",
    								"longitude": -111.5300,
    								"latitude": 40.4500,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1
    							},
    							{
    								"selectable": true,
    								"title": "Helsinki (coming soon)",
    								"longitude": 24.5615,
    								"latitude": 60.1015,
    								"svgPath": targetSVG,
    								"color": "#ff1d51",
    								"scale": 1
    							}
    						]
                          
    					},
              
    					"balloon": {
    						"horizontalPadding": 15,
    						"borderAlpha": 0,
    						"borderThickness": 1,
    						"verticalPadding": 15
    					},
    					"areasSettings": {
    						"color": "rgba(129,129,129,1)",
    						"outlineColor": "rgba(80,80,80,1)",
    						"rollOverOutlineColor": "rgba(80,80,80,1)",
    						"rollOverBrightness": 20,
    						"selectedBrightness": 20,
    						"selectable": true,
    						"unlistedAreasAlpha": 0,
    						"unlistedAreasOutlineAlpha": 0
    					},
    					"imagesSettings": {
    						"alpha": 1,
    						"color": "rgba(129,129,129,1)",
    						"outlineAlpha": 0,
    						"rollOverOutlineAlpha": 0,
    						"outlineColor": "rgba(80,80,80,1)",
    						"rollOverBrightness": 20,
    						"selectedBrightness": 20,
    						"selectable": true
    					},
    					"linesSettings": {
    						"color": "rgba(129,129,129,1)",
    						"selectable": true,
    						"rollOverBrightness": 20,
    						"selectedBrightness": 20
    					},
                  "showDescriptionOnHover":"false",
    					"zoomControl": {
    						"zoomControlEnabled": true,
    						"homeButtonEnabled": false,
    						"panControlEnabled": false,
    						"right": 38,
    						"bottom": 30,
    						"minZoomLevel": 2.25,
    						"gridHeight": 100,
    						"gridAlpha": 0.1,
    						"gridBackgroundAlpha": 0,
    						"gridColor": "#FFFFFF",
    						"draggerAlpha": 1,
    						"buttonCornerRadius": 2
    					}
    				});
        map.dataProvider.zoomLatitude = "54.5260";
             
          
    		</script>
    	</head>
    	<body style="margin: 0;background-color: rgba(80,80,80,1);">
    		<div id="map" style="width: 100%; height: 400px;"></div>
    	</body>
    </html>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多