Created
March 4, 2012 12:53
-
-
Save cecilemuller/1972874 to your computer and use it in GitHub Desktop.
Extend Bing Maps AJAX 6.3 to create pushpins, polylines and polygons easily
This file contains 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
/** | |
* VEMap.CreatePushpin(point, options) and similar functions | |
* to create advanced pins, polylines & polygons easily in Bing Maps. | |
*/ | |
function _addshapeoptions(scope_, type_, points_, options_){ | |
var shape = new VEShape(type_, points_); | |
options_ = options_ || false; | |
if (options_){ | |
for (var key in options_){ | |
var option = options_[key]; | |
switch(key){ | |
case 'Icon': | |
case 'CustomIcon': | |
if (option === false) shape.HideIcon(); | |
else shape.SetCustomIcon(option); | |
break; | |
case 'Title': | |
shape.SetTitle(option); | |
break; | |
case 'Desc': | |
case 'Description': | |
shape.SetDescription(option); | |
break; | |
case 'URL': | |
case 'MoreInfoURL': | |
shape.SetMoreInfoURL(option); | |
break; | |
case 'Photo': | |
case 'PhotoURL': | |
shape.SetPhotoURL(option); | |
break; | |
case 'Z': | |
case 'Index': | |
case 'ZIndex': | |
shape.SetZIndex(option); | |
break; | |
case 'Min': | |
case 'MinZoomLevel': | |
shape.SetMinZoomLevel(option); | |
break; | |
case 'Max': | |
case 'MaxZoomLevel': | |
shape.SetMaxZoomLevel(option); | |
break; | |
case 'LineWidth': | |
shape.SetLineWidth(option); | |
break; | |
case 'LineColor': | |
shape.SetLineColor(option); | |
break; | |
case 'FillColor': | |
shape.SetFillColor(option); | |
break; | |
case 'Draggable': | |
case 'onstartdrag': | |
case 'ondrag': | |
case 'onenddrag': | |
shape[key] = option; | |
break; | |
} | |
} | |
} | |
scope_.AddShape(shape); | |
return shape; | |
}; | |
VEMap.prototype.CreatePushpin = function(point_, options_){ | |
return _addshapeoptions(this, VEShapeType.Pushpin, point_, options_); | |
}; | |
VEShapeLayer.prototype.CreatePushpin = function(point_, options_){ | |
return _addshapeoptions(this, VEShapeType.Pushpin, point_, options_); | |
}; | |
VEMap.prototype.CreatePolyline = function(points_, options_){ | |
return _addshapeoptions(this, VEShapeType.Polyline, points_, options_); | |
}; | |
VEShapeLayer.prototype.CreatePolyline = function(points_, options_){ | |
return _addshapeoptions(this, VEShapeType.Polyline, points_, options_); | |
}; | |
VEMap.prototype.CreatePolygon = function(points_, options_){ | |
return _addshapeoptions(this, VEShapeType.Polygon, points_, options_); | |
}; | |
VEShapeLayer.prototype.CreatePolygon = function(points_, options_){ | |
return _addshapeoptions(this, VEShapeType.Polygon, points_, options_); | |
}; |
This file contains 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
/** | |
* Usage Example: Draggable pushpin | |
*/ | |
var map = new VEMap('container'); | |
map.LoadMap( new VELatLong(0, 0), 2 ); | |
var pin = map.CreatePushpin( | |
new VELatLong(-50, -30), | |
{ | |
Title: 'Draggable pin', | |
Draggable: true, | |
onstartdrag: function(){}, | |
ondrag: function(){}, | |
onenddrag: function(){} | |
} | |
); | |
map.ShowInfoBox(pin); |
This file contains 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
/** | |
* Usage Example: Multiple polygons using the same color settings. | |
*/ | |
var map = new VEMap('container'); | |
map.LoadMap( new VELatLong(0, 0), 2 ); | |
var color = { | |
Icon: false, | |
LineWidth: 3, | |
LineColor: new VEColor(255, 0, 0, 1.0), | |
FillColor: new VEColor(0, 100, 150, 0.5) | |
}; | |
map.CreatePolygon( | |
[ | |
new VELatLong(-10, -5, 10), | |
new VELatLong(0, 5, 10), | |
new VELatLong(10, -5, 10), | |
new VELatLong(-10, -5, 10), | |
], | |
color | |
); | |
map.CreatePolygon( | |
[ | |
new VELatLong(-10, 20, 10), | |
new VELatLong(0, 30, 10), | |
new VELatLong(10, 20, 10), | |
new VELatLong(-10, 20, 10), | |
], | |
color | |
); |
This file contains 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
/** | |
* Usage Example: Custom pushpin | |
*/ | |
var map = new VEMap('container'); | |
map.LoadMap( new VELatLong(0, 0), 2 ); | |
map.CreatePushpin( | |
new VELatLong(50, 30), | |
{ | |
Icon: 'http://i.msdn.microsoft.com/dynimg/IC142439.jpg', | |
Title: 'This is the title', | |
Description: 'This is the description', | |
URL: 'http://www.bing.com', | |
Photo: 'http://www.google.com/images/logos/ps_logo2.png', | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment