-1

I am using mapbox.js for this.

i am working on the project which requires to change the styling of map, eg: area,land and water colors on click of certain button. one possible way is, i use different project_ids and toggle between layer which can be easily achieved. but i want to use same project_id and hence i have to then change the style of map using javascript code dynamically. at one place i found that i can use cartoCSS for this. but i dont know anything about using it in mapbox.

  • What is the source of your map tiles/WMS? Does it support changing of symbology? – Devdatta Tengshe Dec 20 '14 at 12:47
  • i am using mapbox. and mapbox uses Openstreetmap. – Akshay Dec 20 '14 at 13:52
2

Assuming you are loading maptiles from your mapbox account--using something like L.mapbox.tileLayer there is no way to change the style of tiles client side. Your options would be:

  • load the data you want to be able to style dynamically as vector data, displayed on top of your raster tilelayer, using something like L.mapbox.featureLayer and L.mapbox.simplestyle. Then, change its style via javascript. Of course, loading large vector sources (particularly complex polygons) into your browser can cause the browser to slow down or freeze. Loading as a topojson rather than geojson can help.

  • check out mapbox-gl, still in beta, particularly this example. To style your data w/ mapbox-gl, upload the source vector tiles to your mapbox account with MapBox Studio, and style it in browser using its json-based style spec.

caveat: you can style raster tiles via css, just as you would style any <img />. E.g. you can apply css image filters. It doesn't sound like this is what you're looking for though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.