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

GeoJSON Parsing Verbesserungen #586

Merged
merged 4 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions bridging/android/jni/map/layers/tiled/NativeGeoJsonPoint.cpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions bridging/android/jni/map/layers/tiled/NativeGeoJsonPoint.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bridging/ios/MCGeoJsonFeatureParserInterface+Private.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bridging/ios/MCGeoJsonFeatureParserInterface.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions bridging/ios/MCGeoJsonPoint+Private.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions bridging/ios/MCGeoJsonPoint+Private.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions bridging/ios/MCGeoJsonPoint.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions bridging/ios/MCGeoJsonPoint.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion djinni/map/layers/tiled/geo_json_parser.djinni
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

@extern "../../../yaml/vector_layer_feature_info.yaml"
@extern "../../../yaml/coord.yaml"

geo_json_feature_parser_interface = interface +c {
static create() : geo_json_feature_parser_interface;
parse(geo_json: string): optional<list<vector_layer_feature_info>>;

parseWithPointGeometry(geo_json: string): optional<list<geo_json_point>>;
}

geo_json_point = record {
point: coord;
feature_info: vector_layer_feature_info;
}
39 changes: 39 additions & 0 deletions djinni/yaml/geo_json_point.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions ios/graphics/Texture/TextureHolder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ public class TextureHolder: NSObject {
let texture = try MetalContext.current.textureLoader.newTexture(data: data, options: options)
self.init(texture, textureUsableSize: textureUsableSize)
}

public convenience init(_ size: CGSize, drawCallback: ((CGContext) -> Void)) throws {
guard size.width > 0, size.height > 0 else {
throw TextureHolderError.emptyData
}

let width : Int = Int(size.width)
let height : Int = Int(size.height)

let bytesPerPixel = 4
let bytesPerRow = bytesPerPixel * width

let td = MTLTextureDescriptor.texture2DDescriptor(pixelFormat: .rgba8Unorm, width: width, height: height, mipmapped: false)
td.usage = .shaderRead

guard let texture = MetalContext.current.device.makeTexture(descriptor: td) else {
throw TextureHolderError.emptyData
}

let length = 4 * width * height
guard let imageData = calloc(width * height, 4) else {
throw TextureHolderError.emptyData
}

let data = NSMutableData(bytesNoCopy: imageData, length: length, freeWhenDone: true)

let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(rawValue: CGBitmapInfo.byteOrder32Big.rawValue | CGImageAlphaInfo.premultipliedLast.rawValue)

guard let context = CGContext(data: data.mutableBytes, width: width, height: height, bitsPerComponent: 8, bytesPerRow: 4 * width, space: colorSpace, bitmapInfo: bitmapInfo.rawValue) else {
throw TextureHolderError.emptyData
}

context.translateBy(x: 0, y: size.height)
context.scaleBy(x: 1.0, y: -1.0)

UIGraphicsPushContext(context)
drawCallback(context)
UIGraphicsPopContext()

let region = MTLRegionMake2D(0, 0, width, height)
texture.replace(region: region, mipmapLevel: 0, withBytes: data.bytes, bytesPerRow: bytesPerRow)

self.init(texture, textureUsableSize: nil)
}
}

extension TextureHolder: MCTextureHolderInterface {
Expand Down
2 changes: 2 additions & 0 deletions shared/public/GeoJsonFeatureParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ class GeoJsonFeatureParser: public GeoJsonFeatureParserInterface {
GeoJsonFeatureParser();

std::optional<std::vector<::VectorLayerFeatureInfo>> parse(const std::string & geoJson) override;

std::optional<std::vector<GeoJsonPoint>> parseWithPointGeometry(const std::string & geoJson) override;
};
4 changes: 4 additions & 0 deletions shared/public/GeoJsonFeatureParserInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
#include <string>
#include <vector>

struct GeoJsonPoint;

class GeoJsonFeatureParserInterface {
public:
virtual ~GeoJsonFeatureParserInterface() = default;

static /*not-null*/ std::shared_ptr<GeoJsonFeatureParserInterface> create();

virtual std::optional<std::vector<::VectorLayerFeatureInfo>> parse(const std::string & geoJson) = 0;

virtual std::optional<std::vector<GeoJsonPoint>> parseWithPointGeometry(const std::string & geoJson) = 0;
};
Loading
Loading