Googleマップスクリプトのラッパーオブジェクトを作成しようとしていますが、何らかの理由で機能していないようです.誰かが以下のコードを見て、私が間違っていることを教えてください.
var cmdMapObject = {
canvas : 'map-canvas',
latLng : '-25.344, 131.036',
zoom : 14,
myLocation : '',
poly : '',
map : '',
markers : [],
path : '',
addPoint : function(event) {
"use strict";
// add the latitude and longitute to array after the last item
cmdMapObject.path.insertAt(cmdMapObject.path.length, event.latLng);
// create new marker
var marker = new google.maps.Marker({
position: event.latLng,
map: cmdMapObject.map,
draggable: true
});
// add new marker to the array
cmdMapObject.markers.push(marker);
// set tooltip title to the marker
marker.setTitle("#" + cmdMapObject.path.length);
// remove marker on click
google.maps.event.addListener(marker, 'click', function() {
// remove marker from the map
marker.setMap(null);
// remove location from array and path
for (var i = 0, ml = cmdMapObject.markers.length; i < ml && cmdMapObject.markers[i] != marker; ++i) {
cmdMapObject.markers.splice(i, 1);
cmdMapObject.path.removeAt(i);
}
}
);
// add listener to draggend event to change the position of the marker
// when dragging has ended
google.maps.event.addListener(marker, 'dragend', function() {
for (var i = 0, ml = cmdMapObject.markers.length; i < ml && cmdMapObject.markers[i] != marker; ++i) {
var thisNewPosition = marker.getPosition();
cmdMapObject.markers[i]['position'] = thisNewPosition;
cmdMapObject.path.setAt(i, thisNewPosition);
}
});
},
initialize : function() {
"use strict";
cmdMapObject.path = new google.maps.MVCArray;
cmdMapObject.myLocation = new google.maps.LatLng(cmdMapObject.latLng);
cmdMapObject.map = new google.maps.Map(document.getElementById(cmdMapObject.canvas), {
zoom: cmdMapObject.zoom,
center: cmdMapObject.myLocation,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
cmdMapObject.poly = new google.maps.Polygon({
strokeWeight: 3,
fillColor: '#5555FF'
});
cmdMapObject.poly.setMap(cmdMapObject.map);
cmdMapObject.poly.setPaths(new google.maps.MVCArray(cmdMapObject.path));
google.maps.event.addListener(cmdMapObject.map, 'click', cmdMapObject.addPoint);
},
mapInit : function() {
"use strict";
google.maps.event.addDomListener(window, 'load', cmdMapObject.initialize);
}
};
cmdMapObject.mapInit();
私が得たのは、左側にズームスライダー、地図/衛星ボタン、下部に著作権表示がありますが、地図はありません.