The Demo preview

On the command line, run the following command

npm install
bower installCopy the code

View demo.html in your browser

use

For details about how to use demo, see demo.html demo.js demo. CSS

The basic configuration

Js on Baidu map configuration, through an object mapOpts

angular.module('app'['ls.bmap']).controller('DemoCtrl'['$scope'.function ($scope) {
        $scope.mapOpts = {
            apiKey: 'Replace it with your key',
            center: {longitude: 121.595871,latitude: 31.187017},
            zoom: 17,
            enableScrollWheelZoom: true,
            enableMapClick: false.onMapLoadFild: function () {
                //Baidu map loading failed}}; }]);Copy the code

Description:

  • MapOpts Baidu map configuration object. The name is the same as map-options=”mapOpts” in HTML
  • ApiKey Baidu Map console application key, Baidu map key application
  • Center Initializes the center point of the map
  • Zoom Initializes the map zoom level
  • EnableScrollWheelZoom Whether to allow mouse control of map zooming
  • EnableScrollWheelZoom Whether to allow map click events by default (true means basic annotations can be clicked)
  • OnMapLoadFild Callback to local map loading failure

In the HTML template, the configuration is as follows

<div id="map" style="height:500px;"
     ui-baidu-map="myMap"
     map-event="{'map-click': 'onMapClick($event, $params)', 'map-loaded': 'onMapLoaded($event, $params)'}"
     map-options="mapOpts">
</div>Copy the code

Description:

  • MyMap is a reference to Baidu Map in Controller, which is the object map. Map. We can operate it using the methods provided by Baidu Map. MyMap can be changed to any value, as long as it has the same name as the controller above
  • Map-event command is used to describe various events of Baidu map (map click, map load completed, etc., you can go to the official map reference, the configuration is the same, add ‘map-‘ before the event, the parameter is ($event,$params),$event contains the information of map event, $params is the parameter list (array) for this event
  • Map-options is the object name of baidu map that we configure, which can be changed to any value, consistent with controller