New map javascript
Here is an example of how to create a new map using JavaScript:
Using Google Maps
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40.7128, lng: -74.0060},
zoom: 12
});
}
In this example, we create a new Google Map object and pass it an HTML element (#map
) to render the map in. We also set the center of the map to New York City and the zoom level to 12.
Using Leaflet
var map = L.map('map').setView([40.7128, -74.0060], 12);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a rel="nofollow" target="_blank" href="https://www.openstreetmap.org/">OpenStreetMap</a>',
subdomains: ['a', 'b', 'c']
}).addTo(map);
In this example, we create a new Leaflet map object and set the center of the map to New York City and the zoom level to 12. We also add a tile layer to the map using OpenStreetMap tiles.
Using Mapbox
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-74.0060, 40.7128], // starting position [lng, lat]
zoom: 12 // starting zoom
});
In this example, we create a new Mapbox map object and set the center of the map to New York City and the zoom level to 12. We also set the style of the map to the "Streets" style.
Common attributes
center
: The center of the map, specified as a latitude and longitude pair.zoom
: The initial zoom level of the map.mapTypeId
: The type of map to display (e.g. "roadmap", "satellite", "hybrid").mapTypeControl
: Whether to display the map type control (e.g. buttons to switch between map types).
Note: You will need to replace YOUR_MAPBOX_ACCESS_TOKEN
with your actual Mapbox access token.