地图显示在外部浏览器中,但不显示在查看器窗格中

时间:2015-12-24 11:54:23

标签: javascript html r google-maps shiny

我是有光泽和谷歌地图API的新手。应用程序在外部模式中显示地图,但窗口或查看器窗格中的不是

ui.R

library(shiny)

shinyUI(fluidPage(

  # Application title
  titlePanel("My Map"),

  # Sidebar with a slider input for number of bins
  sidebarLayout(
    sidebarPanel(
      textInput("coordinates","Coordinate"),
      actionButton("updateMap", "Mark the Place")
    ),

    # Show a plot of the generated distribution
    mainPanel(
      includeHTML("www/ui.html")
    )
  )
))

server.R

library(shiny)

shinyServer(function(input, output) {
  observeEvent(input$updateMap, {
    print(input$updateMap)
  })
})
www 目录

中的

ui.html

<!DOCTYPE html>
<html>
  <head>
    <style>
      #map {
        width: 500px;
        height: 500px;
      }
    </style>
    <script src="https://maps.googleapis.com/maps/api/js"></script>
    <script>
      var map;
      var counter = 0;  
      function placeddMarkers(lat = 44.5403, lng = -78.5463) {
          var iconBase = 'https://maps.google.com/mapfiles/kml/shapes/';
          var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lng),
            map: map,
            icon: iconBase + 'schools_maps.png'
          });  
      }     

      function initialize() {
        var mapCanvas = document.getElementById('map');
        var mapOptions = {
          center: new google.maps.LatLng(44.5403, -78.5463),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
         map = new google.maps.Map(mapCanvas, mapOptions)
      }
      google.maps.event.addDomListener(window, 'load', initialize);             

    </script>
  </head>
  <body>
    <button onclick="placeddMarkers()">The time is?</button>
    <div id="map"></div>
  </body>
</html>

从ui.html中删除 placementdMarkers 定义后,一切似乎都正常。为什么会这样?问题是闪亮还是我做错了什么。请帮忙。

0 个答案:

没有答案