javascript - Using mapbox js, how do I change the style of a map? -
i have included js
, css
mapbox
in header
:
<script src='//api.mapbox.com/mapbox.js/v2.2.4/mapbox.js'></script> <link href='//api.mapbox.com/mapbox.js/v2.2.4/mapbox.css' rel='stylesheet' />
added map html:
<div id='map'></div> <style> body { margin:0; padding:0; } #map { width:100%; height:471px; } </style>
and in js
made map:
l.mapbox.accesstoken = 'pk.eyj1ijoic21py2tpzsisimeioijjawtim2jkdw0wmdjudnrsety0nwdrbjfnin0.wxgyl18bjjwuiniu-r3msa'; var map = l.mapbox.map('map', 'mapbox.streets').setview([40, -74.50], 3);
i don't know how change style of 1 have in mapbox
studio.
i have 2 style urls in mapbox studio:
mapbox://styles/smickie/cikb3fhvi0063cekqns0pk1f1 https://api.mapbox.com/styles/v1/smickie/cikb3fhvi0063cekqns0pk1f1.html?title=true&access_token=pk.eyj1ijoic21py2tpzsisimeioijjawtim2jkdw0wmdjudnrsety0nwdrbjfnin0.wxgyl18bjjwuiniu-r3msa#1.4858291953347187/42.16057367191365/1.6334765316350683/0
how apply these styles map in page?
this api can't find how change styles anywhere: https://www.mapbox.com/mapbox.js/api/v2.2.4/
edit: updated answer because of introduction of v2.3.0 of mapbox.js api. add l.mapbox.stylelayer
can handle styles created using mapbox studio:
l.mapbox.stylelayer('mapbox://styles/mapbox/emerald-v8').addto(map);
example: https://www.mapbox.com/mapbox.js/example/v1.0.0/stylelayer/
answer before mapbox 2.3.0:
you're using wrong api, styles use mapbox-gl api:
https://www.mapbox.com/mapbox-gl-js/examples/
if want use classic mapbox api you're doing need use mapbox studio classic create own styled tileset:
Comments
Post a Comment