I am using MapKit JS in Filemaker and can get the coordinates from an input in Filemaker Web View like this.
"const punkt = '" & Substitute ( MYMAP::longlat ; ¶ ; ", " ) & "';" & ¶ &
The input is e.g.: 59.436549, 10.629371 but I can not get this into mapkit definition. I get the latitude ang longtitude value and make sure it is a digit. But then I need the comma (,).
var punkt // this is 59.658985, 10.790869
var punktxy = punkt.split(",");
var x = parseFloat(punktxy[0]);
var x = parseFloat(punktxy[1);
When I hardcode it works:
new mapkit.Coordinate(59.658985, 10.790869)
But I can not get this right. Probably because it is type text when I concatenate it like this:
new mapkit.Coordinate(x + ',' + y)
This does not work either:
new mapkit.Coordinate(x,y)
It is probably a string? How do I get the value correct? This is probably a javascript basic question but I am lost here.
Here is my webviewer code that includes the javascript from the text fields. Notice I am putting the x and y values into the javascript. That is why I need 3 js files since I can't seem to get this right: mapkit.Coordinate(59.658985, 10.790869)
webviewer:
// Load your specific implementation of MapKit JS ""; "const punkt = '" & Substitute ( ARTSFUNN::Lokalitet ; ¶ ; ", " ) & "';" & ¶ & GetLayoutObjectAttribute ( "map1.js" ; "content" ) & ARTSFUNN::Lat & " , " & ARTSFUNN::Long & GetLayoutObjectAttribute ( "map2.js" ; "content" ) & ARTSFUNN::Lat & " , " & ARTSFUNN::Long & GetLayoutObjectAttribute ( "map3.js" ; "content" ); "";
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);
Define the Lat and Long in WebViewer:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
Use the values in the include 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);
This is not really an answer (unless your question is purely about the "as digit" part), but I can't post this much code in a comment.
At the beginning of your question, you used a field named MYMAP::longlat
which apparently held both coordinates separated by a carriage return. And you used Substitute()
to replace the return with a comma.
Now you are using two separate fields, ARTSFUNN::Lat
and ARTSFUNN::Lon
- yet you're still applying the same Substitute
operation to both. This does not seem necessary.
More importantly, you're doing:
"var x = '" & Substitute ( ARTSFUNN::Lat ; ¶ ; ", " ) & "';" & ¶ &
"var y = '" & Substitute ( ARTSFUNN::Long ; ¶ ; ", " ) & "';" & ¶ &
which would produce a result like:
var x = '59.436549';
var y = '10.629371';
where both variables are clearly strings which you then have to convert to numbers.
I believe you should be doing:
"var x = " & ARTSFUNN::Lat & ";¶var y = " & ARTSFUNN::Long & ";¶"
to produce:
var x = 59.436549;
var y = 10.629371;
which can then be used directly by:
new mapkit.Coordinate(x,y)
The same result can be obtained using your original field in:
"var x = " & GetValue ( MYMAP::longlat ; 2 ) & ";¶var y = " & GetValue ( MYMAP::longlat ; 1 ) & ";¶"
(assuming longitude is the first value listed in the field).