Ошибка AngularJS: $ injector: modulerr Ошибка модуля при попытке использовать директиву OpenLayers - PullRequest
0 голосов
/ 28 апреля 2018

У меня проблемы с тем, что мой модуль не загружает мою карту, из-за ошибки: $ injector: modulerr Ошибка модуля Я почти уверен, что правильно создал свой модуль с помощью ...

var app = angular.module("MapApp", ["openlayers-directive"]);

app.controller('MapController', ['$scope', function MapController($scope){
    angular.extend($scope, {
        center:{
            lat: 40.060620,
            lon: -77.523182,
            zoom: 17
        }
    });
}]);

А затем используйте это в моем html ...

<!DOCTYPE html>
<html lang="en" ng-app="MapApp">
<head>
    <meta charset="UTF-8">
    <title>ShipList</title>

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.4.2/css/bulma.css">
    <link rel="stylesheet" href="../css/main.css">
    <script src="../js/ol.js"></script>
    <script src="../lib/angular.min.js"></script>
    <link rel="stylesheet" href="../css/ol.css"/>
    <script src="../js/Map.js"></script>

...
<!--Later in my body tag, I'm declaring my Controller-->
    <div class="overlay" ng-controller="MapController">
        <openlayers id="mapid"></openlayers>

Но я все еще получаю ошибку экземпляра модуля. Я думаю, что я неправильно загружаю директиву OpenLayers? Я также попытался загрузить те же зависимости из CDN для OpenLayers, и вот, смотрите здесь, в этом JSFiddle . Если это имеет значение, я также определил свойства высоты, ширины и масштаба моей карты в своей таблице стилей.

.angular-openlayers-map {
    height: 800px;
    width: 100%;
    float: left;
    z-index: 1;
    position: relative;
}

1 Ответ

0 голосов
/ 28 апреля 2018

Я не вижу ссылок на файл javascript открытых слоев. Пожалуйста, проверьте следующее демо.

Демо

var app = angular.module("demoapp", ["openlayers-directive"]);
app.controller("DemoController", [ '$scope', function($scope) {
  $scope.showDetails = function(id) {
    alert('lat: '+ id.lat+', '+'lon: '+id.lon);
  };
  angular.extend($scope, {
    center: {
      lat: 42.9515,
      lon: -8.6619,
      zoom: 9
    },
    finisterre: {
      lat: 42.907800500000000000,
      lon: -9.265031499999964000,
      label: {
        show: false,
      },
      onClick: function (event, properties) {
        alert('lat: '+ properties.lat+', '+'lon: '+properties.lon);
      }
    },
    santiago: {
      lat: 42.880596200000010000,
      lon: -8.544641200000001000,
      label: {
          show: true
      }
    },
    santacomba: {
      lat: 43.0357404,
      lon: -8.8213786,
      label: {
        message: "Santa Comba",
        show: false,
      },
      onClick: function (event, properties) {
        alert('lat: '+ properties.lat+', '+'lon: '+properties.lon);
      }
    }
  });
}]);
<!DOCTYPE html>
<html ng-app="demoapp">
  <head>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.7.0/ol.min.js"></script>
    <script src="https://code.angularjs.org/1.4.0/angular.min.js"></script>
    <script src="https://code.angularjs.org/1.4.0/angular-sanitize.min.js"></script>
    <script src="https://tombatossals.github.io/angular-openlayers-directive/dist/angular-openlayers-directive.js"></script>
    
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.7.0/ol.min.css" />
    <link rel="stylesheet" href="http://tombatossals.github.io/angular-openlayers-directive/dist/angular-openlayers-directive.css" />
    
    <!-- Demo Styles -->
    <link rel="stylesheet" href="style.css" />
    
  </head>
  <body ng-controller="DemoController">
    <h1>Open Layers Demo</h1>
    <p>Click on the <em>map marker</em> for <strong>Fisterra</strong> or <strong>Santa Comba</strong>to see the latitude and longitude.</p>
    <p>Click on the map marker <em>popover</em> for <strong>Santiago de Compostela</strong> to see the latitude and longitude.</p>
    <openlayers ol-center="center" height="400px" width="100%">
      <ol-marker ol-marker-properties="santiago"><p ng-click="showDetails(santiago)">Santiago de Compostela</p></ol-marker>
      <ol-marker ol-marker-properties="finisterre" class="hidden"><span></span></ol-marker>
      <ol-marker ol-marker-properties="santacomba"></ol-marker>
    </openlayers>
  </body>
</html>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...