Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea689 committed Feb 11, 2020
1 parent 1f960cc commit 639fc1d
Show file tree
Hide file tree
Showing 63 changed files with 4,652 additions and 1,179 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Mapbox-gl wrapper for Dart

Library to use Mapbox GL JS from Dart. Working examples here: https://andrea689.github.io/mapbox-gl-dart/

## Using this package

You must include [Mapbox GL JS](https://github.com/mapbox/mapbox-gl-js) into your `.html` file
Expand Down
10 changes: 3 additions & 7 deletions example/data_driven_circle_colors/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'dart:js';

import 'package:js/js.dart';
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart';

void main() {
Expand All @@ -16,7 +13,7 @@ void main() {
),
);

map.on('load', allowInterop((_) {
map.on('load', (_) {
/* Sample feature from the `examples.8fgz4egr` tileset:
{
"type": "Feature",
Expand Down Expand Up @@ -61,7 +58,6 @@ void main() {
],
),
);

map.addLayer(layer.toJs());
}));
map.addLayer(layer);
});
}
3 changes: 1 addition & 2 deletions example/drag_a_marker/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:html';

import 'package:js/js.dart';
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart';

Marker marker;
Expand All @@ -26,7 +25,7 @@ void main() {
),
).setLngLat(LngLat(0, 0)).addTo(map);

marker.on('dragend', allowInterop(onDragEnd));
marker.on('dragend', onDragEnd);
}

void onDragEnd(_) {
Expand Down
21 changes: 10 additions & 11 deletions example/popup_on_click/index.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:js/js.dart';
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart';

void main() {
Expand All @@ -14,7 +13,7 @@ void main() {
),
);

map.on('load', allowInterop((_) {
map.on('load', (_) {
// Add a layer showing the places.
var layer = SymbolLayer(
id: 'places',
Expand Down Expand Up @@ -128,27 +127,27 @@ void main() {
iconAllowOverlap: true,
),
);
map.addLayer(layer.toJs());
map.addLayer(layer);

// When a click event occurs on a feature in the places layer, open a popup at the
// location of the feature, with description HTML from its properties.
map.on('click', 'places', allowInterop((e) {
map.on('click', 'places', (e) {
var coordinates = e.features[0].geometry.coordinates;
var description = e.features[0].properties.description;
var description = e.features[0].properties['description'];
Popup()
.setLngLat(LngLat(coordinates[0], coordinates[1]))
.setHTML(description)
.addTo(map);
}));
});

// Change the cursor to a pointer when the mouse is over the places layer.
map.on('mouseenter', 'places', allowInterop((_) {
map.on('mouseenter', 'places', (_) {
map.getCanvas().style.cursor = 'pointer';
}));
});

// Change it back to a pointer when it leaves.
map.on('mouseleave', 'places', allowInterop((_) {
map.on('mouseleave', 'places', (_) {
map.getCanvas().style.cursor = '';
}));
}));
});
});
}
5 changes: 5 additions & 0 deletions example/popup_on_click/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
text-align: center;
font-style: italic;
}

.mapboxgl-popup {
max-width: 400px;
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
</style>
</head>

Expand Down
253 changes: 130 additions & 123 deletions example/popup_on_hover/index.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import 'dart:js';

import 'package:js/js.dart';
import 'package:mapbox_gl_dart/mapbox_gl_dart.dart';

void main() {
Expand All @@ -16,121 +13,131 @@ void main() {
),
);

map.on('load', allowInterop((_) {
map.on('load', (_) {
map.addSource('places', {
'type': 'geojson',
'data': {
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'properties': {
'description':
'<strong>Make it Mount Pleasant</strong><p>Make it Mount Pleasant is a handmade and vintage market and afternoon of live entertainment and kids activities. 12:00-6:00 p.m.</p>',
'icon': 'theatre'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.038659, 38.931567]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Mad Men Season Five Finale Watch Party</strong><p>Head to Lounge 201 (201 Massachusetts Avenue NE) Sunday for a Mad Men Season Five Finale Watch Party, complete with 60s costume contest, Mad Men trivia, and retro food and drink. 8:00-11:00 p.m. \$10 general admission, \$20 admission and two hour open bar.</p>',
'icon': 'theatre'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.003168, 38.894651]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Big Backyard Beach Bash and Wine Fest</strong><p>EatBar (2761 Washington Boulevard Arlington VA) is throwing a Big Backyard Beach Bash and Wine Fest on Saturday, serving up conch fritters, fish tacos and crab sliders, and Red Apron hot dogs. 12:00-3:00 p.m. \$25.grill hot dogs.</p>',
'icon': 'bar'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.090372, 38.881189]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Ballston Arts & Crafts Market</strong><p>The Ballston Arts & Crafts Market sets up shop next to the Ballston metro this Saturday for the first of five dates this summer. Nearly 35 artists and crafters will be on hand selling their wares. 10:00-4:00 p.m.</p>',
'icon': 'art-gallery'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.111561, 38.882342]
}
},
{
'type': 'Feature',
'properties': {
'description':
"<strong>Seersucker Bike Ride and Social</strong><p>Feeling dandy? Get fancy, grab your bike, and take part in this year's Seersucker Social bike ride from Dandies and Quaintrelles. After the ride enjoy a lawn party at Hillwood with jazz, cocktails, paper hat-making, and more. 11:00-7:00 p.m.</p>",
'icon': 'bicycle'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.052477, 38.943951]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Capital Pride Parade</strong><p>The annual Capital Pride Parade makes its way through Dupont this Saturday. 4:30 p.m. Free.</p>',
'icon': 'star'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.043444, 38.909664]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Muhsinah</strong><p>Jazz-influenced hip hop artist Muhsinah plays the Black Cat (1811 14th Street NW) tonight with Exit Clov and Gods’illa. 9:00 p.m. \$12.</p>',
'icon': 'music'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.031706, 38.914581]
}
},
{
'type': 'Feature',
'properties': {
'description':
"<strong>A Little Night Music</strong><p>The Arlington Players' production of Stephen Sondheim's <em>A Little Night Music</em> comes to the Kogod Cradle at The Mead Center for American Theater (1101 6th Street SW) this weekend and next. 8:00 p.m.</p>",
'icon': 'music'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.020945, 38.878241]
}
},
{
'type': 'Feature',
'properties': {
'description':
'<strong>Truckeroo</strong><p>Truckeroo brings dozens of food trucks, live music, and games to half and M Street SE (across from Navy Yard Metro Station) today from 11:00 a.m. to 11:00 p.m.</p>',
'icon': 'music'
},
'geometry': {
'type': 'Point',
'coordinates': [-77.007481, 38.876516]
}
}
]
}
});

// Add a layer showing the places.
var layer = SymbolLayer(
id: 'places',
source: GeoJsonSource(
data: FeatureCollection(
features: [
Feature(
properties: {
'description':
'<strong>Make it Mount Pleasant</strong><p><a href="http://www.mtpleasantdc.com/makeitmtpleasant" target="_blank" title="Opens in a new window">Make it Mount Pleasant</a> is a handmade and vintage market and afternoon of live entertainment and kids activities. 12:00-6:00 p.m.</p>',
'icon': 'theatre',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.038659, 38.931567],
),
),
Feature(
properties: {
'description':
'<strong>Mad Men Season Five Finale Watch Party</strong><p>Head to Lounge 201 (201 Massachusetts Avenue NE) Sunday for a <a href="http://madmens5finale.eventbrite.com/" target="_blank" title="Opens in a new window">Mad Men Season Five Finale Watch Party</a>, complete with 60s costume contest, Mad Men trivia, and retro food and drink. 8:00-11:00 p.m. \$10 general admission, \$20 admission and two hour open bar.</p>',
'icon': 'theatre',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.003168, 38.894651],
),
),
Feature(
properties: {
'description':
'<strong>Big Backyard Beach Bash and Wine Fest</strong><p>EatBar (2761 Washington Boulevard Arlington VA) is throwing a <a href="http://tallulaeatbar.ticketleap.com/2012beachblanket/" target="_blank" title="Opens in a new window">Big Backyard Beach Bash and Wine Fest</a> on Saturday, serving up conch fritters, fish tacos and crab sliders, and Red Apron hot dogs. 12:00-3:00 p.m. \$25.grill hot dogs.</p>',
'icon': 'bar',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.090372, 38.881189],
),
),
Feature(
properties: {
'description':
'<strong>Ballston Arts & Crafts Market</strong><p>The <a href="http://ballstonarts-craftsmarket.blogspot.com/" target="_blank" title="Opens in a new window">Ballston Arts & Crafts Market</a> sets up shop next to the Ballston metro this Saturday for the first of five dates this summer. Nearly 35 artists and crafters will be on hand selling their wares. 10:00-4:00 p.m.</p>',
'icon': 'art-gallery',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.111561, 38.882342],
),
),
Feature(
properties: {
'description':
'<strong>Seersucker Bike Ride and Social</strong><p>Feeling dandy? Get fancy, grab your bike, and take part in this year\'s <a href="http://dandiesandquaintrelles.com/2012/04/the-seersucker-social-is-set-for-june-9th-save-the-date-and-start-planning-your-look/" target="_blank" title="Opens in a new window">Seersucker Social</a> bike ride from Dandies and Quaintrelles. After the ride enjoy a lawn party at Hillwood with jazz, cocktails, paper hat-making, and more. 11:00-7:00 p.m.</p>',
'icon': 'bicycle',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.052477, 38.943951],
),
),
Feature(
properties: {
'description':
'<strong>Capital Pride Parade</strong><p>The annual <a href="http://www.capitalpride.org/parade" target="_blank" title="Opens in a new window">Capital Pride Parade</a> makes its way through Dupont this Saturday. 4:30 p.m. Free.</p>',
'icon': 'rocket',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.043444, 38.909664],
),
),
Feature(
properties: {
'description':
'<strong>Muhsinah</strong><p>Jazz-influenced hip hop artist <a href="http://www.muhsinah.com" target="_blank" title="Opens in a new window">Muhsinah</a> plays the <a href="http://www.blackcatdc.com">Black Cat</a> (1811 14th Street NW) tonight with <a href="http://www.exitclov.com" target="_blank" title="Opens in a new window">Exit Clov</a> and <a href="http://godsilla.bandcamp.com" target="_blank" title="Opens in a new window">Gods’illa</a>. 9:00 p.m. \$12.</p>',
'icon': 'music',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.031706, 38.914581],
),
),
Feature(
properties: {
'description':
'<strong>A Little Night Music</strong><p>The Arlington Players\' production of Stephen Sondheim\'s <a href="http://www.thearlingtonplayers.org/drupal-6.20/node/4661/show" target="_blank" title="Opens in a new window"><em>A Little Night Music</em></a> comes to the Kogod Cradle at The Mead Center for American Theater (1101 6th Street SW) this weekend and next. 8:00 p.m.</p>',
'icon': 'music',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.020945, 38.878241],
),
),
Feature(
properties: {
'description':
'<strong>Truckeroo</strong><p><a href="http://www.truckeroodc.com/www/" target="_blank">Truckeroo</a> brings dozens of food trucks, live music, and games to half and M Street SE (across from Navy Yard Metro Station) today from 11:00 a.m. to 11:00 p.m.</p>',
'icon': 'music',
},
geometry: Geometry(
type: 'Point',
coordinates: [-77.007481, 38.876516],
),
)
],
),
),
layout: SymbolLayout(
iconImage: '{icon}-15',
iconAllowOverlap: true,
),
);
map.addLayer(layer.toJs());
map.addLayer({
'id': 'places',
'type': 'symbol',
'source': 'places',
'layout': {'icon-image': '{icon}-15', 'icon-allow-overlap': true}
});

// Create a popup, but don't add it to the map yet.
var popup = Popup(
Expand All @@ -139,12 +146,12 @@ void main() {
closeOnClick: false,
),
);
map.on('mouseenter', 'places', allowInterop((e) {
map.on('mouseenter', 'places', (e) {
// Change the cursor style as a UI indicator.
map.getCanvas().style.cursor = 'pointer';

var coordinates = e.features[0].geometry.coordinates;
var description = e.features[0].properties.description;
var description = e.features[0].properties['description'];

// Ensure that if the map is zoomed out such that multiple
// copies of the feature are visible, the popup appears
Expand All @@ -159,11 +166,11 @@ void main() {
.setLngLat(LngLat(coordinates[0], coordinates[1]))
.setHTML(description)
.addTo(map);
}));
});

map.on('mouseleave', 'places', allowInterop((_) {
map.on('mouseleave', 'places', (_) {
map.getCanvas().style.cursor = '';
popup.remove();
}));
}));
});
});
}
Loading

0 comments on commit 639fc1d

Please sign in to comment.