Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fill-extrusion support #1095

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@

package com.mapbox.mapboxgl;

import static com.mapbox.mapboxgl.Convert.toMap;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.mapbox.mapboxsdk.style.expressions.Expression;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.google.gson.JsonPrimitive;


import static com.mapbox.mapboxgl.Convert.toMap;

class LayerPropertyConverter {
static PropertyValue[] interpretSymbolLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
Expand Down Expand Up @@ -103,9 +107,9 @@ static PropertyValue[] interpretSymbolLayerProperties(Object o) {
properties.add(PropertyFactory.iconTextFitPadding(expression));
break;
case "icon-image":
if (jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()) {
if(jsonElement.isJsonPrimitive() && jsonElement.getAsJsonPrimitive().isString()){
properties.add(PropertyFactory.iconImage(jsonElement.getAsString()));
} else {
}else{
properties.add(PropertyFactory.iconImage(expression));
}
break;
Expand Down Expand Up @@ -372,6 +376,50 @@ static PropertyValue[] interpretFillLayerProperties(Object o) {
return properties.toArray(new PropertyValue[properties.size()]);
}

static PropertyValue[] interpretFillExtrusionLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
final List<PropertyValue> properties = new LinkedList();
final JsonParser parser = new JsonParser();

for (Map.Entry<String, String> entry : data.entrySet()) {
final JsonElement jsonElement = parser.parse(entry.getValue());
Expression expression = Expression.Converter.convert(jsonElement);
switch (entry.getKey()) {
case "fill-extrusion-opacity":
properties.add(PropertyFactory.fillExtrusionOpacity(expression));
break;
case "fill-extrusion-color":
properties.add(PropertyFactory.fillExtrusionColor(expression));
break;
case "fill-extrusion-translate":
properties.add(PropertyFactory.fillExtrusionTranslate(expression));
break;
case "fill-extrusion-translate-anchor":
properties.add(PropertyFactory.fillExtrusionTranslateAnchor(expression));
break;
case "fill-extrusion-pattern":
properties.add(PropertyFactory.fillExtrusionPattern(expression));
break;
case "fill-extrusion-height":
properties.add(PropertyFactory.fillExtrusionHeight(expression));
break;
case "fill-extrusion-base":
properties.add(PropertyFactory.fillExtrusionBase(expression));
break;
case "fill-extrusion-vertical-gradient":
properties.add(PropertyFactory.fillExtrusionVerticalGradient(expression));
break;
case "visibility":
properties.add(PropertyFactory.visibility(entry.getValue()));
break;
default:
break;
}
}

return properties.toArray(new PropertyValue[properties.size()]);
}

static PropertyValue[] interpretRasterLayerProperties(Object o) {
final Map<String, String> data = (Map<String, String>) toMap(o);
final List<PropertyValue> properties = new LinkedList();
Expand Down Expand Up @@ -453,4 +501,5 @@ static PropertyValue[] interpretHillshadeLayerProperties(Object o) {

return properties.toArray(new PropertyValue[properties.size()]);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,39 @@ private void addFillLayer(
interactiveFeatureLayerIds.add(layerName);
}
}

private void addFillExtrusionLayer(
String layerName,
String sourceName,
String belowLayerId,
String sourceLayer,
Float minZoom,
Float maxZoom,
PropertyValue[] properties,
boolean enableInteraction,
Expression filter) {
FillExtrusionLayer fillLayer = new FillExtrusionLayer(layerName, sourceName);
fillLayer.setProperties(properties);
if (sourceLayer != null) {
fillLayer.setSourceLayer(sourceLayer);
}
if (minZoom != null) {
fillLayer.setMinZoom(minZoom);
}
if (maxZoom != null) {
fillLayer.setMaxZoom(maxZoom);
}
if (filter != null) {
fillLayer.setFilter(filter);
}
if (belowLayerId != null) {
style.addLayerBelow(fillLayer, belowLayerId);
} else {
style.addLayer(fillLayer);
}
if (enableInteraction) {
interactiveFeatureLayerIds.add(layerName);
}
}
private void addCircleLayer(
String layerName,
String sourceName,
Expand Down Expand Up @@ -921,6 +953,36 @@ public void onError(@NonNull String message) {
filterExpression);
updateLocationComponentLayer();

result.success(null);
break;
}
case "fillExtrusionLayer#add":
{
final String sourceId = call.argument("sourceId");
final String layerId = call.argument("layerId");
final String belowLayerId = call.argument("belowLayerId");
final String sourceLayer = call.argument("sourceLayer");
final Double minzoom = call.argument("minzoom");
final Double maxzoom = call.argument("maxzoom");
final String filter = call.argument("filter");
final boolean enableInteraction = call.argument("enableInteraction");
final PropertyValue[] properties =
LayerPropertyConverter.interpretFillExtrusionLayerProperties(call.argument("properties"));

Expression filterExpression = parseFilter(filter);

addFillExtrusionLayer(
layerId,
sourceId,
belowLayerId,
sourceLayer,
minzoom != null ? minzoom.floatValue() : null,
maxzoom != null ? maxzoom.floatValue() : null,
properties,
enableInteraction,
filterExpression);
updateLocationComponentLayer();

result.success(null);
break;
}
Expand Down
22 changes: 7 additions & 15 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
TargetAttributes = {
97C146ED1CF9000F007C117D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = LC5K78Z623;
};
};
};
Expand Down Expand Up @@ -374,17 +375,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = LC5K78Z623;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand Down Expand Up @@ -505,17 +503,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = LC5K78Z623;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand All @@ -532,17 +527,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = LC5K78Z623;
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand Down
16 changes: 8 additions & 8 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import UIKit
import Flutter
import UIKit

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
6 changes: 3 additions & 3 deletions example/macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import FlutterMacOS

@NSApplicationMain
class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}
override func applicationShouldTerminateAfterLastWindowClosed(_: NSApplication) -> Bool {
return true
}
}
16 changes: 8 additions & 8 deletions example/macos/Runner/MainFlutterWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Cocoa
import FlutterMacOS

class MainFlutterWindow: NSWindow {
override func awakeFromNib() {
let flutterViewController = FlutterViewController.init()
let windowFrame = self.frame
self.contentViewController = flutterViewController
self.setFrame(windowFrame, display: true)
override func awakeFromNib() {
let flutterViewController = FlutterViewController()
let windowFrame = frame
contentViewController = flutterViewController
setFrame(windowFrame, display: true)

RegisterGeneratedPlugins(registry: flutterViewController)
RegisterGeneratedPlugins(registry: flutterViewController)

super.awakeFromNib()
}
super.awakeFromNib()
}
}
Loading