javascript - Shape object is undefined for ng-map -
i'm trying simple app , running uses ngmap overlay custom polygons on map of united states. have been following example ngmap simple polygon. largest difference have compared example transitioning pulling data local json file. here controller code , html code.
(function () { var app = angular.module("testapp", ['ngmap']); app.controller("mapcontroller", mapcontroller); mapcontroller.$inject = ['$scope', '$timeout', '$http', '$window', 'ngmap']; function mapcontroller($scope, $timeout, $http, $window, ngmap) { $scope.eastern = getregioninfo("eastern"); $scope.florida = []; $scope.gateway = []; $scope.metronortheast = []; $scope.midamerica = []; $scope.midwest = []; $scope.newenglad = []; $scope.northern = []; $scope.southern = []; $scope.southwest = []; $scope.western = []; var easternregion = new google.maps.polygon({ }); function getregioninfo(region) { $http.get("data/regions.txt").success(function (data) { $scope[region] = data[region]; }) }; }; })(); <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta name="description" content="simple map"> <meta name="keywords" content="ng-map,angularjs,center"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <script src="./libraries/angularjs/angular.js"> </script><script src="http://maps.google.com/maps/api/js?key=aizasyci1dh2ssmkoewzvowtdofqa2gtkmk_ybm&libraries=placeses,visualization,drawing,geometry,places"></script> <script src="./views/mapcontroller.js"></script> <script src="./libraries/bootstrap/js/ui-bootstrap-tpls-2.0.0.js"></script> <script src="./libraries/ng-map.js"></script> <link href="./libraries/bootstrap/css/bootstrap.css" rel="stylesheet"> <title>test</title> </head> <body ng-app="testapp"> <div ng-controller="mapcontroller app"> <ng-map center="[40.74, -74.18]" map-type-id="terrain"> <shape name="easternregion" paths="[ [25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737], [25.774252, -80.190262] ]" stroke-color="#ff0000" stroke-opacity="0.8" stroke-weight="2" fill-color="#ff0000" fill-opacity="0.35"> </shape> </ng-map> </div> </body> </html> sadly when run current code receive error in console.
typeerror: cannot read property 'id' of undefined @ __mapcontroller.vm.addobject (http://localhost:64080/libraries/ng-map.js:67:30) @ linkfunc (http://localhost:64080/libraries/ng-map.js:2084:21) @ invokelinkfn (http://localhost:64080/libraries/angularjs/angular.js:9694:9) @ nodelinkfn (http://localhost:64080/libraries/angularjs/angular.js:9093:11) @ compositelinkfn (http://localhost:64080/libraries/angularjs/angular.js:8397:13) @ nodelinkfn (http://localhost:64080/libraries/angularjs/angular.js:9088:24) @ compositelinkfn (http://localhost:64080/libraries/angularjs/angular.js:8397:13) @ nodelinkfn (http://localhost:64080/libraries/angularjs/angular.js:9088:24) @ compositelinkfn (http://localhost:64080/libraries/angularjs/angular.js:8397:13) @ compositelinkfn (http://localhost:64080/libraries/angularjs/angular.js:8400:13)
this function call undefined object causing errors.
/** * add object collection of group * @memberof __mapcontroller * @function addobject * @param groupname name of collection object belongs * @param obj object add collection, i.e. marker, shape */ vm.addobject = function(groupname, obj) { if (vm.map) { vm.map[groupname] = vm.map[groupname] || {}; var len = object.keys(vm.map[groupname]).length; vm.map[groupname][obj.id || len] = obj; if (vm.map instanceof google.maps.map) { //infowindow.setmap works infowindow.open if (groupname != "infowindows" && obj.setmap) { obj.setmap && obj.setmap(vm.map); } if (obj.centered && obj.position) { vm.map.setcenter(obj.position); } (groupname == 'markers') && vm.objectchanged('markers'); (groupname == 'custommarkers') && vm.objectchanged('custommarkers'); } } }; it seems content in shape tag isn't being parsed? i'm not sure here. insight on issue? thanks!
the error occurs due following declaration:
<shape name="easternregion" ^^^^^^^^^^^^^ unknown shape type the point name attribute of shape directive reserved following values (share types):
circlepolygonpolylinerectanglegroundoverlay(or image)
in case shape not getting initialized.
modified example
<script src="https://maps.googleapis.com/maps/api/js"></script> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.2/angular.js"></script> <script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script> <div ng-app="ngmap"> <ng-map center="[25.774252, -80.190262]" zoom="4" map-type-id="terrain"> <shape name="polygon" paths="[ [25.774252, -80.190262], [18.466465, -66.118292], [32.321384, -64.75737], [25.774252, -80.190262] ]" stroke-color="#ff0000" stroke-opacity="0.8" stroke-weight="2" fill-color="#ff0000" fill-opacity="0.35"> </shape> </ng-map> </div>
Comments
Post a Comment