Created
November 24, 2014 12:08
-
-
Save ffflabs/9e08b294d3bd7ce09220 to your computer and use it in GitHub Desktop.
Overlaying an SVG maker on top of Google Maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
| <title>Google Maps Multiple Markers</title> | |
| <style> | |
| #map { | |
| margin:20px auto; | |
| } | |
| .reddot{ | |
| width:66px; | |
| height:66px; | |
| position:absolute | |
| } | |
| .locater{ | |
| position: absolute; | |
| top: 18px; | |
| left: 17px; | |
| } | |
| .mark{ | |
| fill: none; | |
| stroke: #FF9100; | |
| stroke-width: 1px; | |
| cursor: pointer; | |
| z-index: 1000; | |
| } | |
| </style> | |
| <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> | |
| </head> | |
| <body> | |
| <div id="map" style="width: 1000px; height: 600px;"></div> | |
| <script type="text/javascript"> | |
| var locations = [ | |
| ['STHOWBGA01_ATIF_RNID_L015',24.31026,93.56268], | |
| ['GWTRGOK004_BILF_RNOD_L023',23.70692,91.27397], | |
| ['GWTRBLWBN1_BILF_RNOD_L038',24.0179,91.4529], | |
| ['SJOWKHL007_ATIF_RNOD_L012',25.35197,92.3723], | |
| ['TTINNMSAI4_VIOF_RNID_L011',27.66616,95.87926], | |
| ['SIMWUKHRL5_VIOF_RNID_L061',25.12267,94.36558], | |
| ['SDIMZLUKI3_BILF_RNOD_L035',25.63658,93.64943] | |
| ]; | |
| var lat_center = 24.31026, | |
| long_center = 93.56268; | |
| var map = new google.maps.Map(document.getElementById('map'), { | |
| zoom: 8, | |
| center: new google.maps.LatLng(lat_center, long_center), | |
| mapTypeId: google.maps.MapTypeId.ROADMAP | |
| }); | |
| var infowindow = new google.maps.InfoWindow(); | |
| var marker, i, text; | |
| for (i = 0; i < locations.length; i++) { | |
| marker = new google.maps.Marker({ | |
| position: new google.maps.LatLng(locations[i][1], locations[i][2]), | |
| map: map | |
| }); | |
| text = locations[i][0]; | |
| if(locations[i][1] === lat_center && locations[i][2] === long_center) { | |
| marker.setAnimation(google.maps.Animation.DROP); | |
| marker.setIcon('https://maps.gstatic.com/intl/en_ALL/mapfiles/markers2/boost-marker-mapview.png'); | |
| map.Overlay= new google.maps.OverlayView(); | |
| map.Overlay.center_ = new google.maps.LatLng(lat_center, long_center); | |
| map.Overlay.reddot_ = '<div id="reddot" class="reddot" style="position:relative;"><svg class="marker" height="66" width="66"><circle cy="33" cx="33" class="mark" r="25"><set id="show" attributeName="visibility" attributeType="CSS" to="visible" begin="0s; hide.end" dur="1s" fill="freeze"/><set id="hide" attributeName="visibility" attributeType="CSS" to="hidden" begin="show.end" dur="1s" fill="freeze"/></circle><img src="http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png" class="locater"></svg></div>'; | |
| map.Overlay.draw = function () { | |
| var pixelposition = this.getProjection().fromLatLngToDivPixel(this.center_); | |
| jQuery('#reddot').css({top:(pixelposition.y-50), left:(pixelposition.x-33)}); | |
| }; | |
| map.Overlay.onAdd=function() { | |
| var self=this; | |
| jQuery(self.getPanes().markerLayer).append(self.reddot_); | |
| }; | |
| map.Overlay.setMap(map); | |
| } | |
| google.maps.event.addListener(marker, 'mouseover', (function(marker, text) { | |
| return function() { | |
| infowindow.setContent(text); | |
| infowindow.open(map, marker); | |
| } | |
| })(marker, text)); | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment