bMap - Examples

1. Basic example2. Markers in constructor3. Markers, polylines & polygons
4. Marker sidebar5. Layer Sidebar6. AJAX Layers
7. Advanced AJAX8. Google Functions9. Custom Icons
10. Advanced marker events11. Image Overlay Function12. New sidebar features
V3 - Example 3V3 Example 5V3 Example 12
V3 API Custom Icons
Please note that unless stated, the examples shown here use the V2 of the google maps API - and bMap version 1.2.3
There are only three examples using the V3 API - and bMap 1.3

Adding Markers, Lines and Polygons to the map



How its done:

Here we can see some fundamental bMap concepts. Firstly we can see the functions used to add content to the map, and the data structures they accept. The functions are called by accessing the bMap object that belongs to the map div.
$('#map_div_id').data('bMap').functions....
All the bMap functions are accessed this way, and the actual Google Maps API map object is here too.
We can also see the layer sidebar in use, and the CSS class used to highlight hidden layers.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=YOUR_GOOGLE_KEY" type="text/javascript"></script>
<script type="text/javascript" src="jQuery.bMap.1.2.3.js"></script>
<style type="text/css">
<!--
	#map{ width:500px;height:500px;float:left }
	#layerBar{ width:200px;height:500px;text-align:center;background:#fff;float:right }
	#layerBar div{ padding:2px 0; cursor:pointer }
	#layerBar div:hover{ text-decoration:underline }
	#buttons{ clear:both;text-align:center }
	.bLyrHide{ color:#ddd; } /* class for hidden layerBar layers */
-->
</style>
<script type="text/javascript">
	$(document).ready(function(){ 
		$("#map").bMap({
			mapZoom: 11,
			mapCenter:[51.501690392607,-0.1263427734375],
			mapLayerbar:"layerBar" //Tell bMap to use a sidebar
		});
	});
	function button1(){ //This function acts on the bMap object, adding the layer
		$('#map').data('bMap').insertMarkers({
			"name":"Markers",
			"data":[
				{
					"lat":51.49757618329838,
					"lng":-0.1746654510498047, 
					"title":"Science Museum", 
					"body":"Exhibition Road, London SW7"
				},{
					"lat":51.47769451182406,
					"lng":-0.0009441375732421875, 
					"title":"Royal Observatory Greenwich", 
					"body":"Blackheath Ave, Greenwich, London SE10"
				}	
			]
		});
	}
	function button2(){
		$('#map').data('bMap').insertLine({
			"name":"Line",
			"data":[
				{
					"lat":51.49757618329838,
					"lng":-0.1746654510498047
				},{
					"lat":51.47769451182406,
					"lng":-0.0009441375732421875
				}	
			]
		});		
	}		
	function button3(){
		$('#map').data('bMap').insertPolygon({
			"name":"Polygon",
			"color":"#F00",
			"data":[
				{  
					"lat":51.51921169524832,
					"lng":-0.19947052001953125
				},{
					"lat":51.52540664057756,
					"lng":0.01819610595703125
				},{
					"lat":51.46063853898322,
					"lng":0.0295257568359375
				},{
					"lat":51.45507659279715,
					"lng":-0.19191741943359375
				},{  
					"lat":51.51921169524832,
					"lng":-0.19947052001953125
				}				
			]
		});
	}
</script>
<div style="width:700px;height:500px;margin:0 auto">
	<div id="map"></div>
	<div id="layerBar"></div>
	<div id="buttons">
		<input value="Add Markers" type="button" onclick="button1()">
		<input value="Add Polyline" type="button" onclick="button2()">
		<input value="Add Polygon" type="button" onclick="button3()">
		<input type="button" onclick="$('#map').data('bMap').removeAllLayers()" value="Remove ALL layers"></input>
	</div>
</div>

bMap Function Options:

insertMarkers: name string visual name for the layer, appears in layerbar type string describes the type of layer visible string ("true"/"false") if the layer should start visible data array array of bMap marker objects, rendered as GMarkers icon integer renders the marker with a custom icon from the icons array

insertLine: name string visual name for the layer, appears in layerbar type string describes the type of layer visible string ("true"/"false") if the layer should start visible data array array of latlng used to construct line color string line color, HTML style strings weight integer the line thickness opacity real 0.0 - 1.0 line opacity

insertPolygon: name string visual name for the layer, appears in layerbar type string describes the type of layer visible string ("true"/"false") if the layer should start visible data array array of latlng used to construct polygon edges color string polygon color, HTML style strings weight integer the edge line thickness opacity real 0.0 - 1.0 interior opacity




Comments:

icon parameter
Chris - 9/1/2010 9:26:26 PM
icon should not be listed under insertMarkers, it should be contained within the data array as part of each marker, the documentation as is confuses this.

Also there are no GIcon's with the latest google maps api...
Icons
Darren - 9/4/2010 3:04:39 AM
Hi,
Custom icons can be tricky, so I tried to make using them with bMap as straight forward as possible. You could tweak the code so that the parameters are delivered as part of the data array, but I figured if there was lots of makers with the same icon, then it would be an inefficient use of bandwidth. So all deliver in the data array is a reference to the icon you want from the icon array. It is a value that can be passed to insert markers, so it finds itself being mentioned here.

Icons are not implemented in bMap v1.3 that is correct, as I have yet to implement and test the code.
Markers with address
Lucas Teixeira - 9/16/2010 5:50:15 AM
Hello!

Nice plugin, is it possible to add a marker with an address? Like "Lodon, UK" as in the basic example you centered the map?

Thanks!
Address Location
Darren - 9/16/2010 2:08:41 PM
Hi Lucas,
A bMap user has implemented a feature like that using the google geolocater. They expanded the insertMarkers to check for an address field in the JSON - and if present - geolocated an address.

I have no plans to implement this feature into bMap as I believe it is not best practice to query an address everytime someone visits your website.

Darren

 (*required)
 (*private)
 (*required)
 
© 2010 blocsoft.com All Rights Reserved. GPL License Privacy Policy Contact