Switch styles on an OpenStreetMap server using Mapnik, PostGIS etc - openstreetmap

I have created an OpenStreetMap server using this guide: switch to osm it's very good and works like a charm. I have also been able to add a new theme using TileMill and osm-brigth
However, I now want to be able to switch between two themes, osm-bright and osm-night. Is this an apache question or is there a way to modify mapnik to be able to get a parameter from for example openlayers to switch between these two themes?
Gratefull for any advice.

Install "OSM Night" style like the first one into a separate directory, download all required files.
Produce XML out of MML with carto -l project.mml > osm-night.xml, like you probably did with osm-bright.
Edit /etc/renderd.conf adding a second style section, like for osm-bright, but with names and paths to osm-night.
Restart renderd and apache2.
After that you will have two set of tiles generated: e.g. /osm-bright/{z}/{x}/{y}.png and /osm-night/{z}/{x}/{y}.png. Add both of them as tile layers to your OpenLayers page, and add a layer switcher. (I use Leaflet and not sure how it's done in OL).

Related

Mapbox Studio: can you change the style after the fact?

Is it possible to change the base style of a custom style after the fact in Mapbox Studio? If yes, how? I looked around the UI and in the documentation but couldn't find how.
Say I created a private style from the Vintage designer style (for example's sake), then added and customized layers by importing tilesets, can I switch to the another base style (e.g. North Star), or do I need to start a new custom style from the start?
Yes. Mapbox Studio is just a GUI for generating Javascript; it outputs a giant JSON file.
(A Mapbox Style is just a JSON object.)
Each of your data layers is included in that JSON (and can be copied and pasted into another style JSON).
Use these instructions to learn the process:
https://mapbox.com/help/transfer-styles-between-accounts
Hope that helps!

how to apply a custom mode to mapbox-gl-draw when writing a html which uses GL draw to draw a feature

On the github of the mapbox-gl-draw, I've seen that draw provides an interface for writing and hooking in custom modes, but how does the custom modes actually be used on the browser? For example, if I want to write a mode which can draw a curve line, how can I add this new mode to draw's original modes and be used in browser? I'm new to mapbox gl, and hope anyone can help me on this, thanks a lot!
download the zip on the github, and edit the js file in src. At last, use the nodejs to execute "npm run build" and generate a new mapbox-gl-draw.js in the dist, which can be used in the html by writing

openui5 googlemaps xmlview

I am currently building an, where i need to add a maps option. I found the openui5-googlemaps option which fitted my needs. Currently i managed to get the marker to work in an xml view without any problems. However I want to add directions with waypoints similar to what you see here:
DirectionsWithWaypoints
But i can't figure out how to build this into my XML view. I tried to add this via the controller to the view and just add the myMap element to the page. That did show the map, but it didn't show any directions, i looked at the binding and i had the correct binding.
If i added the myMap to the context of the HTML file instead, then it works.
See the code here
Can someone help?
one trick to finding out how to make something work in an XML view is via the SAPUI5 Diagnostics tool, it generates the xml for you
<ctrl><shift><alt> + S
opens the SAPUI5 Diagnostics tool, then
-> Control Tree -> Export -> XML
here is an example using generated xmlview

How to serve styled vector map data via CartoCSS

I've got an example data set of lines and points, representing peoples' journey to work and where they feel at risk from road accidents.
Now, the data have attributes such as Place (Home, Work, Danger) and the severity of accidents they fear in different places. So the wider question is how to visualise this on a web map. For that I've looked into Google Maps, Leaflet and OpenLayers3. Each of these looks great and allow nice styling but none, to my eye, have the neatness of CartoCSS for fast, complex and intuitive styling, like the code below used to create the image below:
So I tried it out in tile mill and this is what I came up with, after converting the things to raster tiles via TileMill.
But this is a silly way to do things: it cannot overlay a base layer and would be much more efficient to just serve the vector data and style them in the client side, perhaps using something like mapbox.js. But I cannot work out how to use the lovely CartoCSS language in the client side to style GeoJSON files. (How) Is this possible?
p.s. here's how I styled the above map
#tlines {
line-width:1;
line-color: #0b0;
}
#tpoints.points{
marker-width: 6;
}
#tpoints.points[Place='Danger'] {
marker-fill:#db0d0d;
}
#tpoints.points[Place='Home'] {
marker-fill:#db0;
}
#tpoints.points[Severity='1']{
marker-width: 4;}
#tpoints.points[Severity='2']{
marker-width: 6;}
#tpoints.points[Severity='3']{
marker-width: 10;}
I cannot work out how to use the lovely CartoCSS language in the client side to style GeoJSON files. (How) Is this possible?
It is not possible to use CartoCSS for styling features browser side.
To learn how to style GeoJSON in Mapbox.js/Leaflet.js take a look at the docs here:
Styling GeoJSON in Mapbox.js https://www.mapbox.com/mapbox.js/api/v1.6.2/l-geojson/ (works exactly as in Leaflet.js as Mapbox.js is based on Leaflet.js)
You can embed style options directly into the GeoJSON object with L.mapbox.simplestyle.style https://www.mapbox.com/mapbox.js/api/v1.6.2/l-mapbox-simplestyle-style/
Alex rightly points out that vector styling in Leaflet/Mapbox.js is a different creature than CartoCSS styling a la Tilemill or Mapbox Studio. However, it is possible to style features in a browser using CartoCSS; it just requires one of two things:
A different platform: CartoDB has an excellent JS library for styling hosted data with CartoCSS, based on leaflet and fully compatible with Mapbox basemaps.
Hosting your own tile server, either the CartoDB server or a combination of Mapbox-built tools.
If you are using GeoJson as data source, you may try the Leaflet.geojsonCSS plug-in for Leaflet.js. The Geojson CSS provides the styling definition for each feature in the collection in a css-like format. Using this requires to add the styling definition in the geojson beforehand.

Unsure about the best way to fully separate my Dojo layers

Hey so I'm finding the documentation around building dojo a little hazy around layers.
For my Dojo 1.7+ application I would like a layer that contains only Dojo, and a layer that only contains my code, so I can place the appropriate copyright/license headers at the top.
Looking at build profile template, I see:
layers : {
"dojo/dojo":{
include:["dojo/dojo","dojo/i18n","dojo/ready","dojo/domReady"]
},
"myapp/core":{
include:["myapp/core/module1","myapp/core/module2","myapp/core/module3"],
exclude:["dojo/dojo"]
}
}
But when I look inside my 'myapp/core' layer js file I see lots of occurrences of
'define("dojo*'.
I started tackling this by finding each occurrence of the dojo define and putting that in the dojo/dojo layer include list, but that doesn't seem like the appropriate way of doing layers, is it? At the very least can't I just include certain packages? Am I making a big misunderstanding here?
Bonus it seems like the layer property 'copyrightFile' no longer works. Has that been deprecated, or changed?
Thanks
Are all these ("dojo/i18n","dojo/ready","dojo/domReady") dependencies the only dependencies that your external modules need? If myapp/core/module2 requires a dojo module that is not included in the dojo core layer, then it will be included in the myapp/core layer.
I have gone down the path you are going found it difficult to maintain the separation of code over time. I would create a single layer with both dojo and your code.
Use a layer to encapsulate code that is for specific area of functionality. For example, I have a graphical workflow editor that has it's own layer because it includes a bunch of svg code that doesn't need to be present in the rest of the application.