我正在Filemaker中使用MapKit JS,可以像这样从Filemaker Web视图中的输入获取坐标。
"const punkt = '" & Substitute ( MYMAP::longlat ; ¶ ; ", " ) & "';" & ¶ &
例如,输入:59.436549,10.629371,但我无法将此输入到mapkit定义中。我得到了纬度和经度值,并确保它是一个数字。但是然后我需要用逗号(,)。
var punkt // this is 59.658985, 10.790869
var punktxy = punkt.split(",");
var x = parseFloat(punktxy[0]);
var x = parseFloat(punktxy[1);
当我进行硬编码时,它起作用:
new mapkit.Coordinate(59.658985, 10.790869)
但是我无法正确理解。可能是因为当我将其串联时是文本类型:
new mapkit.Coordinate(x + ',' + y)
这也不起作用:
new mapkit.Coordinate(x,y)
可能是字符串?我如何正确获得价值?这可能是一个javascript基本问题,但我在这里迷路了。
这是我的webviewer代码,其中包含来自文本字段的javascript。请注意,我正在将x和y值放入JavaScript。这就是为什么我需要3个js文件的原因,因为我似乎无法正确地做到这一点:mapkit.Coordinate(59.658985, 10.790869)
webviewer:
//加载MapKit JS“”的特定实现; “ constpunkt ='“&替代(ARTSFUNN :: Lokalitet;¶;”,“)&”';“&¶&GetLayoutObjectAttribute(“ map1.js”;“ content”)&ARTSFUNN :: Lat&“,”&ARTSFUNN :: Long&GetLayoutObjectAttribute(“ map2.js”;“ content”)&ARTSFUNN :: Lat&“,”&ARTSFUNN :: Long&GetLayoutObjectAttribute(“ map3.js”;“内容”); “”;
map1.js:
mapkit.init({
authorizationCallback: done => {
done(
"<<$$JWT.TOKEN>>"
);
}
});
var punktxy = punkt.split(",");
var x = parseFloat(punktxy[0]);
var x = parseFloat(punktxy[1);
var xy = (x + ','+ y); // doesn't work
var MarkerAnnotation = mapkit.MarkerAnnotation,
clickAnnotation;
var borch = new mapkit.CoordinateRegion(
new mapkit.Coordinate(
map2.js:
),
new mapkit.CoordinateSpan(0.005, 0.005)
);
var map = new mapkit.Map('map');
map.region = borch;
map.mapType = "hybrid";
map.setCenterAnimated(new mapkit.Coordinate(
map3.js:
), true);
console.log(map);
在WebViewer中定义纬度和经度:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
使用包含在map.js中的值:
var x = parseFloat(x);
var y = parseFloat(y);
// does not work if I don't convert to digit before use!
var bor = new mapkit.CoordinateRegion(
new mapkit.Coordinate(x,y),
new mapkit.CoordinateSpan(0.005, 0.005)
);
var map = new mapkit.Map('map');
map.region = bor;
map.mapType = "hybrid";
map.setCenterAnimated(new mapkit.Coordinate(x,y), true);
这不是真正的答案(除非您的问题纯粹是关于“数字”部分的,但我不能在注释中张贴这么多的代码。
在您的问题开始时,您使用了一个名为MYMAP::longlat
的字段,该字段显然包含两个坐标,并用回车符隔开。然后您用Substitute()
用逗号替换了返回值。
现在您正在使用两个单独的字段ARTSFUNN::Lat
和ARTSFUNN::Lon
-但是您仍在对这两个字段应用相同的Substitute
操作。似乎没有必要。
更重要的是,您正在做:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
将产生类似结果:
var x = '59.436549';
var y = '10.629371';
其中两个变量都是明显的字符串,然后必须将其转换为数字。
我相信您应该这样做:
"var x = " & ARTSFUNN::Lat & ";¶var y = " & ARTSFUNN::Long & ";¶"
产生:
var x = 59.436549;
var y = 10.629371;
然后可以直接用于:
new mapkit.Coordinate(x,y)
可以使用您的原始字段获得相同的结果:
"var x = " & GetValue ( MYMAP::longlat ; 2 ) & ";¶var y = " & GetValue ( MYMAP::longlat ; 1 ) & ";¶"
(假定经度是该字段中列出的第一个值。