From 1d57c2a442d1f517fe64bc116ca3680742d1f005 Mon Sep 17 00:00:00 2001 From: Margriet Groenendijk Date: Fri, 13 May 2022 21:21:07 +0100 Subject: [PATCH 1/2] extended mapbox api call --- pybabylonjs/babylonjs.py | 2 +- pybabylonjs/data.py | 31 ++++++++++++++++++++++++++----- src/widget.ts | 11 +++++++---- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/pybabylonjs/babylonjs.py b/pybabylonjs/babylonjs.py index 3c2ff0a..37f4fed 100644 --- a/pybabylonjs/babylonjs.py +++ b/pybabylonjs/babylonjs.py @@ -87,7 +87,7 @@ def set_defaults(validator, properties, instance, schema): "img_width": {"type": "number"}, "img_height": {"type": "number"}, }, - "required": ["xy_bbox", "img_width"], + "required": ["xy_bbox"], } diff --git a/pybabylonjs/data.py b/pybabylonjs/data.py index ba8868c..b2ef57a 100644 --- a/pybabylonjs/data.py +++ b/pybabylonjs/data.py @@ -84,9 +84,9 @@ def numpy_to_binary(arr): img = ((img - np.min(img)) / (np.max(img) - np.min(img))) * 255 binary_image = numpy_to_binary(img) - [img_height, img_width] = np.shape(img) + #[img_height, img_width] = np.shape(img) - return dict(data=binary_image, img_width=img_width, img_height=img_height) + return dict(data=binary_image) def create_mapbox_image(data: dict, **kwargs): @@ -101,13 +101,30 @@ def create_mapbox_image(data: dict, **kwargs): mbtoken = kwargs["mbtoken"] style_id = kwargs["mbstyle"] data_crs = kwargs["crs"] - + dst_crs = {"init": "EPSG:4326"} # lat/lon - + bbox = BoundingBox( data["X"].min(), data["Y"].min(), data["X"].max(), data["Y"].max() ) + dst_bbox = transform_bounds(data_crs, dst_crs, *bbox) + + print(bbox) + print(dst_bbox) + + w = bbox[2] - bbox[0] + h = bbox[3] - bbox[1] + + if w>h: + ww = 1280 + hh = int(h/w * 1280) + elif h>w: + hh = 1280 + ww = int(w/h * 1280) + + print(ww) + print(hh) f = requests.get( ( @@ -121,7 +138,11 @@ def create_mapbox_image(data: dict, **kwargs): + str(dst_bbox[2]) + "," + str(dst_bbox[3]) - + "]/1280x1280?access_token=" + + "]/" + + str(ww) + + "x" + + str(hh) + + "?access_token=" + mbtoken ) ) diff --git a/src/widget.ts b/src/widget.ts index 62f6d83..d6d1597 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -128,7 +128,6 @@ export class BabylonPointCloudView extends BabylonBaseView { const ymin = data.Y.reduce((accum: number, currentNumber: number) => Math.min(accum, currentNumber)); const ymax = data.Y.reduce((accum: number, currentNumber: number) => Math.max(accum, currentNumber)); - if (isClass) { var pcs = new PointsCloudSystem('pcs', pointSize, scene, { updatable: isClass @@ -405,8 +404,7 @@ export class BabylonImageView extends BabylonBaseView { protected async createScene(): Promise { return super.createScene().then( ( scene ) => { const data = this.values.data; - const img_height = this.values.img_height; - const img_width = this.values.img_width; + const bbox = this.values.xy_bbox; scene.createDefaultCameraOrLight(true, true, true); scene.clearColor = new Color4(0.95, 0.94, 0.92, 1); @@ -422,7 +420,12 @@ export class BabylonImageView extends BabylonBaseView { groundMaterial.specularColor = new Color3(0.5, 0.5, 0.5); groundMaterial.specularPower = 32; - const ground = MeshBuilder.CreateGround("ground", {height: img_height*0.005, width: img_width*0.005, subdivisions: 16}, scene); + const xmin = bbox[0]; + const xmax = bbox[1]; + const ymin = bbox[2]; + const ymax = bbox[3]; + + const ground = MeshBuilder.CreateGround("ground", {height: (xmax-xmin)*0.005, width: (ymax-ymin)*0.005, subdivisions: 36}, scene); ground.material = groundMaterial; let camera = scene.activeCamera as ArcRotateCamera; From e345c3949272e8781eae935dc79730c82b0bd59d Mon Sep 17 00:00:00 2001 From: Margriet Groenendijk Date: Mon, 16 May 2022 11:18:15 +0100 Subject: [PATCH 2/2] Update data.py --- pybabylonjs/data.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pybabylonjs/data.py b/pybabylonjs/data.py index b2ef57a..758d625 100644 --- a/pybabylonjs/data.py +++ b/pybabylonjs/data.py @@ -84,8 +84,6 @@ def numpy_to_binary(arr): img = ((img - np.min(img)) / (np.max(img) - np.min(img))) * 255 binary_image = numpy_to_binary(img) - #[img_height, img_width] = np.shape(img) - return dict(data=binary_image) @@ -101,27 +99,27 @@ def create_mapbox_image(data: dict, **kwargs): mbtoken = kwargs["mbtoken"] style_id = kwargs["mbstyle"] data_crs = kwargs["crs"] - + dst_crs = {"init": "EPSG:4326"} # lat/lon - + bbox = BoundingBox( data["X"].min(), data["Y"].min(), data["X"].max(), data["Y"].max() ) - + dst_bbox = transform_bounds(data_crs, dst_crs, *bbox) - + print(bbox) print(dst_bbox) w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] - if w>h: + if w > h: ww = 1280 - hh = int(h/w * 1280) - elif h>w: + hh = int(h / w * 1280) + elif h > w: hh = 1280 - ww = int(w/h * 1280) + ww = int(w / h * 1280) print(ww) print(hh)