0

I'm very new to R/Shiny/Leaflet.

I have a barebones working example where I can display points on map based on their lat/long in a table I pull from Oracle:

siteData <- conn %>% tbl(in_schema("SCHEMANAME", "TABLENAME")) %>% as.data.frame();

function(input, output, session) {
  output$map <- renderLeaflet({
    leaflet() %>%
      addTiles() %>%
      setView(lng = -93.85, lat = 37.45, zoom = 4)
  })
...
  observe({
    colorBy <- input$color
    sizeBy <- input$size
    
    
    leafletProxy("map", data = siteData) %>%
      clearMarkers() %>%
      addCircleMarkers(~LONGITUDE, ~LATITUDE,
                       popup=
                         ~paste("ID: ", as.character(ID), "<br>",
                                "Latitude: ", as.character(LATITUDE) , "<br/>" ,
                                "Longitude: ", as.character(LONGITUDE) , "<BR/>" 
                                ),
                       clusterOptions=markerClusterOptions()) 
  })

I have an additional table with polygons that I only want to show at certain zoom levels. Basically, once close-enough in, I want to take the IDs of the points currently in view, go to the db and pull the polygons whose IDs match.

I see the flow like this: What is the current zoom level? If the zoome level is appropriate, what are the visible points? What are the IDs of the visible points? SELECT * FROM details WHERE ID in (<set of ID's of visible points>) and then render the returned polygons.

Many of the examples I see seem to assume that you have all the data you need in a single pull, and I don't want to draw that many polygons at once. I'd rather pay the toll for latency than browser memory.

====EDITED TO ADD====

The column that holds the polygon in the detail table is coded as:

    SDO_GEOMETRY(    
        2003,  -- two-dimensional polygon
        NULL,
        NULL,
        SDO_ELEM_INFO_ARRAY(1,1003,1), -- EXTERIOR POLYGON
        SDO_ORDINATE_ARRAY( 
                LONGITUDE , LATITUDE ,
                LONGITUDE + C.ROW_NUMBER*0.0001*COS(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2)), LATITUDE + C.ROW_NUMBER*0.0001*SIN(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2))  ,
                LONGITUDE + C.ROW_NUMBER*0.0001*COS(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + B.BEAMWIDTH/4 )),LATITUDE + C.ROW_NUMBER*0.0001*SIN(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + B.BEAMWIDTH/4))  ,
                LONGITUDE + C.ROW_NUMBER*0.0001*COS(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 2*B.BEAMWIDTH/4)),LATITUDE + C.ROW_NUMBER*0.0001*SIN(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 2*B.BEAMWIDTH/4))  ,
                LONGITUDE + C.ROW_NUMBER*0.0001*COS(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 3*B.BEAMWIDTH/4)),LATITUDE + C.ROW_NUMBER*0.0001*SIN(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 3*B.BEAMWIDTH/4))  ,
                LONGITUDE + C.ROW_NUMBER*0.0001*COS(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 4*B.BEAMWIDTH/4)),LATITUDE + C.ROW_NUMBER*0.0001*SIN(0.017456329*(A.AZIMUTH - B.BEAMWIDTH/2 + 4*B.BEAMWIDTH/4))  ,
                LONGITUDE , LATITUDE
            )
    ) AS SECTORPOLYGON
6
  • You are asking this with the oracle-spatial tag, so I assume that those polygons are stored as rows in a table with the polygon shape encoded using the SDO_GEOMETRY type. Is this correct ? If so you need a spatial query that returns those polygons that interact with those points ? Commented Aug 8, 2023 at 7:30
  • Or is this purely based on IDs, i.e. each point has an attribute called something like POLYGON_ID that represents the id of the polygon that contains that point ? Commented Aug 8, 2023 at 7:34
  • Then again any respectable map generation library has options to only show the content of a layer at a certain scale range. Commented Aug 8, 2023 at 7:37
  • I agree that the controlling the layer content by zoom level is not really the issue. But, I don't want to overload the browser with 250k polygons when they're not useful at a 30k foot view. Hence the comment to prefer network time over browser time. I have some freedom in whether I save the column as an SDO_GEOMETRY object or a string representing a GeoJSON object. It appears with some testing that the GeoJSON object plays friendlier with R/Leaflet.
    – Eddie Rowe
    Commented Aug 8, 2023 at 17:21
  • There are two options here: one is to setup your mapping client so that it only shows that layer from a certain zoom level. For example, if the polygons you deal with are building outlines, then only start showing them when zoomed close enough that they make sense viewing. Commented Aug 27, 2023 at 9:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.