|
4 | 4 | <x-docs-layout>
|
5 | 5 | <div class="grid grid-cols-3 gap-8">
|
6 | 6 | <div class="col-span-3">
|
7 |
| - <x-docs-box> |
8 |
| - <h2>Bing Maps Integration</h2> |
| 7 | + <x-docs-box class="mb-8"> |
| 8 | + <h2 id="static-icons"> |
| 9 | + <a href="#static-icons" class="no-underline"> |
| 10 | + Bing Maps Integration |
| 11 | + </a> |
| 12 | + </h2> |
9 | 13 | <p>Here is a quick code sample that demonstrates how to use our map markers with Bing Maps.</p>
|
| 14 | + |
| 15 | + <p> |
| 16 | + <strong>Important for animated map markers: </strong> |
| 17 | + Bing Maps renders all shapes on an HTML 5 canvas which ends up flattening images and disables any animation |
| 18 | + they might have built in. <strong>In this case its likely only rendering the first frame of your animated image</strong> |
| 19 | + which may be the reason why it can't be seen. The solution is to use an "HTML Pushpin": <a href="#animated-icons">Read more.</a> |
| 20 | + </p> |
| 21 | + |
10 | 22 | <div class="rounded-lg overflow-hidden">
|
11 |
| - <div id="map-bing" style="height:200px"></div> |
| 23 | + <div id="map-bing-simple" style="height:400px"></div> |
12 | 24 | </div>
|
13 | 25 | <script type="text/javascript">
|
14 | 26 | /* global Microsoft */
|
15 |
| - function loadMapScenario() { |
16 |
| - var map = new Microsoft.Maps.Map(document.getElementById('map-bing'), { |
| 27 | + function loadBasicMapScenario() { |
| 28 | + var map = new Microsoft.Maps.Map(document.getElementById('map-bing-simple'), { |
17 | 29 | credentials: '4Dwl9bv4EyWxxh5vxGrc~DQVhL9QibE1uVG3H0y3ESw~Atmr7fRt7VzikgATJcQAzGBsq-fs9Ac6xCv4yPh0ScskuqonEIFN_vGCjn606TiN',
|
18 | 30 | disableScrollWheelZoom: true
|
19 | 31 | });
|
20 |
| - var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), { |
| 32 | +
|
| 33 | + var loc = new Microsoft.Maps.Location(-25.34492034440821, 131.0329830613222); |
| 34 | +
|
| 35 | + var pushpin = new Microsoft.Maps.Pushpin(loc, { |
21 | 36 | icon: '{{ config('app.url') }}/api/v3/font-awesome/v6/pin?icon=fa-solid+fa-star&size=50&hoffset=0&voffset=-1',
|
22 |
| - anchor: new Microsoft.Maps.Point(12, 39) |
| 37 | + anchor: new Microsoft.Maps.Point(25, 50) |
23 | 38 | });
|
24 | 39 | map.entities.push(pushpin);
|
| 40 | + map.setView({ center: loc, zoom: 12 }); |
25 | 41 |
|
26 | 42 | }
|
27 | 43 | </script>
|
28 |
| - <script type="text/javascript" src='https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenario' async defer> |
29 |
| - </script> |
| 44 | + |
30 | 45 | <pre>var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
|
31 | 46 | credentials: 'Your Bing Maps Key'
|
32 | 47 | });
|
33 | 48 |
|
34 | 49 | var pushpin = new Microsoft.Maps.Pushpin(map.getCenter(), {
|
35 | 50 | icon: '{{ config('app.url') }}/api/v3/font-awesome/v6/pin?icon=fa-solid+fa-star&size=50&hoffset=0&voffset=-1',
|
36 |
| - anchor: new Microsoft.Maps.Point(12, 39) |
| 51 | + // define an anchor point at the bottom middle of pin markers to avoid visual shift during zooms |
| 52 | + // for non-pin style markers, you probably won't need this |
| 53 | + anchor: new Microsoft.Maps.Point(25, 50) |
37 | 54 | });
|
38 | 55 |
|
39 | 56 | map.entities.push(pushpin);</pre>
|
40 | 57 |
|
41 | 58 | </x-docs-box>
|
| 59 | + |
| 60 | + <x-docs-box> |
| 61 | + <h2 id="animated-icons" class="mt-0"> |
| 62 | + <a href="#animated-icons" class="no-underline"> |
| 63 | + Bing Maps Animated Icons via HTML Pushpin |
| 64 | + </a> |
| 65 | + </h2> |
| 66 | + <p>Here is a quick code sample that demonstrates how to use our animated map markers with Bing Maps:</p> |
| 67 | + |
| 68 | + <ol> |
| 69 | + <li>Initialize Bing Map</li> |
| 70 | + <li>Initialize Bing Map HtmlPushpinLayerModule Module</li> |
| 71 | + <li>Async Load MapMarker.io Icon</li> |
| 72 | + <li>Add Icon to HtmlPushpinLayer</li> |
| 73 | + <li>Add HtmlPushpinLayer to Bing Map</li> |
| 74 | + </ol> |
| 75 | + |
| 76 | + <div class="rounded-lg overflow-hidden"> |
| 77 | + <div id="map-bing-html-pushpin" style="height:400px"></div> |
| 78 | + </div> |
| 79 | + <script type="text/javascript"> |
| 80 | + /* global Microsoft */ |
| 81 | + function loadHtmlPushpinMap() { |
| 82 | +
|
| 83 | + var map = new Microsoft.Maps.Map(document.getElementById('map-bing-html-pushpin'), { |
| 84 | + credentials: '4Dwl9bv4EyWxxh5vxGrc~DQVhL9QibE1uVG3H0y3ESw~Atmr7fRt7VzikgATJcQAzGBsq-fs9Ac6xCv4yPh0ScskuqonEIFN_vGCjn606TiN', |
| 85 | + disableScrollWheelZoom: true |
| 86 | + }); |
| 87 | +
|
| 88 | + // initalize map |
| 89 | + var loc = new Microsoft.Maps.Location(-25.34492034440821, 131.0329830613222); |
| 90 | + map.setView({ center: loc, zoom: 12 }); |
| 91 | +
|
| 92 | + // fetch html pushpin layer module (source: https://samples.bingmapsportal.com/overlays/html-pushpin-layer) |
| 93 | + Microsoft.Maps.registerModule('HtmlPushpinLayerModule', 'https://samples.bingmapsportal.com//overlays/html-pushpin-layer/HtmlPushpinLayerModule.js'); |
| 94 | + Microsoft.Maps.loadModule('HtmlPushpinLayerModule', function () { |
| 95 | +
|
| 96 | + // fetch marker |
| 97 | + const Http = new XMLHttpRequest(); |
| 98 | + const url='{{ config('app.url') }}/api/v3/font-awesome/v6/icon?size=50&icon=fa-solid%20fa-person-hiking&color=333&label=&labelAnimation=pulse&labelAnimationDuration=1s&lc=4CAF50'; |
| 99 | + Http.open("GET", url); |
| 100 | + Http.send(); |
| 101 | +
|
| 102 | + // marker loaded callbakc |
| 103 | + Http.onreadystatechange = function() { |
| 104 | + // marker available |
| 105 | + if(this.readyState == 4 && this.status == 200) { |
| 106 | + var pin = new HtmlPushpin(loc, Http.responseText, {anchor: new Microsoft.Maps.Point(25, 50)}); |
| 107 | + layer = new HtmlPushpinLayer([pin]); |
| 108 | + map.layers.insert(layer); |
| 109 | + } |
| 110 | + } |
| 111 | + }); |
| 112 | +
|
| 113 | + } |
| 114 | + </script> |
| 115 | + |
| 116 | + <pre>var map = new Microsoft.Maps.Map(document.getElementById('map-bing-html-pushpin'), { |
| 117 | + credentials: 'Your Bing Maps Key', |
| 118 | + disableScrollWheelZoom: true |
| 119 | +}); |
| 120 | + |
| 121 | +// initalize map |
| 122 | +var loc = new Microsoft.Maps.Location(-25.34492034440821, 131.0329830613222); |
| 123 | +map.setView({ center: loc, zoom: 12 }); |
| 124 | + |
| 125 | +// fetch html pushpin layer module (source: https://samples.bingmapsportal.com/overlays/html-pushpin-layer) |
| 126 | +Microsoft.Maps.registerModule('HtmlPushpinLayerModule', 'https://samples.bingmapsportal.com//overlays/html-pushpin-layer/HtmlPushpinLayerModule.js'); |
| 127 | +Microsoft.Maps.loadModule('HtmlPushpinLayerModule', function () { |
| 128 | + |
| 129 | + // fetch marker |
| 130 | + const Http = new XMLHttpRequest(); |
| 131 | + const url='{{ config('app.url') }}/api/v3/font-awesome/v6/icon?size=50&icon=fa-solid%20fa-person-hiking&color=333&label=&labelAnimation=pulse&labelAnimationDuration=1s&lc=4CAF50'; |
| 132 | + Http.open("GET", url); |
| 133 | + Http.send(); |
| 134 | + |
| 135 | + // marker loaded callbakc |
| 136 | + Http.onreadystatechange = function() { |
| 137 | + // marker available |
| 138 | + if(this.readyState == 4 && this.status == 200) { |
| 139 | + var pin = new HtmlPushpin(loc, Http.responseText, {anchor: new Microsoft.Maps.Point(25, 50)}); |
| 140 | + layer = new HtmlPushpinLayer([pin]); |
| 141 | + map.layers.insert(layer); |
| 142 | + } |
| 143 | + } |
| 144 | +});</pre> |
| 145 | + |
| 146 | + </x-docs-box> |
42 | 147 | </div>
|
43 | 148 | </div>
|
| 149 | + |
| 150 | + {{-- INITALIZE ALL MAPS ON PAGE --}} |
| 151 | + <script type="text/javascript"> |
| 152 | + function loadMapScenarios() { |
| 153 | + loadBasicMapScenario(); |
| 154 | + loadHtmlPushpinMap(); |
| 155 | + } |
| 156 | + </script> |
| 157 | + <script type="text/javascript" src="https://www.bing.com/api/maps/mapcontrol?callback=loadMapScenarios" async defer></script> |
44 | 158 | </x-docs-layout>
|
45 | 159 | @endsection
|
0 commit comments