2012-08-15 69 views
0

我從MapBox加載了我的漂亮地圖,但現在我需要從Wax/ModestMaps中獲取點擊事件。以下代碼僅觸發頁面加載時的回調:如何在ModestMaps/Wax中獲取位置點擊事件

var mapbg, interaction; 
var urlBase = 'http://a.tiles.mapbox.com/v3/mteran.house'; 

// Build baselayer background 
wax.tilejson(urlBase + '.jsonp', function(tilejson) { 
    map = new MM.Map('mymap-bg', 
    new wax.mm.connector(tilejson)); 

    map.setCenterZoom(new MM.Location(
    tilejson.center[1], // latitude 
    tilejson.center[0]), // longitude 
    tilejson.center[2]); // zoom level 

    map.addCallback("drawn", function (map) { 
    mapbg.setCenterZoom(map.getCenter(), map.getZoom()); 
    }); 

    wax.mm.zoomer(map, tilejson).appendTo(map.parent); 

    map.setZoomRange(tilejson.minzoom, tilejson.maxzoom); 

    wax.mm.interaction() 
    .map(map) 
    .tilejson(tilejson); 

    var house = new MM.Location(map.getCenter()); 

    house.on('click', alert(map.getCenter())); 

}); 

回答

1

您試圖獲得什麼樣的點擊事件? The map you're using沒有TileMill interaction啓用,所以我假設這不是目標。如果您嘗試在地圖上的任何地方獲取點擊事件,並確定它是否位於「房屋區域」here's your code expanded to make that happen

「足夠接近」將是必要的,因爲積分是地圖上的積分;緯度/經度位置無限小,點擊它們非常困難。

+0

我確實想要點擊房子。你的代碼正是我所需要的。非常感謝! – 2012-08-15 13:34:16

相關問題