2016-01-12 4 views
0

Попытка получить всплывающее окно, работающее с моими данными geojson. Ошибка состояния $ (element) .popover не является функцией. Я думаю, что это связано с тем, что вы не можете читать функции, даже если они отображаются правильно.OpenLayers 3 popup с внешним geojson

Используя последнюю версию OpenLayers и JQuery: http://openlayers.org/en/v3.12.1/build/ol.js https://code.jquery.com/jquery-1.11.2.min.js

var vectorLayer = new ol.layer.Vector({ 
    source: new ol.source.Vector({ 
     url: 'http://services5.arcgis.com/GfwWNkhOj9bNBqoJ/ArcGIS/rest/services/nyad/FeatureServer/0/query?where=1=1&outFields=*&outSR=4326&f=geojson', 
     format: new ol.format.GeoJSON() 
    }), 
    }); 

    var map = new ol.Map({ 
    layers: [ 
     new ol.layer.Tile({ 
     source: new ol.source.MapQuest({layer: 'sat'}) 
     }), 
     vectorLayer 
    ], 
    target: 'map', 
    view: new ol.View({ 
     center: ol.proj.fromLonLat([-73.95, 40.7]), 
     zoom: 11 
    }) 
    }); 

    var element = document.getElementById('popup'); 

    var popup = new ol.Overlay({ 
    element: element, 
    positioning: 'bottom-center', 
    stopEvent: false 
    }); 
    map.addOverlay(popup); 

    // display popup on click 
    map.on('click', function(evt) { 
    var feature = map.forEachFeatureAtPixel(evt.pixel, 
     function(feature, layer) { 
      return feature; 
     }); 
    if (feature) { 
     popup.setPosition(evt.coordinate); 
     console.log(evt.coordinate); 
     $(element).popover({ 
     'placement': 'top', 
     'html': true, 
     'content': feature.get('AssemDist') 
     }); 
     $(element).popover('show'); 
    } else { 
     $(element).popover('destroy'); 
    } 
    });  

ответ

0

Вы добавить самозагрузки

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
Смежные вопросы