diff --git a/README.md b/README.md index 1ecfc83..7778612 100644 --- a/README.md +++ b/README.md @@ -39,19 +39,72 @@ Example: [https://geo.speckle.systems/?speckleUrl=https://app.speckle.systems/pr List of possible issues you can experience and solutions to them: - Page or Map stays blank and Developer Tools Console shows "net::ERR_QUIC_PROTOCOL_ERROR 200 (OK)" + Solution: Try reloading the page. Otherwise, if in Google Chrome, navigate to chrome://flags/#enable-quic in and change Experimental QUIC Protocol dropdown to Disabled. - Model seems to be loaded incomplete + Solution: Check the message "feature count limited to ..." next to the Model name on the top of the page. If the message is present, try increasing the feature limit using "&limit=10000" URL parameter - Attribute table doesn't have original feature attributes and properties -Enable the URL parameter "&preserveAttributes=true". It is disabled by default due to the faulty display of the 3-dimentional multiPolygons overlapping themselves in 2d space, when viweving in the browser on 2d map. Enabling this parameter might make the multipolygons appear "transparent" due to self-overlap. -Report any other issues here or on our [Community Forum](https://speckle.community/invites/qxEmQb1QcM). +Solution: Enable the URL parameter "&preserveAttributes=true". It is disabled by default due to the faulty display of the 3-dimentional multiPolygons overlapping themselves in 2d space, when viweving in the browser on 2d map. Enabling this parameter might make the multipolygons appear "transparent" due to self-overlap. -### Add Speckle Feature Layer to a web-based map +Report any other issues here or on our [Community Forum](https://speckle.community/). -Check out the examples in 'speckle_demos' folder for Leaflet and OpenLayers implementation. +## Add Speckle Feature Layers to web-based maps and desktop apps + +### Add Speckle layer in Javascript + +Javascript-based mapping libraries can load speckle data as JSON using the following function: + +```javascript + async function loadSpeckleData() => { + var speckle_model_url = 'https://geo.speckle.systems/?speckleUrl=https://app.speckle.systems/projects/344f803f81/models/5582ab673e&datatype=polygons'; + const speckle_data = await fetch(speckle_model_url, { + headers: {'Accept': 'application/geo+json'} + }).then(response => response.json()); + } +``` + +Then you can add it to the base map (e.g. using Leaflet and OpenStreetMap basemap tiles). The following example assumes an html div element with id="items-map": + +```html + +``` + +Check out 'speckle_demos' folder for more Leaflet and OpenLayers implementation. ### Add Speckle WFS layer in QGIS 1. Add new WFS Layer diff --git a/pygeoapi/config.py b/pygeoapi/config.py index fd994dc..6e38b3f 100644 --- a/pygeoapi/config.py +++ b/pygeoapi/config.py @@ -88,13 +88,16 @@ def get_config(raw: bool = False, request: Request = None) -> dict: # make sure to restrict the usage for the key if ".speckle.systems" in request.url.split("?")[0] and map_api_key_speckle and len(map_api_key_speckle)>=20: CONFIG["server"]["map"]["url"] = r'https://api.maptiler.com/maps/dataviz/{z}/{x}/{y}.png' + f'?key={map_api_key_speckle}' + CONFIG["server"]["map"]["key"] = f'{map_api_key_speckle}' CONFIG["server"]["map"]["attribution"] = r'© MapTiler © OpenStreetMap contributors' elif map_api_key_local and len(map_api_key_local)>=20: CONFIG["server"]["map"]["url"] = r'https://api.maptiler.com/maps/dataviz/{z}/{x}/{y}.png' + f'?key={map_api_key_local}' + CONFIG["server"]["map"]["key"] = f'{map_api_key_local}' CONFIG["server"]["map"]["attribution"] = r'© MapTiler © OpenStreetMap contributors' else: CONFIG["server"]["map"]["url"] = r'https://tile.openstreetmap.org/{z}/{x}/{y}.png' + CONFIG["server"]["map"]["key"] = "" CONFIG["server"]["map"]["attribution"] = r'© OpenStreetMap contributors' diff --git a/pygeoapi/provider/speckle_utils/display_utils.py b/pygeoapi/provider/speckle_utils/display_utils.py index 890ae73..d0a37e6 100644 --- a/pygeoapi/provider/speckle_utils/display_utils.py +++ b/pygeoapi/provider/speckle_utils/display_utils.py @@ -51,10 +51,11 @@ def separate_display_vals(displayValue: List) -> List[Tuple["Base"]]: for i, item in enumerate(displayValue): if isinstance(item, Mesh): - count = 0 + all_count = len(item.faces) + for _ in item.faces: - try: + if count < all_count: faces = [] verts = [] colors = [] @@ -71,20 +72,16 @@ def separate_display_vals(displayValue: List) -> List[Tuple["Base"]]: new_vert = item.vertices[3*vert_index : 3*vert_index + 3] verts.extend(new_vert) - if isinstance(item.colors, List) and len(item.colors)>2: - + if isinstance(item.colors, List) and len(item.colors) > vert_index: color = item.colors[vert_index] colors.append(color) count += vert_num+1 - except IndexError: - continue - - if len(colors)>0: - mesh = Mesh.create(faces= faces, vertices=verts, colors=colors) - else: - mesh = Mesh.create(faces= faces, vertices=verts) - display_objs.append((mesh, item)) + if len(colors)>0: + mesh = Mesh.create(faces= faces, vertices=verts, colors=colors) + else: + mesh = Mesh.create(faces= faces, vertices=verts) + display_objs.append((mesh, item)) elif item is not None: display_objs.append((item, item)) @@ -225,6 +222,7 @@ def assign_color(obj_display, props) -> None: # initialize Speckle Blue color color = DEFAULT_COLOR + opacity = None try: # prioritize renderMaterials for Meshes & Brep @@ -232,8 +230,10 @@ def assign_color(obj_display, props) -> None: # print(obj_display.get_member_names()) if hasattr(obj_display, 'renderMaterial'): color = obj_display['renderMaterial']['diffuse'] + opacity = obj_display['renderMaterial']['opacity'] elif hasattr(obj_display, '@renderMaterial'): color = obj_display['@renderMaterial']['diffuse'] + opacity = obj_display['@renderMaterial']['opacity'] elif isinstance(obj_display, Mesh) and isinstance(obj_display.colors, List) and len(obj_display.colors)>1: sameColors = True @@ -256,26 +256,35 @@ def assign_color(obj_display, props) -> None: color = obj_display['@displayStyle']['color'] elif hasattr(obj_display, 'renderMaterial'): color = obj_display['renderMaterial']['diffuse'] + opacity = obj_display['renderMaterial']['opacity'] elif hasattr(obj_display, '@renderMaterial'): color = obj_display['@renderMaterial']['diffuse'] + opacity = obj_display['@renderMaterial']['opacity'] except Exception as e: print(e) - r, g, b = get_r_g_b(color) - hex_color = '#%02x%02x%02x' % (r, g, b) - props['color'] = hex_color + a, r, g, b = get_r_g_b(color) + if opacity is not None and isinstance(opacity, float): + a_test = int(255* opacity) + if 0 <= a_test <= 255: + a = a_test + # hex_color = '#%02x%02x%02x' % (r, g, b) + props['color'] = f'rgba({r},{g},{b},{a})' def get_r_g_b(rgb: int) -> Tuple[int, int, int]: """Get R, G, B values from int.""" r = g = b = 0 + a = 255 try: + a = (rgb & 0xFF000000) >> 24 r = (rgb & 0xFF0000) >> 16 g = (rgb & 0xFF00) >> 8 b = rgb & 0xFF except Exception as e: r = g = b = 150 - return r, g, b + a = 255 + return a, r, g, b def assign_display_properties(feature: Dict, f_base: "Base", obj_display: "Base") -> None: """Assign displayProperties to the feature.""" diff --git a/pygeoapi/templates/_base.html b/pygeoapi/templates/_base.html index b3fb7cd..abe30da 100644 --- a/pygeoapi/templates/_base.html +++ b/pygeoapi/templates/_base.html @@ -1,5 +1,69 @@ + +
- 4. Speckle project comments: https://geo.speckle.systems/?speckleUrl=https://app.speckle.systems/projects/344f803f81/models/5582ab673e&datatype=projectcomments + 4. Rhino detailed building: https://geo.speckle.systems/?speckleUrl=https://app.speckle.systems/projects/5feae56049/models/9c43d7569c&limit=100000&northDegrees=-117 +
++ 5. Speckle project comments: https://geo.speckle.systems/?speckleUrl=https://app.speckle.systems/projects/344f803f81/models/5582ab673e&datatype=projectcomments