-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathpx-map-tile-layer-bing.html
162 lines (140 loc) · 4.79 KB
/
px-map-tile-layer-bing.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!--
Copyright (c) 2018, General Electric
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Relative paths assume component is being run from inside an app or another component, where dependencies are flat
siblings. When this component is run from its own repo (e.g. tests, examples), we assume the server is started with
'gulp serve' (or similar server setup) to enable correct finding of bower dependencies for local runs.
-->
<link rel="import" href="../polymer/polymer.html"/>
<!-- Load external dependencies -->
<link rel="import" href="../leaflet-bing-tiles/leaflet-bing-tiles.html">
<!-- Load required PxMapBehaviors -->
<link rel="import" href="px-map-behavior-tile-layer.html">
<!--
Adds a Bing Maps tile layer. Bing tiles are requested by authenticating with a
valid Bing Maps API key and choosing the type of imagery to display.
Note that a Bing Maps API key is not provided by this component. You will need
to [sign up and create your own API key](https://msdn.microsoft.com/en-us/library/ff428642.aspx).
If you do not provide an API key, the map will not load any tiles.
### Usage
<px-map>
<px-map-tile-layer-bing key="XXXXXXXXXXXXXXXXXXXXX"></px-map-tile-layer-bing>
</px-map>
@element px-map-tile-layer-bing
@blurb Loads base layer tiles from the Bing Maps API
@homepage index.html
@demo index.html
-->
<dom-module id="px-map-tile-layer-bing">
<template>
<style>
:host { display: none }
</style>
</template>
</dom-module>
<script>
Polymer({
is: 'px-map-tile-layer-bing',
behaviors: [PxMapBehavior.Layer],
properties: {
/**
* A valid Bing Maps API key. Required to fetch the tiles - if it is not
* provided, no tiles will be loaded.
*/
key: {
type: String,
observer: 'shouldUpdateInst'
},
/**
* The imagery set to use. Choose from the following options:
*
* - 'Aerial' - (default) Aerial imagery
* - 'AerialWithLabels' - Aerial imagery with a road overlay.
* - 'Roads' - Roads without additional imagery
*
* The following Bing imagery sets are not supported: 'Birdseye',
* 'BirdseyeWithLabels', 'OrdnanceSurvey'.
*/
imagery: {
type: String,
value: 'Aerial',
observer: 'shouldUpdateInst'
},
/**
* Set to disable adding attribution information to the map for this
* tile layer.
*
* @type {Boolean}
*/
disableAttribution: {
type: Boolean,
value: false,
observer: 'shouldUpdateInst'
},
/**
* Language code for map labels. For a list of acceptable codes, see:
* https://msdn.microsoft.com/en-us/library/hh441729.aspx
*/
languageCode: {
type: String,
value: 'en-US',
observer: 'shouldUpdateInst'
},
/**
* Opacity of the layer. Particularly useful for reducing the intensity
* of color from satellite imagery. Accepts values between 0.0 and 1.0.
*/
opacity: {
type: Number,
value: 1.0,
observer: 'shouldUpdateInst'
}
},
canAddInst: function() {
return (typeof this.key === 'string') && this.key.length;
},
createInst: function(options) {
return L.tileLayer.bing(options);
},
updateInst: function(lastOptions, nextOptions) {
if (lastOptions.bingMapsKey !== nextOptions.bingMapsKey) {
this.elementInst.setKey(nextOptions.bingMapsKey);
}
if (lastOptions.imagerySet !== nextOptions.imagerySet) {
this.elementInst.setImagery(nextOptions.imagerySet);
}
if (lastOptions.culture !== nextOptions.culture) {
this.elementInst.setCulture(nextOptions.culture);
}
if (lastOptions.noAttribution !== nextOptions.noAttribution) {
if (nextOptions.noAttribution) {
this.elementInst.disableAttribution();
} else {
this.elementInst.enableAttribution();
}
}
if (lastOptions.opacity !== nextOptions.opacity) {
this.elementInst.setOpacity(nextOptions.opacity);
}
},
getInstOptions: function() {
return {
bingMapsKey: this.key,
imagerySet: this.imagery,
culture: this.languageCode,
noAttribution: this.disableAttribution,
opacity: this.opacity
};
}
});
</script>