How to do add multiple pushpins to the Bing map v7 through Ajax API.. ?
They could be loaded from a array, list, json or anywhere else..
could someone provide a small example? Thank you
You can use EntityCollection to add several pins at the same time.
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0&mkt=de-de" type="text/javascript" charset="UTF-8"></script>
</head>
<body onload="init()">
<div id="map" style="position: relative; width: 800px; height: 300px;"></div>
<script type="text/javascript">
function init(){
// Initialize the map
var map = new Microsoft.Maps.Map(
document.getElementById("map"),
{
credentials: "YOUR-BING-KEY",
mapTypeId: Microsoft.Maps.MapTypeId.road
}
);
// Creates a collection to store multiple pins
var pins = new Microsoft.Maps.EntityCollection();
// Creates 5 random pins
for (var i = 0; i < 5; i++){
// A random position
var position = new Microsoft.Maps.Location(Math.random() * 45, Math.random() * 90);
// Creates a Pushpin
var pin = new Microsoft.Maps.Pushpin(position);
// Adds the pin to the collection instead of adding it directly to the Map
pins.push(pin);
}
// Adds all pins at once
map.entities.push(pins);
}
</script>
</body>
</html>
Also, here another example using JSON and jQuery.
Related
I am trying to delete all the markers on my map, but code below only the last added marker will be deleted.
Is there a way to get a new a instance of map i mean on click of a button is there a way to reinitialize the map in leaflet?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="https://npmcdn.com/leaflet#1.0.0-rc.3/dist/leaflet.css" />
</head>
<body>
<script src="https://npmcdn.com/leaflet#1.0.0-rc.3/dist/leaflet.js"></script>
<script src="../leaflet/lib/AnimatedMarker.js"></script>
<style>
#mapid { height: 500px; }
</style>
<div id="mapid"></div>
<script>
var mymap = L.map('mapid').setView([40.68510, -73.94136], 13);
L.tileLayer('http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png', {
attribution: '© Openstreetmap France | © OpenStreetMap'
}).addTo(mymap);
var marker = L.marker([40.68510, -73.94136]).addTo(mymap);
var marker = L.marker([40.68576, -73.94149]).addTo(mymap);
var marker = L.marker([40.68649, -73.94165]).addTo(mymap);
mymap.removeLayer(marker);
</script>
</body>
</html>
Instead of adding markers to the map, add your markers to a layerGroup and add the layerGroup to the map.
You can remove the markers using clearLayers() method.
var markers = L.layerGroup([marker1, marker2]).addTo(map);
markers.clearLayers();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Drawing Tools Sample</title>
<!-- Bing Map Control references -->
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
function GetMap() {
map = new Microsoft.Maps.Map(document.getElementById("myMap"), {
credentials: "",
zoom: 17,
center: new Microsoft.Maps.Location(47.592, -122.332)
});
var infoboxOptions = {
width: 200,
height: 100,
showCloseButton: true,
zIndex: 0,
offset: new Microsoft.Maps.Point(10, 0),
showPointer: true
};
var defaultInfobox = new Microsoft.Maps.Infobox(map.getCenter(), infoboxOptions);
map.entities.push(defaultInfobox);
defaultInfobox.setHtmlContent('<div>MY TEXT <input type="text"></div>');
}
</script>
</head>
<body onload="GetMap()">
<div style="position:relative;width:250px;height:150px;float:left;">
<div id="myMap" style="position:relative; width:600px;height:200px;"></div>
</div>
</body>
</html>
I am looking add custom Html elements such as textbox, textarea to bing map pushpin therefore it can be editable when it placed.
problem is can be place push pin with textbox or textarea but it cannot be editable.
This is a limitation of the default infobox class. You can work around this by using the custom infobox module found here: https://bingmapsv7modules.codeplex.com/wikipage?title=Custom%20Infobox%20Control
I am using Mapbox API to create simple maps and learn. I have written a very simple code to display the centre on some coordinates but the map won't show.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'pk.eyJ1Ijoicm9oYW4wNzkzIiwiYSI6IjhFeGVzVzgifQ.MQBzoHJmjH19bXDW0b8nKQ';
var map = L.mapbox.map('map', {
center: [28.611690, 77.191008],
zoom: 13
});
</script>
</body>
</html>
What am I doing wrong here?
You're using the wrong parameters for L.mapbox.map, the first element is correct, that's for the ID of a HTML element or a reference to an HTML element. The second however, isn't for the options object. The second is for your mapbox mapid (or url, or tilejson), which you get when you create your own map via the Mapbox editor: https://www.mapbox.com/editor/#app The third parameter is for the options object.
L.mapbox.accessToken = 'pk.eyJ1IjoicGF1bC12ZXJob2V2ZW4iLCJhIjoiZ1BtMWhPSSJ9.wQGnLyl1DiuIQuS0U_PtiQ';
var map = L.mapbox.map('map', 'examples.map-i86nkdio', {
center: [28.611690, 77.191008],
zoom: 13
});
Is there a way to use an svg element as an icon for the Microsoft.Maps.Pushpin?
I created an svg
element like this:
var fillcolor = "#ff0222";
var svg1 = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg1.setAttribute("height",50);
svg1.setAttribute("width",50);
var circles = document.createElementNS("http://www.w3.org/2000/svg", "circle");
circles.setAttribute("cx",25);
circles.setAttribute("cy",25);
circles.setAttribute("r",25);
circles.setAttribute("fill",fillcolor);
svg1.appendChild(circles);
On the Microsoft.Maps.Pushpin it is possible to set the options (PushpinOptions) where you can specify the htmlContent property to the value of your choice.
See: http://msdn.microsoft.com/en-us/library/gg427629.aspx
And the iSDK sample: http://www.bingmapsportal.com/isdk/ajaxv7#Pushpins15
The code should be inspired by something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Add pushpin with options</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'), {credentials: 'Your Bing Maps Key'});
}
function addCustomPushpin()
{
var pushpinOptions = {width: null, height: null, htmlContent: "<div style='font-size:12px;font-weight:bold;border:solid 2px;background-color:LightBlue;width:100px;'>Custom Pushpin</div>"};
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), pushpinOptions);
map.entities.push(pushpin);
}
</script>
</head>
<body onload="getMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div>
<input type="button" value="AddCustomPushpin" onclick="addCustomPushpin();" />
</div>
</body>
</html>
I am using Bing Maps v7 and created a draggable pushpin. i have taken code from here.
http://www.garzilla.net/vemaps/Draggable-Push-Pins-with-Bing-Maps-7.aspx
I need to restrict the drag outside of visible map area.
I have a defined map area with zoom pan disabled and with draggable pin where user can put there pin.
issue: pushpin is draggable outside of map then no option to get that back.
On the Pushpin class, you have several events to manage the action that are done on drag start, drag and drag end, see on MSDN: http://msdn.microsoft.com/en-us/library/gg427615.aspx
So, to be simple, all you have to do is to handle the event of your choice (in your case, I would recommend to use drag on the pushpin) and cancel the event or just modify by yourself the location of the pushpin.
See a live example where the pushpin is restricted to a minimal latitude value (you can update the drag event to be able to restrict to a specific area based on your current map view):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Bing Maps AJAX V7 - Restricted draggable pushpin</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
<script type="text/javascript">
var map = null;
var minLatitude = 49;
function getMap()
{
map = new Microsoft.Maps.Map(document.getElementById('myMap'),
{
credentials: 'YOURKEY',
center: new Microsoft.Maps.Location(50, 3),
zoom: 6
});
}
function addDraggablePushpin()
{
var pushpinOptions = {draggable: true};
var pushpin= new Microsoft.Maps.Pushpin(map.getCenter(), pushpinOptions);
map.entities.push(pushpin);
Microsoft.Maps.Events.addHandler(pushpin, 'drag', function() {
var loc = pushpin.getLocation();
// Verify if it's in a certain area if not, cancel event
if(loc.latitude < minLatitude) {
pushpin.setLocation(new Microsoft.Maps.Location(minLatitude, loc.longitude));
}
});
}
</script>
</head>
<body onload="getMap();">
<div id='myMap' style="position:relative; width:400px; height:400px;"></div>
<div>
<input type="button" value="AddDraggablePushpin" onclick="addDraggablePushpin();" />
</div>
</body>
</html>