Skip to content

Commit

Permalink
syntax improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanvds committed Jul 17, 2016
1 parent c39a170 commit b4701e4
Show file tree
Hide file tree
Showing 28 changed files with 158 additions and 153 deletions.
56 changes: 28 additions & 28 deletions example/CreateClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
#include "wtMapbox.h"

CreateClusters::CreateClusters() {
source.setFromURL("http://127.0.0.1:8080/earthquakes.geojson");
source.setCluster(50, 14);
source.set("http://127.0.0.1:8080/earthquakes.geojson");
source.cluster(50, 14);

unclusteredLayer.setSource(&source);
unclusteredLayer.set(&source);
unclusteredLayer.icon.image("'marker-15'");

clusterLayer[0].setSource(&source);
clusterLayer[0].set(&source);
clusterLayer[0].color(Wt::WColor("#f28cb1")).radius(18);
clusterLayer[0].setFilter("['>=', 'point_count', 150]");
clusterLayer[0].filter("['>=', 'point_count', 150]");

clusterLayer[1].setSource(&source);
clusterLayer[1].set(&source);
clusterLayer[1].color(Wt::WColor("#f1f075")).radius(18);
clusterLayer[1].setFilter("['all', ['>=', 'point_count', 20], ['<', 'point_count', 150]]");
clusterLayer[1].filter("['all', ['>=', 'point_count', 20], ['<', 'point_count', 150]]");

clusterLayer[2].setSource(&source);
clusterLayer[2].set(&source);
clusterLayer[2].color(Wt::WColor("#51bbd6")).radius(18);
clusterLayer[2].setFilter("['all', ['>=', 'point_count', 0], ['<', 'point_count', 20]]");
clusterLayer[2].filter("['all', ['>=', 'point_count', 0], ['<', 'point_count', 20]]");

clusterCountLayer.setSource(&source);
clusterCountLayer.set(&source);
clusterCountLayer.text.label("'{point_count}'").size(12);
clusterCountLayer.text.font("[\"DIN Offc Pro Medium\", \"Arial Unicode MS Bold\"]");

Expand All @@ -31,7 +31,7 @@ CreateClusters::CreateClusters() {
unclusteredCheck->setInline(false);
unclusteredCheck->setChecked();
unclusteredCheck->changed().connect(std::bind([=]() {
unclusteredLayer.setVisible(unclusteredCheck->isChecked());
unclusteredLayer.visible(unclusteredCheck->isChecked());
}));

clusterCheck[0] = new Wt::WCheckBox("Show Red Dots", this);
Expand All @@ -43,7 +43,7 @@ CreateClusters::CreateClusters() {
clusterCheck[i]->setChecked();
clusterCheck[i]->setInline(false);
clusterCheck[i]->changed().connect(std::bind([=]() {
clusterLayer[i].setVisible(clusterCheck[i]->isChecked());
clusterLayer[i].visible(clusterCheck[i]->isChecked());
}));
}

Expand All @@ -52,39 +52,39 @@ CreateClusters::CreateClusters() {
clusterCountCheck->setChecked();
clusterCountCheck->setInline(false);
clusterCountCheck->changed().connect(std::bind([=]() {
clusterCountLayer.setVisible(clusterCountCheck->isChecked());
clusterCountLayer.visible(clusterCountCheck->isChecked());
}));
}

void CreateClusters::onShow() {
// reset stuff
unclusteredLayer.setVisible(true);
unclusteredLayer.visible(true);
unclusteredCheck->setChecked();
clusterCountLayer.setVisible(true);
clusterCountLayer.visible(true);
clusterCountCheck->setChecked();

for (int i = 0; i < 3; i++) {
clusterLayer[i].setVisible(true);
clusterLayer[i].visible(true);
clusterCheck[i]->setChecked();
}

// change style and add layers
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Dark, true);
APP->getMap()->addSource(&source);
APP->getMap()->addLayer(&unclusteredLayer);
APP->getMap()->addLayer(&clusterLayer[0]);
APP->getMap()->addLayer(&clusterLayer[1]);
APP->getMap()->addLayer(&clusterLayer[2]);
APP->getMap()->addLayer(&clusterCountLayer);
APP->getMap()->add(&source);
APP->getMap()->add(&unclusteredLayer);
APP->getMap()->add(&clusterLayer[0]);
APP->getMap()->add(&clusterLayer[1]);
APP->getMap()->add(&clusterLayer[2]);
APP->getMap()->add(&clusterCountLayer);
APP->getMap()->easeTo(MapBox::Coordinate(38.620655, -118.411719), 3, 1000);
APP->getMap()->applyMapStyle();
}

void CreateClusters::onHide() {
APP->getMap()->removeSource(&source);
APP->getMap()->removeLayer(&unclusteredLayer);
APP->getMap()->removeLayer(&clusterLayer[0]);
APP->getMap()->removeLayer(&clusterLayer[1]);
APP->getMap()->removeLayer(&clusterLayer[2]);
APP->getMap()->removeLayer(&clusterCountLayer);
APP->getMap()->rem(&source);
APP->getMap()->rem(&unclusteredLayer);
APP->getMap()->rem(&clusterLayer[0]);
APP->getMap()->rem(&clusterLayer[1]);
APP->getMap()->rem(&clusterLayer[2]);
APP->getMap()->rem(&clusterCountLayer);
}
12 changes: 6 additions & 6 deletions example/FeatureOnClick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

FeatureOnClick::FeatureOnClick()
{
source.setFromURL("https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_admin_1_states_provinces_shp.geojson");
layer.setSource(&source);
source.set("https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_110m_admin_1_states_provinces_shp.geojson");
layer.set(&source);
layer.color(Wt::WColor(200, 100, 240));
layer.outlineColor(Wt::WColor(0, 255, 0));
layer.opacity(0.5);
Expand All @@ -32,7 +32,7 @@ void FeatureOnClick::onShow()
coordinate = e;
}, std::placeholders::_1));

APP->getMap()->addSource(&source).addLayer(&layer);
APP->getMap()->add(&source).add(&layer);
APP->getMap()->center(MapBox::Coordinate(38.907, -100.04)).zoom(3);

// signale to collect feature
Expand All @@ -52,16 +52,16 @@ void FeatureOnClick::onShow()
APP->getMap()->enableClickedFeature(true);

// add mousemove handler to change cursor on features
APP->getMap()->addJSHandler(mouseMove);
APP->getMap()->add(mouseMove);

APP->getMap()->applyMapStyle();
}

void FeatureOnClick::onHide()
{
APP->getMap()->clicked().disconnect(connection);
APP->getMap()->removeLayer(&layer).removeSource(&source);
APP->getMap()->rem(&layer).rem(&source);
APP->getMap()->enableClickedFeature(false);
APP->getMap()->remJSHandler(mouseMove);
APP->getMap()->rem(mouseMove);
popup->remove();
}
4 changes: 2 additions & 2 deletions example/FeaturesBelowMouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ void FeaturesBelowMouse::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Streets, true);
APP->getMap()->center(MapBox::Coordinate(50.883198, 4.712435)).zoom(3);
APP->getMap()->addJSHandler(mouseMove);
APP->getMap()->add(mouseMove);
APP->getMap()->applyMapStyle();
}

void FeaturesBelowMouse::onHide()
{
APP->getMap()->remJSHandler(mouseMove);
APP->getMap()->rem(mouseMove);
}
8 changes: 4 additions & 4 deletions example/GeoJSONLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ GeoJSONLine::GeoJSONLine()
.add(MapBox::Coordinate(37.833378258, -122.4922370))
.add(MapBox::Coordinate(37.833683307, -122.4937820));

source.sourceData(&line);
layer.setSource(&source);
source.set(&line);
layer.set(&source);
layer.join(MapBox::JOIN::Round);
layer.cap(MapBox::CAP::Round);
layer.color(Wt::WColor("#888"));
Expand All @@ -37,13 +37,13 @@ GeoJSONLine::GeoJSONLine()
void GeoJSONLine::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Streets, true);
APP->getMap()->addSource(&source).addLayer(&layer);
APP->getMap()->add(&source).add(&layer);
APP->getMap()->center(MapBox::Coordinate(37.830348, -122.486052)).zoom(15);
APP->getMap()->applyMapStyle();

}

void GeoJSONLine::onHide()
{
APP->getMap()->removeLayer(&layer).removeSource(&source);
APP->getMap()->rem(&layer).rem(&source);
}
8 changes: 4 additions & 4 deletions example/GeoJSONPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ GeoJSONPoint::GeoJSONPoint()
featureCollection.add(feature1);
featureCollection.add(feature2);

source.sourceData(&featureCollection);
source.set(&featureCollection);

layer.setSource(&source);
layer.set(&source);
layer.icon.image("{icon}-15").size(2);
layer.text.label("{title}")
.font("['Open Sans Semibold', 'Arial Unicode MS Bold']")
Expand All @@ -42,12 +42,12 @@ GeoJSONPoint::GeoJSONPoint()
void GeoJSONPoint::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Light, true);
APP->getMap()->addSource(&source).addLayer(&layer);
APP->getMap()->add(&source).add(&layer);
APP->getMap()->center(MapBox::Coordinate(37.8, -96)).zoom(3);
APP->getMap()->applyMapStyle();
}

void GeoJSONPoint::onHide()
{
APP->getMap()->removeLayer(&layer).removeSource(&source);
APP->getMap()->rem(&layer).rem(&source);
}
10 changes: 5 additions & 5 deletions example/GeoJSONPoly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ GeoJSONPoly::GeoJSONPoly()
feature.geometry(poly);
feature.properties(properties);

source.sourceData(&feature);
source.set(&feature);

layer.setSource(&source);
layer.set(&source);
layer.color(Wt::WColor("#088"));
layer.opacity(0.8);
layer.setSourceLayer("Maine");
layer.sourceLayer("Maine");
}

void GeoJSONPoly::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Streets, true);
APP->getMap()->addSource(&source).addLayer(&layer);
APP->getMap()->add(&source).add(&layer);
APP->getMap()->center(MapBox::Coordinate(45.1374518906, -68.13734351)).zoom(5);
APP->getMap()->applyMapStyle();
}

void GeoJSONPoly::onHide()
{
APP->getMap()->removeLayer(&layer).removeSource(&source);
APP->getMap()->rem(&layer).rem(&source);
}
40 changes: 20 additions & 20 deletions example/Heatmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@

Heatmap::Heatmap()
{
source.setFromURL("http://127.0.0.1:8080/earthquakes.geojson");
source.setCluster(20, 15);
source.set("http://127.0.0.1:8080/earthquakes.geojson");
source.cluster(20, 15);


layer[0].setSource(&source);
layer[0].set(&source);
layer[0].color(Wt::WColor("green"));
layer[0].radius(70).blur(1);
layer[0].setFilter("['all', ['>=', 'point_count', 0], ['<', 'point_count', 20]]");
layer[0].filter("['all', ['>=', 'point_count', 0], ['<', 'point_count', 20]]");

layer[1].setSource(&source);
layer[1].set(&source);
layer[1].color(Wt::WColor("orange"));
layer[1].radius(70).blur(1);
layer[1].setFilter("['all', ['>=', 'point_count', 20], ['<', 'point_count', 200]]");
layer[1].filter("['all', ['>=', 'point_count', 20], ['<', 'point_count', 200]]");

layer[2].setSource(&source);
layer[2].set(&source);
layer[2].color(Wt::WColor("red"));
layer[2].radius(70).blur(1);
layer[2].setFilter("['>=', 'point_count', 200]");
layer[2].filter("['>=', 'point_count', 200]");

layer[3].setSource(&source);
layer[3].set(&source);
layer[3].color(Wt::WColor(0, 255, 0, 125));
layer[3].radius(20).blur(1);
layer[3].setFilter("['!=', 'cluster', true]");
layer[3].filter("['!=', 'cluster', true]");

new Wt::WText("Opacity: ", this);
Wt::WSlider * slider = new Wt::WSlider(this);
Expand All @@ -46,20 +46,20 @@ Heatmap::Heatmap()
void Heatmap::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Dark, true);
APP->getMap()->addSource(&source);
APP->getMap()->addLayer(&layer[0]);
APP->getMap()->addLayer(&layer[1]);
APP->getMap()->addLayer(&layer[2]);
APP->getMap()->addLayer(&layer[3]);
APP->getMap()->add(&source);
APP->getMap()->add(&layer[0]);
APP->getMap()->add(&layer[1]);
APP->getMap()->add(&layer[2]);
APP->getMap()->add(&layer[3]);
APP->getMap()->easeTo(MapBox::Coordinate(18.609917, -72.324234), 3, 1000);
APP->getMap()->applyMapStyle();
}

void Heatmap::onHide()
{
APP->getMap()->removeSource(&source);
APP->getMap()->removeLayer(&layer[0]);
APP->getMap()->removeLayer(&layer[1]);
APP->getMap()->removeLayer(&layer[2]);
APP->getMap()->removeLayer(&layer[3]);
APP->getMap()->rem(&source);
APP->getMap()->rem(&layer[0]);
APP->getMap()->rem(&layer[1]);
APP->getMap()->rem(&layer[2]);
APP->getMap()->rem(&layer[3]);
}
28 changes: 14 additions & 14 deletions example/HeightLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

HeightLines::HeightLines()
{
museums.setFromURL("mapbox://mapbox.2opop9hr");
contours.setFromURL("mapbox://mapbox.mapbox-terrain-v2");
museums.set("mapbox://mapbox.2opop9hr");
contours.set("mapbox://mapbox.mapbox-terrain-v2");

museumLayer.setSource(&museums);
museumLayer.setSourceLayer("museum-cusco");
museumLayer.set(&museums);
museumLayer.sourceLayer("museum-cusco");
museumLayer.radius(8);
museumLayer.color(Wt::WColor(55, 148, 179));

contourLayer.setSource(&contours);
contourLayer.setSourceLayer("contour");
contourLayer.set(&contours);
contourLayer.sourceLayer("contour");
contourLayer.join(MapBox::JOIN::Round);
contourLayer.cap(MapBox::CAP::Round);
contourLayer.color(Wt::WColor("#877b59"));
Expand Down Expand Up @@ -65,18 +65,18 @@ HeightLines::HeightLines()
void HeightLines::onShow()
{
APP->getMap()->setMapStyle(MapBox::MAPSTYLE::Streets, true);
APP->getMap()->addSource(&museums);
APP->getMap()->addSource(&contours);
APP->getMap()->addLayer(&museumLayer);
APP->getMap()->addLayer(&contourLayer);
APP->getMap()->add(&museums);
APP->getMap()->add(&contours);
APP->getMap()->add(&museumLayer);
APP->getMap()->add(&contourLayer);
APP->getMap()->easeTo(MapBox::Coordinate(-13.517379300798098 ,-71.97722138410576), 15, 1000);
APP->getMap()->applyMapStyle();
}

void HeightLines::onHide()
{
APP->getMap()->removeSource(&museums);
APP->getMap()->removeSource(&contours);
APP->getMap()->removeLayer(&museumLayer);
APP->getMap()->removeLayer(&contourLayer);
APP->getMap()->rem(&museums);
APP->getMap()->rem(&contours);
APP->getMap()->rem(&museumLayer);
APP->getMap()->rem(&contourLayer);
}
Loading

0 comments on commit b4701e4

Please sign in to comment.