简体   繁体   English

在AMMAP中动态设置和缩放国家/地区地图

[英]Set and zoom country map dynamically in AMMAP

I'm working with the latest javascript version of ammap and I'm trying to get the correct country to load when a page is loading. 我正在使用ammap的最新javascript版本,并且我正在尝试在加载页面时加载正确的国家/地区。 I'm aware of the fact you can load the correct country by simply load the correct country js file 我知道您可以通过加载正确的country js文件来加载正确的国家/地区

<script src="/js/ammap/maps/js/australiaLow.js"></script> 

and then set the dataprovider correctly 然后正确设置dataprovider

var dataProvider = {
mapVar: AmCharts.maps.australiaLow,
getAreasFromMap: true
};

But my goal is to start with continentsLow and to drill down to the correct country by using javascript and no interaction of the user. 但我的目标是从大陆开始,并通过使用javascript并没有用户的交互深入到正确的国家。 This because the users should be able to navigate at all levels and the maps should load accordingly. 这是因为用户应该能够在所有级别导航,并且应该相应地加载地图。

<script src="/js/ammap/maps/js/australiaLow.js"></script>

It's similar to this example page, but in this example. 它与此示例页面类似,但在此示例中。 But in this example you have to click before you will get to see the correct country. 但在此示例中,您必须先单击才能看到正确的国家/地区。 http://www.ammap.com/javascript-maps/zooming-to-countries-map/ I tried to load the map and set it and then reload the ammap but without success. http://www.ammap.com/javascript-maps/zooming-to-countries-map/我尝试加载地图并设置它,然后重新加载ammap但没有成功。

map.selectObject(map.getObjectById("AU")); 

Any idea how to do this? 知道怎么做吗?

I had the same need and what I ended up doing is using the clickMapObject method to simulate a click on the map object I wanted it to start out with: 我有同样的需求,我最终做的是使用clickMapObject方法来模拟我希望它开始的地图对象的点击:

var mapObject = map.getObjectById('US');
map.clickMapObject(mapObject);

When I load the page it will zoom right into the country I selected (US). 当我加载页面时,它将缩放到我选择的国家(美国)。

According to their tips page http://www.amcharts.com/tips/auto-zoom-country-map-loads/ the easiest solution IMO is to set linkToObject in dataProvider : 根据他们的提示页面http://www.amcharts.com/tips/auto-zoom-country-map-loads/最简单的解决方案IMO是在dataProvider设置linkToObject

"dataProvider": {
    "map": "worldLow",
    "getAreasFromMap": true,
    "linkToObject": "US"
},

map.addListener("clickMapObject", function (event) { if (event.mapObject.id == "FR") { loadNewMap("http://www.ammap.com/lib/maps/js/franceLow.js", "franceLow"); }

jsfiddle demo jsfiddle演示

I think this will help 我认为这会有所帮助

Alternative solution: 替代方案:

map.zoomToGroup([map.getObjectById('RO')]);

The map will start with the selected region zoomed in. 地图将从放大的选定区域开始。

My solution : 我的解决方案

http://kirmizikaya.net/blog/ammap-dynamically-load-map-of-the-country-on-click/ http://kirmizikaya.net/blog/ammap-dynamically-load-map-of-the-country-on-click/

..
.....
$.getScript(filename, function (data, textStatus, jqxhr) {})
 .done(function (script, textStatus)
 {
       var dataProvider = {
       mapVar: eval(mapVar),
       getAreasFromMap: true,
     };
      // ilgili ülkenin haritasını bağlayalım
      map.dataProvider = dataProvider;
      //harita yüklensin
map.validateData();
});
...
......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM