Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 传单不会第一次加载url_Javascript_Angularjs_Leaflet - Fatal编程技术网

Javascript 传单不会第一次加载url

Javascript 传单不会第一次加载url,javascript,angularjs,leaflet,Javascript,Angularjs,Leaflet,我有以下代码,用于在get函数中加载非地理地图,以便每次获取所需地图: $scope.tableFloors = data; //Creamos las dimensiones del mapa e inicializamos la url de la imagen correspondiente al plano $scope.url = $scope.tableFloors.results[0].idBluePrint; console.log("url: " + $scope.url);

我有以下代码,用于在get函数中加载非地理地图,以便每次获取所需地图:

$scope.tableFloors = data;

//Creamos las dimensiones del mapa e inicializamos la url de la imagen correspondiente al plano
$scope.url = $scope.tableFloors.results[0].idBluePrint;
console.log("url: " + $scope.url);
//INICIALIZACIÓN DE VARIABLES NECESARIAS PARA GENERAR EL MAPA
//zoom mínimo para el mapa
$scope.minZoom = 1;
//zoom máximo para el mapa
$scope.maxZoom = 4;
//posición del centro para el mapa
$scope.center = [0, 0];
//zoom por defecto al cargar el mapa
$scope.zoom = 3;
//sistema de referencia de coordenadas
$scope.crs = L.CRS.Simple;
//atributo para mostrar/ocultar información extra
$scope.attributionControl = false;
$scope.map = L.map('image-map',
{
    minZoom: $scope.minZoom,
    maxZoom: $scope.maxZoom,
    center: $scope.center,
    zoom: $scope.zoom,
    crs: $scope.crs,
    attributionControl: $scope.attributionControl
});

//obtenemos el ancho y el alto de la foto del plano
$scope.fotoPlano = new Image();
$scope.fotoPlano.src = $scope.url;
$scope.width = $scope.fotoPlano.width;
$scope.height = $scope.fotoPlano.height;
// Calculamos los bordes de la imagen en el espacio de coordenadas
$scope.surOeste = $scope.map.unproject([0, $scope.height], $scope.map.getMaxZoom() - 1);
$scope.norEste = $scope.map.unproject([$scope.width, 0], $scope.map.getMaxZoom() - 1);;
$scope.bounds = new L.LatLngBounds($scope.surOeste, $scope.norEste);
// lo añadimos
L.imageOverlay($scope.url, $scope.bounds).addTo($scope.map).bringToFront();
$scope.myIcon = L.icon(
{
    iconUrl: 'assets/images/ic_location.png',
    // iconRetinaUrl: 'my-icon@2x.png',
    iconSize: [34, 34],
    iconAnchor: [22, 94],
    // popupAnchor: [-3, -76],
    // shadowUrl: 'my-icon-shadow.png',
    // shadowRetinaUrl: 'my-icon-shadow@2x.png',
    // shadowSize: [68, 95],
    // shadowAnchor: [22, 94]
});

// establecemos los límites
$scope.map.setMaxBounds($scope.bounds);
$scope.yx = L.latLng;
$scope.xy = function (x, y)
{
    if (L.Util.isArray(x))
    { // When doing xy([x, y]);
        return $scope.yx(x[1], x[0]);
    }
    return $scope.yx(y, x); // When doing xy(x, y);
};

var puntoIncidencia1 = $scope.xy(100, -40);

var incidencia1 = L.marker(puntoIncidencia1,
{
    icon: $scope.myIcon,
    draggable: true
}).addTo($scope.map).bindPopup('incidencia1');
//version con mapclickevent
$scope.map.on('click',
    function mapClickListen(e)
    {
        var pos = e.latlng;
        console.log("pos: ", this.options);
        console.log('map click event');
        var marker = L.marker(
            pos,
            {
                draggable: true
            }
        );
        marker.on('drag', function (e)
        {
            console.log('marker drag event');
        });
        marker.on('dragstart', function (e)
        {
            console.log('marker dragstart event');
            $scope.map.off('click', mapClickListen);
        });
        marker.on('dragend', function (e)
        {
            console.log('marker dragend event');
            setTimeout(function ()
            {
                $scope.map.on('click', mapClickListen);
            }, 10);
        });
        marker.addTo($scope.map);
    }
);

但是我第一次调用函数时,它没有正确加载图像,或者如果我第一次调用时删除缓存,它也不会加载图像。当我调用函数时,它会正确加载,之后如果我不删除缓存,它会一直正常加载,这只是它第一次没有正确加载。。。为什么?

在访问图像大小时,图像无法加载

var imageObj = new Image();
imageObj.addEventListener('load', function() { /* ... */ }, false); 
// use the load event to know that image has been loaded 

加载映像后继续。

我知道问题出在哪里,问题是我第一次调用它:$scope.fotoPlano=new image()$scope.fotoPlano.src=$scope.url$scope.width=$scope.fotoPlano.width$scope.height=$scope.fotoPlano.height;高度和宽度为0,但我不理解第二次,它需要很好的宽度和高度。。。。。任何解决方案??可能在时间之前未加载图像..当你刷新它时,bcs图像已加载…检查图像的加载事件,当加载图像时,然后做你想做的事情我知道问题所在,你的注释速度比我快xd,它的宽度和高度第一次是0,但我不明白为什么或者如何用一个优雅/好的解决方案来解决这个问题$scope.fotoPlano=new Image()$scope.fotoPlano.addEventListener('load',function(){$scope.fotoPlano.src=$scope.url;$scope.width=$scope.fotoPlano.width;$scope.height=$scope.fotoPlano.height;console.log(“ancho:+$scope.width+”alto:+$scope.height);},false);所以,如果我理解你的意思,但现在它不起作用了,我把控制台日志放进加载函数,它就不会进入//obtenemos el-ancho y el-alto de la foto del plano$scope.fotoPlano=new Image()$scope.fotoPlano.addEventListener('load',function(){$scope.fotoPlano.src=$scope.url;$scope.width=$scope.fotoPlano.width;$scope.height=$scope.fotoPlano.height;console.log(“ancho:+$scope.width+”alto:+$scope.height);},false);所以,如果我理解你的意思,但现在它不工作了,我把一个控制台日志放到加载函数中,它没有进入inca,请提供一个jsbin