使用Knockout JS的Google Maps多边形位置,“属性<map>的值无效”</map>

时间:2013-05-16 14:40:32

标签: google-maps-api-3 knockout.js

根本不确定这与敲门有关,但这是我的代码:

$(document).ready(function () {
    ko.applyBindings(viewModel);
});
function MyViewModel() {
    var self = this;
    self.mapOne = ko.observable({
        lat: ko.observable(38.6),
        lng: ko.observable(-90.1)
    });
    var sshColor = ko.observable('#00FF00');
}

ko.bindingHandlers.map = {
    init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
        var mapObj = ko.utils.unwrapObservable(valueAccessor());
        var latLng = new google.maps.LatLng(
            ko.utils.unwrapObservable(mapObj.lat),
            ko.utils.unwrapObservable(mapObj.lng));
        var mapOptions = {
            center: latLng,
            zoom: 6,
            maxZoom: 9,
            minZoom: 5,
            disableDefaultUI: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var SunsetHills;
        var sshCoords = [
          new google.maps.LatLng(38, -90),
          new google.maps.LatLng(36, -89),
          new google.maps.LatLng(38, -89)
        ];

        SunsetHills = new google.maps.Polygon({
            paths: sshCoords,
            strokeColor: "#00FF00",
            strokeOpacity: 0.8,
            strokeWeight: 2,
            fillColor: "#00FF00",
            fillOpacity: 0.35
        });


        mapObj.googleMap = new google.maps.Map(element, mapOptions);

        SunsetHills.setMap(mapObj);

    }
};


var viewModel = new MyViewModel();
  

Uncaught Error: Invalid value for property <map>: [object Object]

0 个答案:

没有答案