为什么在设置图层后将鼠标悬停在地图上时会出现类型错误? [英] why am I getting type errors when hovering over map after layers are set?

查看:118
本文介绍了为什么在设置图层后将鼠标悬停在地图上时会出现类型错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里建立了一张地图: https://www.jsnippet.net / snippet / 1437 /



这是一个绘图管理解决方案,可绘制圆形,方形或多边形。不是多个图层,只有一个图层。



多边形贴图工作正常(尽管我试图找出删除多边形顶点),但我的问题确实是控制台



在放置多边形,圆形或矩形后,我开始接受地图上的悬停错误:

 未捕获TypeError:在UV下无法读取null 
的属性'Sa'。< anonymous> (onion.js:59)
at Object._。A.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& libraries = drawing& callback = initMap:102)
at UV.handleEvent(onion.js:63 )
at jy._.k.de(map.js:44)
at Object ._。A.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& libraries = drawing& callback = initMap:102)
在hq。< anonymous> (common.js:132)
at Object ._。A.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& libraries = drawing& callback = initMap:102)
at nq(common.js:87)
在hq。< anonymous> (common.js:192)$ h
< anonymous> (common.js:192)

当我将鼠标悬停在地图上并且移动时发生此错误鼠标,它继续显示。我不知道如何解决这个问题。任何智慧将不胜感激。



谢谢。

更新#1:



我针对多种浏览器(Opera,Firefox,IE和Chrome)进行了测试,得到的回应与以下错误相同:

  Uncaught TypeError:JSON.parse不是一个函数
在lW(onion.js:29)
在OV。< anonymous> (onion.js:59)
at Object._。z.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& v = 3& libraries = drawing& callback = initMap:102)
at OV.handleEvent(onion .js:63)
at hy._.k.be(map.js:44)
at Object ._。z.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& v = 3& libraries = drawing& amp; ; callback = initMap:102)
at aq。< anonymous> (common.js:135)
at Object ._。z.trigger(js?key = AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA& v = 3& libraries = drawing& callback = initMap:102)
at gq(common.js :90)
at aq。< anonymous> (common.js:200)

现在,我没有专门调用JSON.parse,但它听起来就像我在顺便那样做。哪里?我该如何解决它?感谢!

解决方案

您在这个函数中犯了一个非常不错的错误:

 函数setJSON(Shape){
console.log(Shape.type);
if(Shape.type ===circle){
return'{type:'+ Shape.type +',lat:'+ Shape.getCenter() .lat()+',lng:'+ Shape.getCenter()。lng()+',radius:'+ Shape.getRadius()+'}';
}
if(Shape.type ===rectangle){
return'{type:'+ Shape.type +',start:'+ Shape .getBounds()。getNorthEast()+',end:'+ Shape.getBounds()。getSouthWest()+'}';
}
if(Shape.type == =polygon){
// eturn'{type:'+ Shape.type +'}'+ Shape.getPaths();
vertice = Shape.getPath();
console.log(vertice count:+ vertice.getLength());


/ * HERE * /
JSON ='{type: '+ Shape.type +',coordinates:';
/ * ^^^ * /


vertice.forEach(function(xy,i){
JSON = JSON + xy.lat()+'' + xy.lng()+',';
});

JSON = JSON.slice(0,-2)+'}';
返回JSON;
}

返回0
}

您正在覆盖全局JSON对象,所以JSON不再有其方法。 / p>

通过在函数作用域中声明变量来修复它:

var JSON ='{type:'+ Shape .type +',coordinates:';

https://www.jsnippet.net/snippet/1440/

更好的重命名为 myJSON 或其他。

最好避免使用像JSON,窗口,文档等全球名称。因此,您可以避免混淆。


I have a map that I'm building here: https://www.jsnippet.net/snippet/1437/

It's a drawingmanager solution, where I can draw a circle, square, or polygon. Not multiple layers, just one.

THe polygon placement is working perfectly (although I'm trying to figure out deleting a polygon vertice), but my problem truly is the console.

after placing a polygon, circle, or rectangle, I started receiving hovering errors on the map:

Uncaught TypeError: Cannot read property 'Sa' of null
    at UV.<anonymous> (onion.js:59)
    at Object._.A.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&libraries=drawing&callback=initMap:102)
    at UV.handleEvent (onion.js:63)
    at jy._.k.de (map.js:44)
    at Object._.A.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&libraries=drawing&callback=initMap:102)
    at hq.<anonymous> (common.js:132)
    at Object._.A.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&libraries=drawing&callback=initMap:102)
    at nq (common.js:87)
    at hq.<anonymous> (common.js:192)
    at hq.<anonymous> (common.js:192)

This error occurs when I hover over the map, and when I move the mouse, it continues to show. I don't know how to figure this out. any wisdom would be greatly appreciated.

Thanks.

UPDATE #1:

I tested against multiple browsers (Opera, Firefox, IE, and Chrome), I am getting the same response plus the following error:

Uncaught TypeError: JSON.parse is not a function
    at lW (onion.js:29)
    at OV.<anonymous> (onion.js:59)
    at Object._.z.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&v=3&libraries=drawing&callback=initMap:102)
    at OV.handleEvent (onion.js:63)
    at hy._.k.be (map.js:44)
    at Object._.z.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&v=3&libraries=drawing&callback=initMap:102)
    at aq.<anonymous> (common.js:135)
    at Object._.z.trigger (js?key=AIzaSyALxYexJJN5slLNWWGijb16z2Dys66ASIA&v=3&libraries=drawing&callback=initMap:102)
    at gq (common.js:90)
    at aq.<anonymous> (common.js:200)

Now, I'm not calling JSON.parse specifically, but it sounds like I'm doing it incidentally. Where? and how do I fix it? Thanks!

解决方案

You have made a very nice mistake in this function:

function setJSON(Shape) {
  console.log(Shape.type);
  if (Shape.type === "circle") {
    return '{"type":"' + Shape.type + '", "lat":"' + Shape.getCenter().lat() + '", "lng":"' + Shape.getCenter().lng() + '", "radius":"' + Shape.getRadius() + '"  }';
  }
  if (Shape.type === "rectangle") {
    return '{"type":"' + Shape.type + ', "start":"' + Shape.getBounds().getNorthEast() + '", "end":"' + Shape.getBounds().getSouthWest() + '"}';
  }
  if (Shape.type === "polygon") {
    //eturn '{"type":"'+ Shape.type +'"}' + Shape.getPaths();
    vertice = Shape.getPath();
    console.log("vertice count:  " + vertice.getLength());


/* HERE */
           JSON = '{"type":"' + Shape.type + '", "coordinates": "';
/* ^^^  */


    vertice.forEach(function(xy, i) {
      JSON = JSON + xy.lat() + ' ' + xy.lng() + ', ';
    });

    JSON = JSON.slice(0, -2) + '"}';
    return JSON;
  }

  return 0
}

You're overriding the global JSON object, so JSON do not have its methods anymore.

Fix it by declaring variable whithin the function scope:
var JSON = '{"type":"' + Shape.type + '", "coordinates": "';
https://www.jsnippet.net/snippet/1440/
Even better rename it to myJSON or whatever.

And better avoid global names like JSON, window, document etc. So you'll avoid a confusion.

这篇关于为什么在设置图层后将鼠标悬停在地图上时会出现类型错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆