change data with pass to javascript function

I so sorry for my english

I load data from database and convert to JObject like this image
First Level Convert and Debug it and show resut

I convert to string then pass to my function in javascript
but when pass to function, this changed format like this image

After pass string to function

now when i define same code into scripts , i do not have any problem
Define manual code in javascript

now i want to pass JObject to javascript function and use it
How to solve this problem?

CODES :

I use Postgres Database
Create table :

CREATE TABLE "TLandPoint"
(
    gid integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
    geom geometry,
    "LandId" bigint NOT NULL,
    "SumSpace" bigint NOT NULL,
    "CityLevelId" bigint NOT NULL,
    CONSTRAINT "PK_TLandPoint" PRIMARY KEY (gid)
        USING INDEX TABLESPACE "MyDB"
)

TABLESPACE "MyDB";

ALTER TABLE "TLandPoint"
    OWNER to postgres;

insert sample data

INSERT INTO "TLandPoint"(
     geom, "LandId", "SumSpace", "CityLevelId")
    VALUES ( '0101000000F30D15E765D355410C3A0D001F1B5041', 5698, 13500, 123001002);

and create view for convert geom to json

CREATE OR REPLACE VIEW "TLandPointView"
 AS
 SELECT "TLandPoint".gid,
    st_asgeojson("TLandPoint".geom) AS jsonpoint,
    "TLandPoint"."LandId",
    "TLandPoint"."SumSpace",
    "TLandPoint"."CityLevelId"
   FROM "TLandPoint";

ALTER TABLE "TLandPointView"
    OWNER TO postgres;

Load data from view with Linq

var TLandPts =DbContext.TLandPointView.AsQueryable();

and use this code to create JObject

JObject rss =
        new JObject(
        new JProperty("type", "FeatureCollection"),
        new JProperty("features",
                new JArray(from p in TLandPts select
                new JObject(
                new JProperty("id", p.gid),
                new JProperty("type", "Feature"),
                new JProperty("geometry", new JObject(JObject.Parse(p.jsonpoint))),
                new JProperty("properties",
                    new JObject(
                        new JProperty("LandId", p.LandId),
                        new JProperty("SumSpace", p.SumSpace),
                        new JProperty("CityLevelId", p.CityLevelId)
                        )
                
                    )
                )
                )
            )
        );
            var y = rss.ToString();

and use this code to pass y to my function

in controler

public IActionResult Index(){
ViewBag.Land = y;
return view()
}

in index.cshtml

<script>
LoadData('@ViewBag.Land');
</script

and into javascript

function loadData(mydata){
    var PointSource = new ol.source.Vector({
        features: new ol.format.GeoJSON().readFeatures(mydata)
    });
    var PointLayer = new ol.layer.Vector({
        source: PointSource
    });
    map.addLayer(PointLayer);

}

104 thoughts on “change data with pass to javascript function”

  1. Hi, I do think this is an excellent web site. I stumbledupon it 😉 I am going
    to return once again since I bookmarked it. Money and freedom is the greatest
    way to change, may you be rich and continue to help other
    people.

    Reply

Leave a Comment