Skip to content

Commit

Permalink
Finish: add polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
leftstick committed Apr 2, 2018
1 parent 761aa93 commit 421fb62
Show file tree
Hide file tree
Showing 7 changed files with 235 additions and 7 deletions.
2 changes: 2 additions & 0 deletions demo/js/features/apidoc/components/subs/apiContent/index.co
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
<doc-marker ng-if="$ctrl.api === 'marker'"></doc-marker>
<doc-polyline ng-if="$ctrl.api === 'polyline'"></doc-polyline>
<doc-circle ng-if="$ctrl.api === 'circle'"></doc-circle>
<doc-polygon ng-if="$ctrl.api === 'polygon'"></doc-polygon>
<doc-control ng-if="$ctrl.api === 'control'"></doc-control>
<doc-overlay ng-if="$ctrl.api === 'overlay'"></doc-overlay>

Expand All @@ -35,6 +36,7 @@ export default {
'marker',
'polyline',
'circle',
'polygon',
'control',
'overlay',
'map-options',
Expand Down
140 changes: 140 additions & 0 deletions demo/js/features/apidoc/components/subs/apiContent/subs/docPolygon.co
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
export default {
template: `
<p>
The <code>polygon</code> component is sub-component of <code>baidu-map</code>. It is used to add <code>BMap.Polygon</code> to the map.
</p>
<h2 class="title">Usage</h2>
<div class="snippet" highlight>
<pre><code class="html">&lt;baidu-map map-options="{expression}"&gt;
&lt;polygon points="{expression}" options="{expression}" loaded="{expression}"&gt;&lt;polygon&gt;
&lt;/baidu-map&gt;</code></pre>
</div>
<h2 class="title">Attributes</h2>
<blockquote>Required properties are in red</blockquote>
<table class="matrix">
<thead>
<tr>
<th style="width: 80px;">Param</th>
<th>Type</th>
<th>Details</th>
</tr>
</thead>
<tbody>
<tr>
<td>points</td>
<td><span class="label required">expression</span></td>
<td>How polygon draws. Should be Array of point, See <a href="#!/apidoc?api=point">point</a></td>
</tr>
<tr>
<td>options</td>
<td><span class="label">expression</span></td>
<td>
Literal for constructing polygon. See <a href="http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a3b15">PolygonOptions</a>
</td>
</tr>
<tr>
<td>loaded</td>
<td><span class="label">expression</span></td>
<td>Expression to evaluate upon polygon loaded event. (The object passed to this callback, <code>polygon</code> for instance of <a href="http://lbsyun.baidu.com/cms/jsapi/reference/jsapi_reference.html#a3b14" target="_blank">BMap.Polygon</a>)</td>
</tr>
</tbody>
</table>
<h2 class="title">Example</h2>
<baidu-map map-options="$ctrl.opts">
<polygon points="$ctrl.points" options="$ctrl.polygonOpts" loaded="$ctrl.polygonLoaded(polygon)"></polygon>
</baidu-map>
<div class="snippet" highlight>
<pre><code class="html">&lt;baidu-map map-options="opts"&gt;
&lt;polygon point="points" options="polygonOpts" loaded="polygonLoaded(polygon)"&gt;&lt;/polygon&gt;
&lt;/baidu-map&gt;</code></pre>
</div>
<br/>
<div class="snippet" highlight>
<pre><code class="javascript">app.controller('demoCtrl', ['$scope',
function($scope) {
$scope.opts = {
centerAndZoom: {
longitude: 116.404,
latitude: 39.915,
zoom: 14
}
};

$scope.points = [
{
longitude: 116.387112,
latitude: 39.920977
}, {
longitude: 116.385243,
latitude: 39.913063
}, {
longitude: 116.394226,
latitude: 39.917988
}, {
longitude: 116.401772,
latitude: 39.921364
}, {
longitude: 116.41248,
latitude: 39.927893
}
];

//below are for polygon
$scope.polygonOpts = {
strokeColor: 'blue',
strokeWeight: 2
};

$scope.polygonLoaded = function(polygon) {
console.log('polygon loaded', polygon)
};
}
]);</code></pre>
</div>
`,
controller: class {
/* @ngInject */
constructor() {
this.opts = {
centerAndZoom: {
longitude: 116.404,
latitude: 39.915,
zoom: 14
}
}

this.points = [
{
longitude: 116.387112,
latitude: 39.920977
},
{
longitude: 116.385243,
latitude: 39.913063
},
{
longitude: 116.394226,
latitude: 39.917988
},
{
longitude: 116.401772,
latitude: 39.921364
},
{
longitude: 116.41248,
latitude: 39.927893
}
]

// below are for polygon
this.polygonOpts = {
strokeColor: 'blue',
strokeWeight: 2
}

this.polygonLoaded = function(polygon) {
console.log('polygon loaded', polygon)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default {
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'marker'}"><a href="#!/apidoc?api=marker">marker</a></div>
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'polyline'}"><a href="#!/apidoc?api=polyline">polyline</a></div>
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'circle'}"><a href="#!/apidoc?api=circle">circle</a></div>
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'polygon'}"><a href="#!/apidoc?api=polygon">polygon</a></div>
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'control'}"><a href="#!/apidoc?api=control">control</a></div>
<div class="api-nav-item" ng-class="{active: $ctrl.api === 'overlay'}"><a href="#!/apidoc?api=overlay">overlay</a></div>
<div class="api-nav-header">Models</div>
Expand Down
2 changes: 2 additions & 0 deletions demo/js/features/apidoc/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import docCenterAndZoom from './components/subs/apiContent/subs/docCenterAndZoom
import docMarker from './components/subs/apiContent/subs/docMarker'
import docPolyline from './components/subs/apiContent/subs/docPolyline'
import docCircle from './components/subs/apiContent/subs/docCircle'
import docPolygon from './components/subs/apiContent/subs/docPolygon'
import docPoint from './components/subs/apiContent/subs/docPoint'
import docMarkerOptions from './components/subs/apiContent/subs/docMarkerOptions'
import docSize from './components/subs/apiContent/subs/docSize'
Expand All @@ -29,6 +30,7 @@ export default {
docMarker,
docPolyline,
docCircle,
docPolygon,
docPoint,
docMarkerOptions,
docSize,
Expand Down
14 changes: 7 additions & 7 deletions demo/js/features/apidoc/routes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default [
{
id: 'apidoc',
isDefault: false,
when: '/apidoc',
template: '<apidoc></apidoc>'
}
];
{
id: 'apidoc',
isDefault: false,
when: '/apidoc',
template: '<apidoc></apidoc>'
}
]
81 changes: 81 additions & 0 deletions src/components/polygon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { nullCheck, isUndefined } from '../helper/validate'
import { transformPoints } from '../helper/transformer'

export default {
bindings: {
points: '<',
options: '<',
loaded: '&'
},
require: {
mapCtrl: '^baiduMap'
},
template: '',
controller: class {
/* @ngInject */
constructor($scope, $attrs) {
this.$scope = $scope
this.$attrs = $attrs
}

$onInit() {
nullCheck(this.points, 'points is required for <polygon>')

this.mapCtrl.mapReady
.then(() => {
const points = transformPoints(this.points, '<polygon> points')
const opts = this.options
const polygon = (this.polygon = new BMap.Polygon(points, opts))
this.mapCtrl.addOverlay(polygon)
return polygon
})
.then(polygon => {
this.loaded({
polygon
})
this.$scope.$apply()
})
}

$onChanges(changes) {
if (!this.polygon) {
return
}
if (changes.points && changes.points.currentValue) {
this.polygon.setPath(transformPoints(changes.points.currentValue, '<polygon> points'))
}
if (!changes.options || !changes.options.currentValue) {
return
}
if (!isUndefined(changes.options.currentValue.strokeColor)) {
this.polygon.setStrokeColor(changes.options.currentValue.strokeColor)
}
if (!isUndefined(changes.options.currentValue.fillColor)) {
this.polygon.setFillColor(changes.options.currentValue.fillColor)
}
if (!isUndefined(changes.options.currentValue.strokeWeight)) {
this.polygon.setStrokeWeight(changes.options.currentValue.strokeWeight)
}
if (!isUndefined(changes.options.currentValue.strokeOpacity)) {
this.polygon.setStrokeOpacity(changes.options.currentValue.strokeOpacity)
}
if (!isUndefined(changes.options.currentValue.fillOpacity)) {
this.polygon.setFillOpacity(changes.options.currentValue.fillOpacity)
}
if (!isUndefined(changes.options.currentValue.strokeStyle)) {
this.polygon.setStrokeStyle(changes.options.currentValue.strokeStyle)
}

if (!isUndefined(changes.options.currentValue.enableMassClear)) {
this.polygon[changes.options.currentValue.enableMassClear ? 'enableMassClear' : 'disableMassClear']()
}
if (!isUndefined(changes.options.currentValue.enableEditing)) {
this.polygon[changes.options.currentValue.enableEditing ? 'enableEditing' : 'disableEditing']()
}
}

$onDestroy() {
this.mapCtrl.removeOverlay(this.polygon)
}
}
}
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import baiduMap from './components/baiduMap'
import marker from './components/marker'
import polyline from './components/polyline'
import circle from './components/circle'
import polygon from './components/polygon'
import control from './components/control'
import overlay from './components/overlay'
import mapScriptProvider from './provider/mapScript'
Expand All @@ -20,6 +21,7 @@ angular
.component('marker', marker)
.component('polyline', polyline)
.component('circle', circle)
.component('polygon', polygon)
.component('control', control)
.component('overlay', overlay)

Expand Down

0 comments on commit 421fb62

Please sign in to comment.